-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Exclude the same special attributes from Protocol as CPython #15490
Changes from 4 commits
2966617
67872e8
e2edbf9
87ddf42
b348e71
f473ea0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3017,6 +3017,24 @@ class is generic then it will be a type constructor of higher kind. | |
"is_intersection", | ||
] | ||
|
||
# Special attributes not collected as protocol members by Python 3.12 | ||
# See typing._SPECIAL_NAMES | ||
EXCLUDED_ATTRIBUTES: Final = frozenset( | ||
{ | ||
"__abstractmethods__", | ||
"__annotations__", | ||
"__dict__", | ||
"__doc__", | ||
"__init__", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. CC @AlexWaygood about that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think excluding In general, constructors and initialisers aren't thought to be relevant to whether or not a class abides by the Liskov Substitution Principle. In general, there's no guarantee that just because class There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Python had a change in 3.11 so that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I found an old discussion of this topic at #3823. |
||
"__module__", | ||
"__new__", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am also not sure about |
||
"__slots__", | ||
"__subclasshook__", | ||
"__weakref__", | ||
"__class_getitem__", # Since Python 3.9 | ||
} | ||
) | ||
|
||
def __init__(self, names: SymbolTable, defn: ClassDef, module_name: str) -> None: | ||
"""Initialize a TypeInfo.""" | ||
super().__init__() | ||
|
@@ -3115,6 +3133,8 @@ def protocol_members(self) -> list[str]: | |
if isinstance(node.node, (TypeAlias, TypeVarExpr, MypyFile)): | ||
# These are auxiliary definitions (and type aliases are prohibited). | ||
continue | ||
if name in self.EXCLUDED_ATTRIBUTES: | ||
continue | ||
members.add(name) | ||
return sorted(list(members)) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that module level constant is better :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I moved it back above the class. Unless it should go somewhere else.