@@ -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:
@@ -7165,40 +7161,42 @@ foo: int
7165
7161
7166
7162
[case testClassScopeImportFunctionAlias]
7167
7163
class Foo:
7168
- from mod import foo
7164
+ from mod import foo # E: Unsupported class scoped import
7169
7165
bar = foo
7170
7166
7171
7167
from mod import const_foo
7172
7168
const_bar = const_foo
7173
7169
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 "
7170
+ reveal_type(Foo.foo) # N: Revealed type is "Any "
7171
+ reveal_type(Foo.bar) # N: Revealed type is "Any "
7176
7172
reveal_type(Foo.const_foo) # N: Revealed type is "builtins.int"
7177
7173
reveal_type(Foo.const_bar) # N: Revealed type is "builtins.int"
7174
+
7178
7175
[file mod.py]
7179
7176
def foo(x: int, y: int) -> int: ...
7180
7177
const_foo: int
7181
7178
7182
7179
[case testClassScopeImportModuleStar]
7183
7180
class Foo:
7184
- from mod import *
7181
+ from mod import * # E: Unsupported class scoped import
7185
7182
7186
7183
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 "
7184
+ reveal_type(Foo.bar) # N: Revealed type is "Any "
7188
7185
reveal_type(Foo.baz) # E: "Type[Foo]" has no attribute "baz" \
7189
7186
# N: Revealed type is "Any"
7187
+
7190
7188
[file mod.py]
7191
7189
foo: int
7192
7190
def bar(x: int) -> int: ...
7193
7191
7194
7192
[case testClassScopeImportFunctionNested]
7195
7193
class Foo:
7196
7194
class Bar:
7197
- from mod import baz
7195
+ from mod import baz # E: Unsupported class scoped import
7196
+
7197
+ reveal_type(Foo.Bar.baz) # N: Revealed type is "Any"
7198
+ reveal_type(Foo.Bar().baz) # N: Revealed type is "Any"
7198
7199
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
7200
[file mod.py]
7203
7201
def baz(x: int) -> int: ...
7204
7202
@@ -7221,25 +7219,44 @@ def foo(x: int, y: int) -> int: ...
7221
7219
7222
7220
[case testClassScopeImportVarious]
7223
7221
class Foo:
7224
- from mod1 import foo
7225
- from mod2 import foo # E: Name "foo" already defined on line 2
7222
+ from mod1 import foo # E: Unsupported class scoped import
7223
+ from mod2 import foo
7226
7224
7227
- from mod1 import meth1
7225
+ from mod1 import meth1 # E: Unsupported class scoped import
7228
7226
def meth1(self, a: str) -> str: ... # E: Name "meth1" already defined on line 5
7229
7227
7230
7228
def meth2(self, a: str) -> str: ...
7231
- from mod1 import meth2 # E: Name "meth2" already defined on line 8
7229
+ from mod1 import meth2 # E: Unsupported class scoped import \
7230
+ # E: Name "meth2" already defined on line 8
7232
7231
7233
7232
class Bar:
7234
- from mod1 import foo
7233
+ from mod1 import foo # E: Unsupported class scoped import
7235
7234
7236
7235
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 "
7236
+ reveal_type(Foo.foo) # N: Revealed type is "Any "
7237
+ reveal_type(Bar.foo) # N: Revealed type is "Any "
7239
7238
reveal_type(mod1.foo) # N: Revealed type is "def (x: builtins.int, y: builtins.int) -> builtins.int"
7239
+
7240
7240
[file mod1.py]
7241
7241
def foo(x: int, y: int) -> int: ...
7242
7242
def meth1(x: int) -> int: ...
7243
7243
def meth2(x: int) -> int: ...
7244
7244
[file mod2.py]
7245
7245
def foo(z: str) -> int: ...
7246
+
7247
+
7248
+ [case testClassScopeImportWithError]
7249
+ class Foo:
7250
+ from mod import meth1 # E: Unsupported class scoped import
7251
+ from mod import meth2 # E: Unsupported class scoped import
7252
+
7253
+ [file mod.pyi]
7254
+ from typing import Any, TypeVar, overload
7255
+
7256
+ @overload
7257
+ def meth1(self: Any, y: int) -> int: ...
7258
+ @overload
7259
+ def meth1(self: Any, y: str) -> str: ...
7260
+
7261
+ T = TypeVar("T")
7262
+ def meth2(self: Any, y: T) -> T: ...
0 commit comments