Skip to content

Commit 2b38551

Browse files
Jdwashin9Jdwashin9
authored andcommitted
adding test case to suggestions.py
1 parent ee5f4b9 commit 2b38551

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

mypy/suggestions.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
TypeOfAny,
7575
TypeStrVisitor,
7676
TypeTranslator,
77+
TypeVarType,
7778
UninhabitedType,
7879
UnionType,
7980
get_proper_type,
@@ -650,13 +651,17 @@ def extract_from_decorator(self, node: Decorator) -> FuncDef | None:
650651
if not isinstance(typ, FunctionLike):
651652
return None
652653
for ct in typ.items:
653-
if not (
654-
len(ct.arg_types) == 1
655-
# and isinstance(ct.arg_types[0], TypeVarType)
656-
and ct.arg_types[0] == ct.ret_type
657-
):
654+
if len(ct.arg_types) != 1:
658655
return None
659656

657+
arg_type = get_proper_type(ct.arg_types[0])
658+
ret_type = get_proper_type(ct.ret_type)
659+
660+
if isinstance(arg_type, TypeVarType) and arg_type == ret_type:
661+
continue
662+
663+
return None
664+
660665
return node.func
661666

662667
def try_type(self, func: FuncDef, typ: ProperType) -> list[str]:

mypy/test_decorator_suggestion.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,8 @@ def dec(f: Callable[P, R]) -> Callable[P, R]:
1212
@dec
1313
def f() -> None:
1414
print("hello world")
15+
16+
17+
@dec
18+
def foo() -> None:
19+
print()

0 commit comments

Comments
 (0)