Skip to content

Avoid unnecessary setattr lookups - #22270

Merged
hauntsaninja merged 2 commits into
python:masterfrom
hauntsaninja:protcolsetattr
Oct 29, 2026
Merged

hauntsaninja merged 2 commits into
python:masterfrom
hauntsaninja:protcolsetattr

Conversation

@hauntsaninja

@hauntsaninja hauntsaninja commented Oct 22, 2026 •

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
@github-actions

This comment has been minimized.

@hauntsaninja

hauntsaninja commented Oct 22, 2026 •

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

@ilevkivskyi

Copy link
Copy Markdown
Member

Btw I can confirm this also affects some other protocol-heavy libraries, let's just focus on the optimization part.

@ilevkivskyi

Copy link
Copy Markdown
Member

Btw a (much) better performance fix is to delete all the bizarre logic from get_method() added in #17219 That PR added a lot of slow ops to a very hot code path to fix a niche edge case (also I am not sure that PR is actually the correct solution).

@hauntsaninja

Copy link
Copy Markdown
Collaborator Author

Yeah I was looking at that redefinition one too. Will definitely at least put up an optimisation PR for it

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

@ilevkivskyi ilevkivskyi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

👍

@hauntsaninja hauntsaninja changed the title Avoid unnecessary setattr lookups, ignore object.__setattr__ Avoid unnecessary setattr lookups Oct 29, 2026
@hauntsaninja
hauntsaninja merged commit b3ab06a into python:master Oct 29, 2026
25 checks passed
@hauntsaninja
hauntsaninja deleted the protcolsetattr branch October 29, 2026 19:47
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.

2 participants