Repository navigation
Hide imported names in stubs unless 'as id' is used (PEP 484) - #3706
Conversation
|
I'll test this against Dropbox codebases. |
|
It looks like some of the typeshed failures are due to a bug in my PR, will investigate now. |
|
Yeah, I get this for example: |
|
After I fixed the bug in this PR, it looks like there are only two errors in typeshed: Both seem to be legitimate errors. |
Actually two in stdlib plus a dozen or so in third party stubs. |
|
So do we need to fix all the typeshed errors first? Also I can't re-test this with the Dropbox codebases until you've fixed the merge conflict. |
|
@gvanrossum I fixed the merge conflict and made a PR to typeshed python/typeshed#1484 |
|
Please hold off on this until after the release of 0.521 (or until Jukka vets it). |
NP, I don't think this is urgent. But it would be great to test this with internal codebases (maybe there are more errors in stubs). |
|
OK, I have fixed the logic as discussed in python/typeshed#1484, this should be now ready for review and testing with internal codebases. |
|
I added one more test and simplified the PR, still I cannot do this with only one flag Also typeshed is synced, so that this ready to be reviewed and merged. |
emmatyping
left a comment
There was a problem hiding this comment.
One style nit, otherwise looks good to me.
| return n | ||
| if n and n.module_hidden: | ||
| self.name_not_defined(name, ctx) | ||
| return n if n and not n.module_hidden else None |
There was a problem hiding this comment.
Minor style nit. Take it if you want. I prefer to not have compound if statements in returns. It makes things clearer if you break it up, but up to you.
|
@gvanrossum Do you think Ethan's review is enough, or we need another one? (This is quite a minor change, so that I would merge this soon to avoid more merge conflicts.) |
|
I'm taking a look now. |
gvanrossum
left a comment
There was a problem hiding this comment.
LGTM. I'm pressed for time, can you merge it yourself?
After mypy [started hiding](python/mypy#3706) imported names in stubs unless `from ... import ...` is used, we found an error with stubs of ast module. It looks like ast module should re-export everything in `_ast` and according to PEP 484, it can do that by doing `from _ast import *`, so this is what this PR does.
Fixes #2927
PEP 484 specifies that only names imported as
from mod import name as nameshould be re-exported. However, mypy didn't follow this rule so that this code passed without errors but obviously fails at runtime:This PR makes all these errors. CI will fail since there are several dozens of errors in typeshed, I am going to make a PR to typeshed soon.