Skip to content

Commit 73804f3

Browse files
committed
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.
1 parent f445369 commit 73804f3

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

mypy/stubtest.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,13 @@ def verify_typeinfo(
568568
# Catch all exceptions in case the runtime raises an unexpected exception
569569
# from __getattr__ or similar.
570570
continue
571+
572+
# If it came from the metaclass, consider the runtime_attr to be MISSING
573+
# for a more accurate message
574+
if runtime_attr is not MISSING and type(runtime) != runtime:
575+
if getattr(runtime_attr, "__objclass__", None) is type(runtime):
576+
runtime_attr = MISSING
577+
571578
# Do not error for an object missing from the stub
572579
# If the runtime object is a types.WrapperDescriptorType object
573580
# and has a non-special dunder name.

0 commit comments

Comments
 (0)