FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Add star imported modules as dependencies by ilevkivskyi · Pull Request #6179 · python/mypy · GitHub

Repository navigation

Add star imported modules as dependencies - #6179

Merged
msullivan merged 2 commits into
python:masterfrom
ilevkivskyi:fix-star-import-crash
Jan 11, 2019
Merged

msullivan merged 2 commits into
python:masterfrom
ilevkivskyi:fix-star-import-crash

Conversation

Copy link
Copy Markdown
Member

Fixes #6110

I tried few approaches, and this one seems the most clean to me. Essentially, we just add some more imports (dependencies) after the second pass, where the star imports are resolved.

Copy link
Copy Markdown
Member Author

(I manually verified that this fixes the mypy crashes discovered in our internal codebases.)

msullivan left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

This seems basically reasoanble.

msullivan merged commit e6f111a into python:master Jan 11, 2019
ilevkivskyi deleted the fix-star-import-crash branch January 11, 2019 08:37
hauntsaninja added a commit that referenced this pull request Apr 11, 2025
Fixes #12664

A root cause is there is this stateful `_update_ns_ancestors` thing in
`modulefinder`, so if things get called in the wrong order, you can get
incorrect results.

See also the logic in `all_imported_modules_in_file` where we've fixed
several bugs like this previously, like #13124 and #10937

As a result of (seemingly accidentally) reusing imports across modules,
we can end up in a situation where the namespace gets added as a
dependency to all other modules and so on the cached run we attempt to
find namespace before package, which does not work

I am not sure this `imports` code path is even needed, so I will open an
alternate PR, see #18908.

Relevant history:
- #6582
- #6179

I can't write a good test for this because it requires something in
site_packages, but here's a minimal repro:
```
set -eux
rm -rf repro
mkdir repro
cd repro

SITEPACK=env/site-packages
mkdir -p $SITEPACK

mkdir $SITEPACK/ruamel
mkdir $SITEPACK/ruamel/yaml

printf 'from ruamel.yaml.main import *' > $SITEPACK/ruamel/yaml/__init__.py
printf 'import ruamel.yaml' > $SITEPACK/ruamel/yaml/main.py
printf '' > $SITEPACK/ruamel/yaml/py.typed

printf 'import ruamel.yaml' > a.py
printf 'import a' > main.py

rm -rf .mypy_cache
PYTHONPATH=$SITEPACK mypy main.py
PYTHONPATH=$SITEPACK mypy main.py
```
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Crash with star imports and new file in the build

2 participants


Back | FazBrowse Home | New Git URL