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

Avoid unnecessary setattr lookups, ignore object.__setattr__ by hauntsaninja · Pull Request #22270 · python/mypy · GitHub

Repository navigation

Avoid unnecessary setattr lookups, ignore object.__setattr__ - #22270

Open
hauntsaninja wants to merge 1 commit into
python:masterfrom
hauntsaninja:protcolsetattr
Open

hauntsaninja wants to merge 1 commit into
python:masterfrom
hauntsaninja:protcolsetattr

Conversation

hauntsaninja commented Oct 22, 2026 •
edited
Loading

Copy link
Copy Markdown
Collaborator

This makes mypy 13% faster on the colour-science/colour codebase. Codex claims it's worth 0.8% on self check too.

Co-authored by Codex

This makes mypy 10% faster on the colour-science/colour codebase

Copy link
Copy Markdown
Contributor

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

aiohttp (https://github.com/aio-libs/aiohttp)
+ aiohttp/compression_utils.py:156:54: error: Argument 1 to "ZLibBackendWrapper" has incompatible type Module; expected "ZLibBackendProtocol"  [arg-type]
+ aiohttp/compression_utils.py:156:54: note: Protocol member ZLibBackendProtocol.MAX_WBITS expected settable variable, got read-only attribute
+ aiohttp/compression_utils.py:156:54: note: Protocol member ZLibBackendProtocol.Z_BEST_SPEED expected settable variable, got read-only attribute
+ aiohttp/compression_utils.py:156:54: note:     <3 more conflict(s) not shown>

core (https://github.com/home-assistant/core)
+ homeassistant/helpers/trigger/__init__.py:503: error: Argument 3 to "_register_trigger_platform" has incompatible type Module; expected "TriggerProtocol"  [arg-type]
+ homeassistant/helpers/trigger/__init__.py:503: note: Protocol member TriggerProtocol.TRIGGER_SCHEMA expected settable variable, got read-only attribute
+ homeassistant/helpers/trigger/__init__.py:505: error: Incompatible return value type (got "tuple[str, Module]", expected "tuple[str, TriggerProtocol]")  [return-value]
+ homeassistant/loader.py:1137: error: Incompatible return value type (got Module | ComponentProtocol, expected "ComponentProtocol")  [return-value]
+ homeassistant/loader.py:1215: error: Incompatible return value type (got Module | ComponentProtocol, expected "ComponentProtocol")  [return-value]
+ homeassistant/loader.py:1242: error: Incompatible return value type (got Module | ComponentProtocol, expected "ComponentProtocol")  [return-value]

schemathesis (https://github.com/schemathesis/schemathesis)
+ src/schemathesis/specs/openapi/error_feedback.py: note: In member "apply" of class "NumericBoundAdjustment":
+ src/schemathesis/specs/openapi/error_feedback.py:415: error: Non-overlapping container check (element type: "SpecificationAdapter", container item type: Module)  [comparison-overlap]

sphinx (https://github.com/sphinx-doc/sphinx)
+ sphinx/_cli/__init__.py: note: In function "_load_subcommand_descriptions":
+ sphinx/_cli/__init__.py:58:37: error: Incompatible types in assignment (expression has type Module, variable has type "_SubcommandModule")  [assignment]
+ sphinx/_cli/__init__.py:58:37: note: Protocol member _SubcommandModule.parser_description expected settable variable, got read-only attribute
+ sphinx/_cli/__init__.py:58:37: note: Protocol member _SubcommandModule.run expected settable variable, got read-only attribute
+ sphinx/_cli/__init__.py:58:37: note:     <1 more conflict(s) not shown>
+ sphinx/_cli/__init__.py: note: In function "_load_subcommand":
+ sphinx/_cli/__init__.py:272:37: error: Incompatible types in assignment (expression has type Module, variable has type "_SubcommandModule")  [assignment]
+ sphinx/_cli/__init__.py:272:37: note: Protocol member _SubcommandModule.parser_description expected settable variable, got read-only attribute
+ sphinx/_cli/__init__.py:272:37: note: Protocol member _SubcommandModule.run expected settable variable, got read-only attribute
+ sphinx/_cli/__init__.py:272:37: note:     <1 more conflict(s) not shown>
+ sphinx/util/docutils.py: note: In member "directive" of class "CustomReSTDispatcher":
+ sphinx/util/docutils.py:296:52: error: Argument 2 to "__call__" of "_DirectivesDispatcher" has incompatible type Module; expected "_LanguageModule"  [arg-type]
+ sphinx/util/docutils.py:296:52: note: Protocol member _LanguageModule.author_separators expected settable variable, got read-only attribute
+ sphinx/util/docutils.py:296:52: note: Protocol member _LanguageModule.bibliographic_fields expected settable variable, got read-only attribute
+ sphinx/util/docutils.py:296:52: note:     <1 more conflict(s) not shown>

scipy-stubs (https://github.com/scipy/scipy-stubs)
- tests/misc/test_submodules_empty.pyi:3: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports

hauntsaninja commented Oct 22, 2026 •
edited
Loading

Copy link
Copy Markdown
Collaborator Author

Hmm that's a little annoying. I guess I could just land the optimisation and punt on the "correctness" issue

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.

1 participant


Back | FazBrowse Home | New Git URL