Skip to content

Commit 2d6cc35

Browse files
author
Guido van Rossum
committed
Don't raise in TypeAnalyser.visit_type_var().
The raise caused two specific errors that are now fixed. The fix causes no new errors. I don't understand what's going on, but the raise has been there since prehistoric times, and may well have been misguided in the first place. Fixes #1898.
1 parent b20ee6a commit 2d6cc35

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

mypy/typeanal.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ def visit_instance(self, t: Instance) -> Type:
201201
return t
202202

203203
def visit_type_var(self, t: TypeVarType) -> Type:
204-
raise RuntimeError('TypeVarType is already analyzed')
204+
return t
205205

206206
def visit_callable_type(self, t: CallableType) -> Type:
207207
return t.copy_modified(arg_types=self.anal_array(t.arg_types),

test-data/unit/check-generics.test

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -857,3 +857,21 @@ from typing import TypeVar, Container
857857
T = TypeVar('T')
858858
def f(x: Container[T]) -> T: ...
859859
reveal_type(f((1, 2))) # E: Revealed type is 'builtins.int*'
860+
861+
[case testClassMethodInGenericClassWithGenericConstructorArg]
862+
from typing import TypeVar, Generic
863+
T = TypeVar('T')
864+
class A(Generic[T]):
865+
def __init__(self, a: T) -> None: pass
866+
@classmethod
867+
def f(cls) -> None: pass
868+
[builtins fixtures/classmethod.py]
869+
870+
[case testClassMethodInClassWithGenericConstructor]
871+
from typing import TypeVar, Generic
872+
T = TypeVar('T')
873+
class A:
874+
def __init__(self, a: T) -> None: pass
875+
@classmethod
876+
def f(cls) -> None: pass
877+
[builtins fixtures/classmethod.py]

0 commit comments

Comments
 (0)