Skip to content

Commit 9b07239

Browse files
committed
python#1727: more unit tests
1 parent b0f7a24 commit 9b07239

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

test-data/unit/check-classes.test

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,9 @@ main:5: error: Incompatible types in assignment (expression has type "D2", varia
620620
class C:
621621
@classmethod
622622
def create(cls, arg: int) -> 'C':
623+
reveal_type(cls) # E: Revealed type is 'def (arg: builtins.int) -> __main__.C'
624+
reveal_type(cls(arg)) # E: Revealed type is '__main__.C'
625+
cls() # E: Too few arguments for "C"
623626
return cls(arg)
624627

625628
def __init__(self, arg: 'int') -> None:
@@ -628,6 +631,20 @@ class C:
628631
reveal_type(C.create) # E: Revealed type is 'def (arg: builtins.int) -> __main__.C'
629632
[builtins fixtures/classmethod.pyi]
630633

634+
[case testClassmethodBeforeInitInGenericClass]
635+
from typing import Generic, TypeVar
636+
T = TypeVar('T')
637+
class C(Generic[T]):
638+
@classmethod
639+
def create(cls, arg: T) -> 'C':
640+
cls() # E: Too few arguments for "C"
641+
return cls(arg, arg)
642+
643+
def __init__(self, arg1: T, arg2: T) -> None:
644+
self._arg1 = arg1
645+
self._arg2 = arg2
646+
[builtins fixtures/classmethod.pyi]
647+
631648

632649
-- Attribute access in class body
633650
-- ------------------------------

test-data/unit/check-overloading.test

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,21 @@ class A:
523523
def __init__(self, b: 'B') -> None: pass
524524
class B: pass
525525

526+
[case testOverloadedInitAndClassMethod]
527+
from foo import *
528+
[file foo.pyi]
529+
from typing import overload
530+
class A:
531+
@classmethod
532+
def from_int(cls, x: int) -> 'A':
533+
reveal_type(cls) # E: Revealed type is 'Any'
534+
return cls(x)
535+
@overload
536+
def __init__(self, a: int) -> None: pass
537+
@overload
538+
def __init__(self, b: str) -> None: pass
539+
[builtins fixtures/classmethod.pyi]
540+
526541
[case testIntersectionTypeCompatibility]
527542
from foo import *
528543
[file foo.pyi]

0 commit comments

Comments
 (0)