Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_forward_ref_policy_guess(self, checker):
import collections
def unresolvable_annotation(x: 'OrderedDict'): # noqa
pass
checker.annotation_policy = ForwardRefPolicy.GUESS
with checker, pytest.warns(TypeHintWarning) as record:
unresolvable_annotation(collections.OrderedDict())
assert len(record) == 1
assert str(record[0].message).startswith("Replaced forward declaration 'OrderedDict' in")
assert unresolvable_annotation.__annotations__['x'] is collections.OrderedDict
def test_forward_ref_policy_resolution_fails(self, checker, policy):
def unresolvable_annotation(x: 'OrderedDict'): # noqa
pass
checker.annotation_policy = policy
gc.collect() # prevent find_function() from finding more than one instance of the function
with checker, pytest.warns(TypeHintWarning) as record:
unresolvable_annotation({})
assert len(record) == 1
assert ("unresolvable_annotation: name 'OrderedDict' is not defined"
in str(record[0].message))
assert 'x' not in unresolvable_annotation.__annotations__