Skip to content
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

Explicit decorated __new__, __class_getitem__ and __init_subclass__ #15353

Merged
merged 10 commits into from
Jul 5, 2023
Prev Previous commit
Next Next commit
Fix primer error, minor polish.
  • Loading branch information
erikkemperman committed Jun 9, 2023
commit 3064f3b996117c8e6810e7f9764682534671c3ea
6 changes: 1 addition & 5 deletions mypy/checkmember.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,11 +319,7 @@ def analyze_instance_member_access(
mx.msg.cant_assign_to_method(mx.context)
signature = function_type(method, mx.named_type("builtins.function"))
signature = freshen_all_functions_type_vars(signature)
if name == "__new__" or method.is_static:
# __new__ is special and behaves like a static method -- don't strip
# the first argument.
pass
else:
if not method.is_static:
if name != "__call__":
# TODO: use proper treatment of special methods on unions instead
# of this hack here and below (i.e. mx.self_type).
Expand Down
2 changes: 1 addition & 1 deletion mypy/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ class FuncBase(Node):
"info",
"is_property",
"is_class", # Uses "@classmethod" (explicit or implicit)
"is_static", # Uses "@staticmethod"
"is_static", # Uses "@staticmethod" (explicit or implicit)
"is_final", # Uses "@final"
"is_explicit_override", # Uses "@override"
"_fullname",
Expand Down
2 changes: 1 addition & 1 deletion mypy/semanal.py
Original file line number Diff line number Diff line change
Expand Up @@ -1383,7 +1383,7 @@ def analyze_function_body(self, defn: FuncItem) -> None:
# The first argument of a non-static, non-class method is like 'self'
# (though the name could be different), having the enclosing class's
# instance type.
if is_method and not defn.is_static and defn.arguments:
if is_method and (not defn.is_static or defn.name == "__new__") and defn.arguments:
if not defn.is_class:
defn.arguments[0].variable.is_self = True
else:
Expand Down