Skip to content

Commit 611de40

Browse files
committed
enhance tests
1 parent e0249cc commit 611de40

File tree

1 file changed

+42
-1
lines changed

1 file changed

+42
-1
lines changed

Lib/test/test_type_annotations.py

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,6 @@ def check_scopes(self, code, true_annos, false_annos):
476476

477477
def test_with(self):
478478
code = """
479-
import contextlib
480479
class Swallower:
481480
def __enter__(self):
482481
pass
@@ -501,6 +500,21 @@ def test_simple_if(self):
501500
"""
502501
self.check_scopes(code, {"in_if": "if"}, {"in_if": "else"})
503502

503+
def test_if_elif(self):
504+
code = """
505+
if not len:
506+
in_if: "if"
507+
elif {cond}:
508+
in_elif: "elif"
509+
else:
510+
in_else: "else"
511+
"""
512+
self.check_scopes(
513+
code,
514+
{"in_elif": "elif"},
515+
{"in_else": "else"}
516+
)
517+
504518
def test_try(self):
505519
code = """
506520
try:
@@ -562,6 +576,33 @@ def test_for(self):
562576
{"in_else": "else"}
563577
)
564578

579+
def test_match(self):
580+
code = """
581+
match {cond}:
582+
case True:
583+
x: "true"
584+
case False:
585+
x: "false"
586+
"""
587+
self.check_scopes(
588+
code,
589+
{"x": "true"},
590+
{"x": "false"}
591+
)
592+
593+
def test_nesting_override(self):
594+
code = """
595+
if {cond}:
596+
x: "foo"
597+
if {cond}:
598+
x: "bar"
599+
"""
600+
self.check_scopes(
601+
code,
602+
{"x": "bar"},
603+
{}
604+
)
605+
565606
def test_nesting_outer(self):
566607
code = """
567608
if {cond}:

0 commit comments

Comments
 (0)