Skip to content

Fix implicit __loader__ module attribute - #21884

Open
nightcityblade wants to merge 1 commit into
python:masterfrom
nightcityblade:fix/issue-4182
Open

Fix implicit __loader__ module attribute#21884
nightcityblade wants to merge 1 commit into
python:masterfrom
nightcityblade:fix/issue-4182

Conversation

@nightcityblade

@nightcityblade nightcityblade commented Aug 24, 2026

Copy link
Copy Markdown

Fixes #4182

Mypy now recognizes __loader__ as an implicit module attribute. It uses _typeshed.importlib.LoaderProtocol | None with the standard typeshed and falls back to object | None when import following is unavailable or the test fixtures are active.

The existing implicit-module-attributes test now covers __loader__.

Tests:

  • .venv/bin/python -m pytest -n0 'mypy/test/testcheck.py::TypeCheckSuite::check-basic.test' (46 passed)
  • .venv/bin/python -m pytest -n0 mypy/test/testexportjson.py (8 passed)
  • .venv/bin/python -m pytest -n0 -k 'testInspectModuleAttrs' (2 passed)
  • .venv/bin/python runtests.py self (341 source files checked)
  • .venv/bin/python runtests.py lint (all hooks passed)
  • .venv/bin/python -m mypy -c 'reveal_type(__loader__)'

@github-actions

This comment has been minimized.

@github-actions

Copy link
Copy Markdown
Contributor

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

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.

Mypy doesn't recognize __loader__ global in Python 3.6

1 participant