File tree Expand file tree Collapse file tree 1 file changed +25
-0
lines changed
Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Original file line number Diff line number Diff 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+
546571class OrderedCounter (Counter , OrderedDict ):
547572 "Counter that remembers the order elements are first encountered"
548573
You can’t perform that action at this time.
0 commit comments