You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
Yes. This feature enables packages with a __init__.py (which predate the implicit namespace packages from PEP 420) to successfully "collaborate" with implicit namespace packages.
Unfortunately, this situation is still fairly common in my work place, due to how different teams are all contributing to common packages "independently".
To reproduce the issue on a simple example, you can use the following script (very similar to the example in #4230):
Support a limited version of pkgutil.extend_path(). I understand that this is getting close to runtime behavior (and thus arguably not in scope for Pyright), so my proposal is to find a tradeoff that limits the complexity, while still helping with most common cases.
Concretely, I suggest the following behavior:
Only support __path__, __name__ arguments to extend_path. As mentioned in the documentation, this is the intended use.
When an __init__.py file only contains these two lines (other than comments), treat it as if the __init__.py file was missing (I am not an expert in PEP 420, but my understanding is that it would have a similar effect).
Ignore all the other cases as unsupported (note: the behavior from 2. could be extended to __init__.py files which start with these two lines, and have additional ones, but I don't know how much complexity this would incur. It would be a nice to have, but not useful for most cases).
I am curious to hear your thoughts on this. Thanks!
The text was updated successfully, but these errors were encountered:
This is dynamic behavior, and we don't support it in a static type checker. Even the "limited form" that you're suggesting here would be somewhere between "extremely complex" and "impossible" to implement given pyright's lazy (just-in-time) analysis design. We need to know about potential import paths much earlier in the analysis process, but your proposal requires that we parse and analyze the file to determine that it is effectively modifying the import resolution paths dynamically. That's not really feasible.
You should switch to implicit namespace packages if you want to work with static type analysis.
Is your feature request related to a problem? Please describe.
Yes. This feature enables packages with a
__init__.py
(which predate the implicit namespace packages from PEP 420) to successfully "collaborate" with implicit namespace packages.Unfortunately, this situation is still fairly common in my work place, due to how different teams are all contributing to common packages "independently".
To reproduce the issue on a simple example, you can use the following script (very similar to the example in #4230):
Describe the solution you'd like
Support a limited version of
pkgutil.extend_path()
. I understand that this is getting close to runtime behavior (and thus arguably not in scope for Pyright), so my proposal is to find a tradeoff that limits the complexity, while still helping with most common cases.Concretely, I suggest the following behavior:
__path__, __name__
arguments toextend_path
. As mentioned in the documentation, this is the intended use.__init__.py
file only contains these two lines (other than comments), treat it as if the__init__.py
file was missing (I am not an expert in PEP 420, but my understanding is that it would have a similar effect).__init__.py
files which start with these two lines, and have additional ones, but I don't know how much complexity this would incur. It would be a nice to have, but not useful for most cases).I am curious to hear your thoughts on this. Thanks!
The text was updated successfully, but these errors were encountered: