-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Conditional import of a class follows imports of all branches #19009
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
Comments
Thanks for putting this together, and sorry I didn't notice the below looking at previous iterations of it. The |
Thanks for the quick response! Your answer perplexes me. Are you saying that Mypy doesn't check what code is actually executed based on conditionals and missing attributes like this don't often occur in the wild because libraries typically set to |
No, Jelle says that invoking If there are no related regressions, just assert sys.platform == 'win32' after imports in |
(note that you'll need to actually run |
The file-level assertion worked! Is it possible to achieve this with a comment instead so that one doesn't have to potentially unnecessarily |
None that I'm aware of, but you don't have to mess up the imports - unless some of your imports are only available on certain platforms, you can |
Oh, and you may also try |
I tried inline configuration but it looks like this has no effect:
|
Yes, the manual section for the
All such global flags cannot be set inline. And it really makes little sense to set a platform per-file: you can't guarantee that no other file (or even external users, underscores don't prevent me from importing that file) imports it on another platform or without such guard. |
Thanks for the help! I'm going to close this since there is nothing to be done (I think?) and will be watching the feature request that I just opened: #19013 |
Bug Report
When you have the following provider module:
and attempt importing this symbol from somewhere else, Mypy does not respect the platform condition.
For example, if you call
pty.openpty()
insidemy_pkg._pty.unix
and run Mypy on Windows it will show:To Reproduce
Create the following structure:
with the following contents (
__init__.py
files are empty):pyproject.toml
pkg/main.py
pkg/_pty/interface.py
pkg/_pty/session.py
pkg/_pty/unix.py
pkg/_pty/windows.py
Finally, enter the
mypy-issue
directory and runmypy pkg
on Windows:Expected Behavior
I would expect that Mypy respects the platform condition like it does in other circumstances I've experienced and is documented.
Your Environment
The text was updated successfully, but these errors were encountered: