diff --git a/mypy/checkmember.py b/mypy/checkmember.py index 83c4660cb1b1..6c934dccb022 100644 --- a/mypy/checkmember.py +++ b/mypy/checkmember.py @@ -406,7 +406,7 @@ def analyze_class_attribute_access(itype: Instance, return AnyType() if isinstance(node.node, TypeVarExpr): - msg.fail('Type variable "{}.{}" is invalid in a runtime context'.format( + msg.fail('Type variable "{}.{}" cannot be used as an expression'.format( itype.type.name(), name), context) return AnyType() diff --git a/test-data/unit/check-typevar-values.test b/test-data/unit/check-typevar-values.test index 29c72add0624..36df2235a209 100644 --- a/test-data/unit/check-typevar-values.test +++ b/test-data/unit/check-typevar-values.test @@ -505,8 +505,8 @@ class C: reveal_type(l) # E: Revealed type is 'builtins.list[T`-1]' y: C.T = x l.append(x) - C.T # E: Type variable "C.T" is invalid in a runtime context - A = C.T # E: Type variable "C.T" is invalid in a runtime context + C.T # E: Type variable "C.T" cannot be used as an expression + A = C.T # E: Type variable "C.T" cannot be used as an expression return l[0] [builtins fixtures/list.pyi]