Skip to content

Commit bca959f

Browse files
authored
Remove unnecessary workarounds from bind_self() (#19356)
In my original PR I erroneously concluded that attribute access on `TypeVar` would result in `PyObject` attribute access after mypy is compiled, but this is actually no the case. I therefore remove some workarounds (and a bit of unused code).
1 parent 5e9d657 commit bca959f

File tree

2 files changed

+6
-14
lines changed

2 files changed

+6
-14
lines changed

mypy/checkmember.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1477,23 +1477,18 @@ def bind_self_fast(method: F, original_type: Type | None = None) -> F:
14771477
items = [bind_self_fast(c, original_type) for c in method.items]
14781478
return cast(F, Overloaded(items))
14791479
assert isinstance(method, CallableType)
1480-
func: CallableType = method
1481-
if not func.arg_types:
1480+
if not method.arg_types:
14821481
# Invalid method, return something.
14831482
return method
1484-
if func.arg_kinds[0] in (ARG_STAR, ARG_STAR2):
1483+
if method.arg_kinds[0] in (ARG_STAR, ARG_STAR2):
14851484
# See typeops.py for details.
14861485
return method
1487-
original_type = get_proper_type(original_type)
1488-
if isinstance(original_type, CallableType) and original_type.is_type_obj():
1489-
original_type = TypeType.make_normalized(original_type.ret_type)
1490-
res = func.copy_modified(
1491-
arg_types=func.arg_types[1:],
1492-
arg_kinds=func.arg_kinds[1:],
1493-
arg_names=func.arg_names[1:],
1486+
return method.copy_modified(
1487+
arg_types=method.arg_types[1:],
1488+
arg_kinds=method.arg_kinds[1:],
1489+
arg_names=method.arg_names[1:],
14941490
is_bound=True,
14951491
)
1496-
return cast(F, res)
14971492

14981493

14991494
def has_operator(typ: Type, op_method: str, named_type: Callable[[str], Instance]) -> bool:

mypy/typeops.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -472,9 +472,6 @@ class B(A): pass
472472
else:
473473
variables = func.variables
474474

475-
original_type = get_proper_type(original_type)
476-
if isinstance(original_type, CallableType) and original_type.is_type_obj():
477-
original_type = TypeType.make_normalized(original_type.ret_type)
478475
res = func.copy_modified(
479476
arg_types=func.arg_types[1:],
480477
arg_kinds=func.arg_kinds[1:],

0 commit comments

Comments
 (0)