Skip to content

Cache type_object_type() #19514

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 27, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Do not cache another bug
  • Loading branch information
ilevkivskyi committed Jul 26, 2025
commit b8cff96df7faa3d63e5ae5b8023ac4e4bfceabfd
9 changes: 8 additions & 1 deletion mypy/typeops.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,12 @@ def type_object_type(info: TypeInfo, named_type: Callable[[str], Instance]) -> P
init_index = info.mro.index(init_method.node.info)
new_index = info.mro.index(new_method.node.info)

fallback = info.metaclass_type or named_type("builtins.type")
if checker_state.type_checker:
builtins_type = checker_state.type_checker.named_type("builtins.type")
else:
builtins_type = named_type("builtins.type")

fallback = info.metaclass_type or builtins_type
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we keep it lazy (only call named_type if info.metaclass_type is None)?

if init_index < new_index:
method: FuncBase | Decorator = init_method.node
is_new = False
Expand Down Expand Up @@ -1270,6 +1275,8 @@ def get_protocol_member(
if member == "__call__" and class_obj:
# Special case: class objects always have __call__ that is just the constructor.

# TODO: this is wrong, it creates callables that are not recognized as type objects.
# Long-term, we should probably get rid of this callback argument altogether.
def named_type(fullname: str) -> Instance:
return Instance(left.type.mro[-1], [])

Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy