File tree 2 files changed +24
-1
lines changed
2 files changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -3616,7 +3616,7 @@ def accept(self,
3616
3616
not always_allow_any and
3617
3617
not self .chk .is_stub and
3618
3618
self .chk .in_checked_function () and
3619
- has_any_type (typ )):
3619
+ has_any_type (typ ) and not self . chk . current_node_deferred ):
3620
3620
self .msg .disallowed_any_type (typ , node )
3621
3621
3622
3622
if not self .chk .in_checked_function () or self .chk .current_node_deferred :
Original file line number Diff line number Diff line change @@ -6489,3 +6489,26 @@ reveal_type(Foo().y) # N: Revealed type is 'builtins.list[Any]'
6489
6489
class Foo:
6490
6490
def bad(): # E: Method must have at least one argument
6491
6491
self.x = 0 # E: Name 'self' is not defined
6492
+
6493
+ [case testTypeAfterAttributeAccessWithDisallowAnyExpr]
6494
+ # flags: --disallow-any-expr
6495
+
6496
+ def access_before_declaration(self) -> None:
6497
+ obj = Foo('bar')
6498
+ obj.value
6499
+ x = 1
6500
+
6501
+ reveal_type(x) # N: Revealed type is 'builtins.int'
6502
+ x = x + 1
6503
+
6504
+ class Foo:
6505
+ def __init__(self, value: str) -> None:
6506
+ self.value = value
6507
+
6508
+ def access_after_declaration(self) -> None:
6509
+ obj = Foo('bar')
6510
+ obj.value
6511
+ x = 1
6512
+
6513
+ reveal_type(x) # N: Revealed type is 'builtins.int'
6514
+ x = x + 1
You can’t perform that action at this time.
0 commit comments