Skip to content

Commit 45a5ea7

Browse files
h-joocopybara-github
authored andcommitted
Add a test case for cases where it falsely reports a deleted local variable when it could be found in the global scope.
PiperOrigin-RevId: 752173377
1 parent e53a409 commit 45a5ea7

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

pytype/tests/test_typing1.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,35 @@ def test_supported_construct_in_supported_version(self):
682682
from typing import Final
683683
""")
684684

685+
@test_utils.skipBeforePy(
686+
(3, 12),
687+
"This only happens with 3.12 where it puts LOAD_FAST_AND_CLEAR op",
688+
)
689+
def test_not_deleted(self):
690+
# TODO(b/414069834): This shouldn't be an error.
691+
errors = self.CheckWithErrors("""
692+
import re
693+
694+
class Foo():
695+
A = [re.compile(r) for r in (r'___', )]
696+
B = re.compile(r"dummy") # name-error[e]
697+
""")
698+
self.assertErrorRegexes(errors, {"e": r"Name 're' is not defined"})
699+
700+
@test_utils.skipBeforePy(
701+
(3, 12),
702+
"This only happens with 3.12 where it puts LOAD_FAST_AND_CLEAR op",
703+
)
704+
def test_not_deleted2(self):
705+
# TODO(b/414069834): This shouldn't be an error.
706+
errors = self.CheckWithErrors("""
707+
class Foo:
708+
x = 1
709+
ys = [y + x for y in [1]] # name-error[e]
710+
z = x + x
711+
""")
712+
self.assertErrorRegexes(errors, {"e": r"Name 'x' is not defined"})
713+
685714

686715
if __name__ == "__main__":
687716
test_base.main()

0 commit comments

Comments
 (0)