Skip to content

Commit 9ba5bfd

Browse files
authored
Implement test for annotated function pretty print
Add test for pretty printing functions with PEP-649 annotations
1 parent 05f031f commit 9ba5bfd

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

tests/test_pretty.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,31 @@ def meaning_of_life(question=None):
543543
assert "meaning_of_life(question=None)" in pretty.pretty(meaning_of_life)
544544

545545

546+
def test_annotated_function_pretty():
547+
"Test pretty print of a function with PEP-649 annotations"
548+
# Confirm that the name is not in scope
549+
try:
550+
b
551+
except NameError:
552+
pass
553+
else:
554+
assert False, "Unexpected 'b' found in scope"
555+
try:
556+
def f(a: b): pass
557+
except NameError as e:
558+
if e.name == 'b':
559+
# PEP-649 not available
560+
return
561+
raise
562+
# Check whether __future__.annotations is in effect
563+
# It probably shouldn't be, but to be sure:
564+
import __future__
565+
if f.__code__.co_flags & __future__.annotations.compiler_flag:
566+
assert "f(a: 'b')" in pretty.pretty(f)
567+
else:
568+
assert "f(a: b)" in pretty.pretty(f)
569+
570+
546571
class OrderedCounter(Counter, OrderedDict):
547572
"Counter that remembers the order elements are first encountered"
548573

0 commit comments

Comments
 (0)