Skip to content

Commit

Permalink
Removed an erroneous check added in 888a8c5
Browse files Browse the repository at this point in the history
  • Loading branch information
agronholm committed Sep 10, 2023
1 parent bf71c4f commit b218fd8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
1 change: 0 additions & 1 deletion src/typeguard/_transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -930,7 +930,6 @@ def visit_FunctionDef(
and self._memo.parent is not None
and isinstance(self._memo.parent.node, ClassDef)
and node.name == "__new__"
and self._memo.parent.node.name in self._memo.local_names
):
first_args_expr = Name(node.args.args[0].arg, ctx=Load())
cls_name = Name(self._memo.parent.node.name, ctx=Store())
Expand Down
11 changes: 4 additions & 7 deletions tests/test_transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,7 @@ def __new__(cls) -> Self:
class Foo:
def __new__(cls) -> Self:
Foo = cls
memo = TypeCheckMemo(globals(), locals(), self_type=cls)
return check_return_type('Foo.__new__', super().__new__(cls), \
Self, memo)
Expand All @@ -661,8 +662,7 @@ def test_new_with_explicit_class_name() -> None:
class A:
def __new__(cls) -> 'A':
obj: A = object.__new__(cls)
return obj
return object.__new__(cls)
"""
)
)
Expand All @@ -672,17 +672,14 @@ def __new__(cls) -> 'A':
== dedent(
"""
from typeguard import TypeCheckMemo
from typeguard._functions import check_return_type, \
check_variable_assignment
from typeguard._functions import check_return_type
class A:
def __new__(cls) -> 'A':
A = cls
memo = TypeCheckMemo(globals(), locals(), self_type=cls)
obj: A = check_variable_assignment(object.__new__(cls), 'obj', A, \
memo)
return check_return_type('A.__new__', obj, A, memo)
return check_return_type('A.__new__', object.__new__(cls), A, memo)
"""
).strip()
)
Expand Down

0 comments on commit b218fd8

Please sign in to comment.