Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
More tests
  • Loading branch information
JelleZijlstra committed Sep 22, 2024
commit 4f08276e95337d4d4505ae50ff94b53f25dab060
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