-
Notifications
You must be signed in to change notification settings - Fork 771
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reexported class with same name as module treated as module #1050
Comments
Pylance will report a problem if you enable the type checker (set typeCheckingMode to "basic") and attempt to instantiate a class that has unimplemented abstract methods. If you go to the child class and start typing the implementation of a function (e.g. type "def g"), pylance will suggest a completion and auto-fill an initial implementation. Of course, writing the actual implementation will require some additional coding on your part. |
Pylance handles You are correct about completion suggestions not being offered for abstract properties. We'd appreciate it if you'd file a new issue for that. |
Yes it is: this is the problem.
Sure! I'll open a new issue for that so we can focus on the other problem. |
There was a bug in the handling of |
I did a test pull to see, and it does fix it for the non- However in
Note "class" at runtime, but "module" in all of the hovers. The last two should be I'll also point out this edge case:
Here it says module as well, but it should also be
Because current module's symbol table doesn't have |
Test repo here: https://github.com/jakebailey/pylance1050 |
I think this algorithm is actually " |
Yeah actually my goal is to define one file for each class, so it makes no sense to me to have to write Is there another more conventional way you would recommend to keep the code clear? |
Warning, opinion ahead. You won't like this, I'm guessing, but as far as I'm aware, it's a bit un-pythonic to stick one class in each file as though you were writing Java or C# (where you must have a file or more per class and no other code). Most codebases aren't structured like this and instead would probably put most of these types in the same file as one conceptual entity. E.g., maybe you have a I'll also say that in terms of styling, if you're making an abstract class, it's more common to name things something like "AbstractDataLoader" (no naming at all) rather than "IDataLoader". You may also want to consider looking into This is all unrelated to the bug here, of course. Drive by code reviews... 🙂 I don't want to digress forever. |
It's also very unusual in the Python world to see source file names that are capitalized or make use of camel casing. They're almost always lowercase with underscores separating words. As Jake said, that's just convention. |
@jakebailey , I found and fixed one more issue in the hover provider that was causing the hover text to return a type that was inconsistent with the type evaluator. The other issue you found is that the import results can be affected by the side effects of imports that happen earlier in time. As you know, this is an extremely unfortunate property of the python import system, and I consider it a bug if anyone relies on such behavior. So I don't consider that a bug in the type checker, and I don't plan to make a change to accommodate that. |
Thank you guys for your feedback on this, I am using one file for each class because I think that having 500 lines long files is harder to maintain in my opinion; however, I will definitely look deeper in Python modules :) Please be sure to let me know if you need additional help on the issue |
Thanks, I can confirm it works.
At least in the example I've given, there isn't side effect behavior. These two examples are functionally the same to the last import statement, because from foo import X
from . import X X = 1234
from . import X While I think this is unlikely, doing it wrong may mean people who accidentally shadow a module name above the import statement in their So, it worked out. 🙂 |
There shouldn't be anything needed anymore. I think your example should work as expected now and you can test after our release today. |
This issue has been fixed in version 2021.3.2, which we've just released. You can find the changelog here: https://github.com/microsoft/pylance-release/blob/main/CHANGELOG.md#202132-17-march-2021 |
Environment data
Expected behaviour
Pylance should show an error if the user hasn't implemented the abstract function a class inherits.
Actual behaviour
Pylance thinks it is normal!
Code Snippet / Additional information
File 1 :
__init__.py file :
File 2 :
Here, Pylance should underline
class ImageNet(IDataLoader):
in red telling that implementation of IDataLoader is incorrect because the implementation of IDataLoader specifies thatget_training_dataset()
is required.On top of that, Pylance should provide a "quick fix" to automatically implement all the required methods. This behavior is already implemented in PyCharm.
The text was updated successfully, but these errors were encountered: