Skip to content

Commit

Permalink
More tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JelleZijlstra committed Sep 22, 2024
1 parent 293fb0a commit 4f08276
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions Lib/test/test_annotationlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,18 @@ def test_fwdref_with_module(self):
# If globals are passed explicitly, we don't look at the module dict
ForwardRef("Format", module="annotationlib").evaluate(globals={})

def test_fwdref_to_builtin(self):
self.assertIs(ForwardRef("int").evaluate(), int)
self.assertIs(ForwardRef("int", module="collections").evaluate(), int)
self.assertIs(ForwardRef("int", owner=str).evaluate(), int)

# builtins are still searched with explicit globals
self.assertIs(ForwardRef("int").evaluate(globals={}), int)

# explicit values in globals have precedence
obj = object()
self.assertIs(ForwardRef("int").evaluate(globals={"int": obj}), obj)

def test_fwdref_value_is_cached(self):
fr = ForwardRef("hello")
with self.assertRaises(NameError):
Expand Down

0 comments on commit 4f08276

Please sign in to comment.