Skip to content

Commit 60ca471

Browse files
committed
python#1727: test classmethod in nested class
1 parent 9b07239 commit 60ca471

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

‎test-data/unit/check-classes.test‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,33 @@ class C:
631631
reveal_type(C.create) # E: Revealed type is 'def (arg: builtins.int) -> __main__.C'
632632
[builtins fixtures/classmethod.pyi]
633633

634+
[case testClassmethodBeforeInitInNestedClass]
635+
class A:
636+
@classmethod
637+
def create(cls, arg: int) -> 'A':
638+
reveal_type(cls) # E: Revealed type is 'def (arg: builtins.int) -> __main__.A'
639+
reveal_type(cls(arg)) # E: Revealed type is '__main__.A'
640+
cls() # E: Too few arguments for "A"
641+
return cls(arg)
642+
643+
class B:
644+
@classmethod
645+
def create(cls, arg: str) -> 'A.B':
646+
reveal_type(cls) # E: Revealed type is 'def (arg: builtins.str) -> __main__.A.B'
647+
reveal_type(cls(arg)) # E: Revealed type is '__main__.A.B'
648+
cls() # E: Too few arguments for "B"
649+
return cls(arg)
650+
651+
def __init__(self, arg: 'str') -> None:
652+
self._arg: str = arg
653+
654+
def __init__(self, arg: 'int') -> None:
655+
self._arg: int = arg
656+
657+
reveal_type(A.create) # E: Revealed type is 'def (arg: builtins.int) -> __main__.A'
658+
reveal_type(A.B.create) # E: Revealed type is 'def (arg: builtins.str) -> __main__.A.B'
659+
[builtins fixtures/classmethod.pyi]
660+
634661
[case testClassmethodBeforeInitInGenericClass]
635662
from typing import Generic, TypeVar
636663
T = TypeVar('T')

0 commit comments

Comments
 (0)