@@ -7135,24 +7135,20 @@ class B(A): # E: Final class __main__.B has abstract attributes "foo"
7135
7135
class C:
7136
7136
class C1(XX): pass # E: Name "XX" is not defined
7137
7137
7138
- [case testClassScopeImportFunction ]
7138
+ [case testClassScopeImports ]
7139
7139
class Foo:
7140
- from mod import foo
7140
+ from mod import plain_function # E: Unsupported class scoped import
7141
+ from mod import plain_var
7141
7142
7142
- reveal_type(Foo.foo) # N: Revealed type is "def (x: builtins.int, y: builtins.int) -> builtins.int"
7143
- reveal_type(Foo().foo) # E: Invalid self argument "Foo" to attribute function "foo" with type "Callable[[int, int], int]" \
7144
- # N: Revealed type is "def (y: builtins.int) -> builtins.int"
7145
- [file mod.py]
7146
- def foo(x: int, y: int) -> int: ...
7143
+ reveal_type(Foo.plain_function) # N: Revealed type is "Any"
7144
+ reveal_type(Foo().plain_function) # N: Revealed type is "Any"
7147
7145
7148
- [case testClassScopeImportVariable]
7149
- class Foo:
7150
- from mod import foo
7146
+ reveal_type(Foo.plain_var) # N: Revealed type is "builtins.int"
7147
+ reveal_type(Foo().plain_var) # N: Revealed type is "builtins.int"
7151
7148
7152
- reveal_type(Foo.foo) # N: Revealed type is "builtins.int"
7153
- reveal_type(Foo().foo) # N: Revealed type is "builtins.int"
7154
7149
[file mod.py]
7155
- foo: int
7150
+ def plain_function(x: int, y: int) -> int: ...
7151
+ plain_var: int
7156
7152
7157
7153
[case testClassScopeImportModule]
7158
7154
class Foo:
@@ -7163,42 +7159,64 @@ reveal_type(Foo.mod.foo) # N: Revealed type is "builtins.int"
7163
7159
[file mod.py]
7164
7160
foo: int
7165
7161
7166
- [case testClassScopeImportFunctionAlias ]
7162
+ [case testClassScopeImportAlias ]
7167
7163
class Foo:
7168
- from mod import foo
7169
- bar = foo
7164
+ from mod import function # E: Unsupported class scoped import
7165
+ foo = function
7170
7166
7171
- from mod import const_foo
7172
- const_bar = const_foo
7167
+ from mod import var1
7168
+ bar = var1
7169
+
7170
+ from mod import var2
7171
+ baz = var2
7172
+
7173
+ from mod import var3
7174
+ qux = var3
7175
+
7176
+ reveal_type(Foo.foo) # N: Revealed type is "Any"
7177
+ reveal_type(Foo.function) # N: Revealed type is "Any"
7178
+
7179
+ reveal_type(Foo.bar) # N: Revealed type is "builtins.int"
7180
+ reveal_type(Foo.var1) # N: Revealed type is "builtins.int"
7181
+
7182
+ reveal_type(Foo.baz) # N: Revealed type is "mod.C"
7183
+ reveal_type(Foo.var2) # N: Revealed type is "mod.C"
7184
+
7185
+ reveal_type(Foo.qux) # N: Revealed type is "builtins.int"
7186
+ reveal_type(Foo.var3) # N: Revealed type is "builtins.int"
7173
7187
7174
- reveal_type(Foo.foo) # N: Revealed type is "def (x: builtins.int, y: builtins.int) -> builtins.int"
7175
- reveal_type(Foo.bar) # N: Revealed type is "def (x: builtins.int, y: builtins.int) -> builtins.int"
7176
- reveal_type(Foo.const_foo) # N: Revealed type is "builtins.int"
7177
- reveal_type(Foo.const_bar) # N: Revealed type is "builtins.int"
7178
7188
[file mod.py]
7179
- def foo(x: int, y: int) -> int: ...
7180
- const_foo: int
7189
+ def function(x: int, y: int) -> int: ...
7190
+ var1: int
7191
+
7192
+ class C: ...
7193
+ var2: C
7194
+
7195
+ A = int
7196
+ var3: A
7197
+
7181
7198
7182
7199
[case testClassScopeImportModuleStar]
7183
7200
class Foo:
7184
- from mod import *
7201
+ from mod import * # E: Unsupported class scoped import
7185
7202
7186
7203
reveal_type(Foo.foo) # N: Revealed type is "builtins.int"
7187
- reveal_type(Foo.bar) # N: Revealed type is "def (x: builtins.int) -> builtins.int "
7204
+ reveal_type(Foo.bar) # N: Revealed type is "Any "
7188
7205
reveal_type(Foo.baz) # E: "Type[Foo]" has no attribute "baz" \
7189
7206
# N: Revealed type is "Any"
7207
+
7190
7208
[file mod.py]
7191
7209
foo: int
7192
7210
def bar(x: int) -> int: ...
7193
7211
7194
7212
[case testClassScopeImportFunctionNested]
7195
7213
class Foo:
7196
7214
class Bar:
7197
- from mod import baz
7215
+ from mod import baz # E: Unsupported class scoped import
7216
+
7217
+ reveal_type(Foo.Bar.baz) # N: Revealed type is "Any"
7218
+ reveal_type(Foo.Bar().baz) # N: Revealed type is "Any"
7198
7219
7199
- reveal_type(Foo.Bar.baz) # N: Revealed type is "def (x: builtins.int) -> builtins.int"
7200
- reveal_type(Foo.Bar().baz) # E: Invalid self argument "Bar" to attribute function "baz" with type "Callable[[int], int]" \
7201
- # N: Revealed type is "def () -> builtins.int"
7202
7220
[file mod.py]
7203
7221
def baz(x: int) -> int: ...
7204
7222
@@ -7221,25 +7239,48 @@ def foo(x: int, y: int) -> int: ...
7221
7239
7222
7240
[case testClassScopeImportVarious]
7223
7241
class Foo:
7224
- from mod1 import foo
7225
- from mod2 import foo # E: Name "foo" already defined on line 2
7242
+ from mod1 import foo # E: Unsupported class scoped import
7243
+ from mod2 import foo
7226
7244
7227
- from mod1 import meth1
7245
+ from mod1 import meth1 # E: Unsupported class scoped import
7228
7246
def meth1(self, a: str) -> str: ... # E: Name "meth1" already defined on line 5
7229
7247
7230
7248
def meth2(self, a: str) -> str: ...
7231
- from mod1 import meth2 # E: Name "meth2" already defined on line 8
7249
+ from mod1 import meth2 # E: Unsupported class scoped import \
7250
+ # E: Name "meth2" already defined on line 8
7232
7251
7233
7252
class Bar:
7234
- from mod1 import foo
7253
+ from mod1 import foo # E: Unsupported class scoped import
7235
7254
7236
7255
import mod1
7237
- reveal_type(Foo.foo) # N: Revealed type is "def (x: builtins.int, y: builtins.int) -> builtins.int "
7238
- reveal_type(Bar.foo) # N: Revealed type is "def (x: builtins.int, y: builtins.int) -> builtins.int "
7256
+ reveal_type(Foo.foo) # N: Revealed type is "Any "
7257
+ reveal_type(Bar.foo) # N: Revealed type is "Any "
7239
7258
reveal_type(mod1.foo) # N: Revealed type is "def (x: builtins.int, y: builtins.int) -> builtins.int"
7259
+
7240
7260
[file mod1.py]
7241
7261
def foo(x: int, y: int) -> int: ...
7242
7262
def meth1(x: int) -> int: ...
7243
7263
def meth2(x: int) -> int: ...
7244
7264
[file mod2.py]
7245
7265
def foo(z: str) -> int: ...
7266
+
7267
+
7268
+ [case testClassScopeImportWithError]
7269
+ class Foo:
7270
+ from mod import meth1 # E: Unsupported class scoped import
7271
+ from mod import meth2 # E: Unsupported class scoped import
7272
+ from mod import T
7273
+
7274
+ reveal_type(Foo.T) # E: Type variable "Foo.T" cannot be used as an expression \
7275
+ # N: Revealed type is "Any"
7276
+
7277
+ [file mod.pyi]
7278
+ from typing import Any, TypeVar, overload
7279
+
7280
+ @overload
7281
+ def meth1(self: Any, y: int) -> int: ...
7282
+ @overload
7283
+ def meth1(self: Any, y: str) -> str: ...
7284
+
7285
+ T = TypeVar("T")
7286
+ def meth2(self: Any, y: T) -> T: ...
0 commit comments