Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Harmonise return type of builtins.__import__ and importlib.import_module - #6302

Merged
srittau merged 3 commits into
python:masterfrom
AlexWaygood:harmonise-import-return
Nov 15, 2021
Merged

Harmonise return type of builtins.__import__ and importlib.import_module#6302
srittau merged 3 commits into
python:masterfrom
AlexWaygood:harmonise-import-return

Conversation

@AlexWaygood

Copy link
Copy Markdown
Member

This PR is an attempt at solving #6295 by adding __getattr__ to types.ModuleType and changing the return type of builtins.__import__ so that it now returns types.ModuleType rather than Any.

@github-actions

Copy link
Copy Markdown
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

isort (https://github.com/pycqa/isort.git)
+ isort/_future/__init__.py:9: error: unused "type: ignore" comment
+ isort/_future/__init__.py:10: error: unused "type: ignore" comment
+ isort/output.py:504: error: unused "type: ignore" comment
+ isort/output.py:516: error: unused "type: ignore" comment
+ isort/output.py:523: error: unused "type: ignore" comment

pip (https://github.com/pypa/pip.git)
- src/pip/_internal/locations/__init__.py:68: error: Module has no attribute "platlibdir"
+ src/pip/_internal/network/session.py:106: error: unused "type: ignore" comment

kornia (https://github.com/kornia/kornia.git)
- kornia/testing/__init__.py:16: error: Module has no attribute "util"  [attr-defined]

ibis (https://github.com/ibis-project/ibis.git)
- ibis/backends/tests/conftest.py:45: error: Module has no attribute "TestConf"

python-chess (https://github.com/niklasf/python-chess.git)
+ chess/engine.py:122: error: unused "type: ignore" comment
+ chess/engine.py:123: error: unused "type: ignore" comment
+ chess/engine.py:1209: error: unused "type: ignore" comment

anyio (https://github.com/agronholm/anyio.git)
+ src/anyio/_core/_eventloop.py:56: error: unused "type: ignore" comment

sphinx (https://github.com/sphinx-doc/sphinx.git)
+ sphinx/util/typing.py:228: error: unused "type: ignore" comment
+ sphinx/util/typing.py:428: error: unused "type: ignore" comment
+ sphinx/util/inspect.py:424: error: unused "type: ignore" comment
+ sphinx/util/inspect.py:427: error: unused "type: ignore" comment
+ sphinx/util/inspect.py:430: error: unused "type: ignore" comment
+ sphinx/util/docutils.py:52: error: unused "type: ignore" comment
+ sphinx/util/docutils.py:53: error: unused "type: ignore" comment
+ sphinx/util/docutils.py:67: error: unused "type: ignore" comment
+ sphinx/util/docutils.py:81: error: unused "type: ignore" comment
+ sphinx/util/docutils.py:95: error: unused "type: ignore" comment
+ sphinx/util/docutils.py:110: error: unused "type: ignore" comment
+ sphinx/domains/python.py:1452: error: unused "type: ignore" comment
+ sphinx/writers/manpage.py:110: error: unused "type: ignore" comment
+ sphinx/testing/util.py:126: error: unused "type: ignore" comment
+ sphinx/testing/util.py:127: error: unused "type: ignore" comment
+ sphinx/util/compat.py:29: error: unused "type: ignore" comment

aiohttp (https://github.com/aio-libs/aiohttp.git)
+ aiohttp/connector.py:1306: error: unused "type: ignore" comment
+ aiohttp/web_runner.py:181: error: unused "type: ignore" comment
+ aiohttp/pytest_plugin.py:244: error: unused "type: ignore" comment

streamlit (https://github.com/streamlit/streamlit.git)
+ lib/streamlit/script_runner.py:432: error: unused "type: ignore" comment
+ lib/streamlit/script_runner.py:439: error: unused "type: ignore" comment

werkzeug (https://github.com/pallets/werkzeug.git)
+ src/werkzeug/_reloader.py:20: error: unused "type: ignore" comment
- tests/test_wrappers.py:833: note: Use "-> None" if function does not return a value
- tests/test_wrappers.py:856: note: (Skipping most remaining errors due to unresolved imports or missing stubs; fix these first)
+ tests/test_wrappers.py:833: note: (Skipping most remaining errors due to unresolved imports or missing stubs; fix these first)

core (https://github.com/home-assistant/core.git)
+ homeassistant/components/http/forwarded.py:91: error: unused "type: ignore" comment
+ homeassistant/auth/mfa_modules/__init__.py:136: error: unused "type: ignore" comment
+ homeassistant/auth/mfa_modules/__init__.py:171: error: unused "type: ignore" comment
+ homeassistant/auth/providers/__init__.py:145: error: unused "type: ignore" comment
+ homeassistant/auth/providers/__init__.py:178: error: unused "type: ignore" comment
+ homeassistant/config.py:648: error: unused "type: ignore" comment
+ homeassistant/config.py:651: error: unused "type: ignore" comment
+ homeassistant/config.py:662: error: unused "type: ignore" comment
+ homeassistant/config.py:672: error: unused "type: ignore" comment
+ homeassistant/config.py:673: error: unused "type: ignore" comment
+ homeassistant/config.py:753: error: unused "type: ignore" comment
+ homeassistant/config.py:895: error: unused "type: ignore" comment
+ homeassistant/setup.py:241: error: unused "type: ignore" comment
+ homeassistant/setup.py:246: error: unused "type: ignore" comment
+ homeassistant/helpers/check_config.py:161: error: unused "type: ignore" comment
+ homeassistant/config_entries.py:304: error: unused "type: ignore" comment
+ homeassistant/config_entries.py:443: error: unused "type: ignore" comment
+ homeassistant/config_entries.py:482: error: unused "type: ignore" comment
+ homeassistant/config_entries.py:519: error: unused "type: ignore" comment
+ homeassistant/helpers/condition.py:929: error: unused "type: ignore" comment
+ homeassistant/helpers/condition.py:977: error: unused "type: ignore" comment
+ homeassistant/helpers/script.py:260: error: unused "type: ignore" comment
+ homeassistant/helpers/script.py:262: error: unused "type: ignore" comment
+ homeassistant/helpers/script.py:269: error: unused "type: ignore" comment
+ homeassistant/scripts/__init__.py:67: error: unused "type: ignore" comment
+ homeassistant/helpers/reload.py:81: error: unused "type: ignore" comment
+ homeassistant/helpers/reload.py:82: error: unused "type: ignore" comment
+ homeassistant/components/notify/legacy.py:61: error: unused "type: ignore" comment
+ homeassistant/components/notify/legacy.py:66: error: unused "type: ignore" comment
+ homeassistant/components/device_tracker/legacy.py:241: error: unused "type: ignore" comment
+ homeassistant/components/device_tracker/legacy.py:246: error: unused "type: ignore" comment
+ homeassistant/components/device_tracker/legacy.py:251: error: unused "type: ignore" comment
+ homeassistant/components/device_tracker/legacy.py:256: error: unused "type: ignore" comment

edgedb (https://github.com/edgedb/edgedb.git)
+ edb/server/pgconnparams.py:75: error: unused "type: ignore" comment

@AlexWaygood

AlexWaygood commented Nov 15, 2021

Copy link
Copy Markdown
Member Author

Diff from mypy_primer, showing the effect of this PR on open source code:

[...]

This seems like it just makes a lot of people's lives easier, if they were just switching off the type-checker whenever they were doing a dynamic import.

@srittau srittau 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.

Looks quite promising. Waiting for @JelleZijlstra's input.

@srittau
srittau merged commit aa7e277 into python:master Nov 15, 2021
@AlexWaygood
AlexWaygood deleted the harmonise-import-return branch November 15, 2021 15:22
@AlexWaygood

Copy link
Copy Markdown
Member Author

Thanks, both! 😀

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.

3 participants