8000 stubtest: distinguish metaclass attributes from class attributes by tungol · Pull Request #18314 · python/mypy · GitHub
[go: up one dir, main page]

Skip to content

stubtest: distinguish metaclass attributes from class attributes #18314

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 3 commits into from
Dec 20, 2024
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
Next Next commit
stubtest: distinguish metaclass attributes from class attributes
If the runtime attribute of a class is actually from the metaclass,
consider it to be MISSING at runtime.
  • Loading branch information
tungol committed Dec 19, 2024
commit 73804f33f554590a5826303c86028ff4d61645b0
7 changes: 7 additions & 0 deletions mypy/stubtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,13 @@ def verify_typeinfo(
# Catch all exceptions in case the runtime raises an unexpected exception
# from __getattr__ or similar.
continue

# If it came from the metaclass, consider the runtime_attr to be MISSING
# for a more accurate message
if runtime_attr is not MISSING and type(runtime) != runtime:
Copy link
Member

Choose a reason for hiding this comment

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

Should != be is not?

And can you add a test that changes behavior with this patch?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think you're right. I'll have a test ready in a little bit.

if getattr(runtime_attr, "__objclass__", None) is type(runtime):
runtime_attr = MISSING

# Do not error for an object missing from the stub
# If the runtime object is a types.WrapperDescriptorType object
# and has a non-special dunder name.
Expand Down
Loading
0