Skip to content

Commit 0da67dd

Browse files
authored
Fix plugin invocation on classmethod calls through Type (python#7969)
We weren't computing the proper fullname through TypeType (only through type obj callables. Maybe we should get rid of those...) This fixes these getting missed by suggestions.
1 parent f5656f4 commit 0da67dd

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

mypy/checkexpr.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,8 @@ def method_fullname(self, object_type: Type, method_name: str) -> Optional[str]:
382382
# We "unwrap" it to a regular type, as the class/instance method difference doesn't
383383
# affect the fully qualified name.
384384
object_type = get_proper_type(object_type.ret_type)
385+
elif isinstance(object_type, TypeType):
386+
object_type = object_type.item
385387

386388
type_name = None
387389
if isinstance(object_type, Instance):

test-data/unit/fine-grained-suggest.test

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -684,10 +684,11 @@ No guesses that match criteria!
684684
() -> None
685685
==
686686

687-
[case testSuggestInferClassMethod]
687+
[case testSuggestClassMethod]
688688
# flags: --strict-optional
689689
# suggest: foo.F.bar
690690
# suggest: foo.F.baz
691+
# suggest: foo.F.eggs
691692
[file foo.py]
692693
class F:
693694
@classmethod
@@ -698,6 +699,15 @@ class F:
698699
def baz(x, y):
699700
return x
700701

702+
@classmethod
703+
def spam(cls):
704+
# type: () -> None
705+
cls.eggs(4)
706+
707+
@classmethod
708+
def eggs(cls, x):
709+
pass
710+
701711
[file bar.py]
702712
from foo import F
703713
def bar(iany) -> None:
@@ -709,6 +719,7 @@ def bar(iany) -> None:
709719
[out]
710720
(int, int) -> int
711721
(str, int) -> str
722+
(int) -> None
712723
==
713724

714725
[case testSuggestColonBasic]

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy