As noted on the issue, making get_annotate_function() support both types and
mappings is problematic because one object may be both. So let's add a new one
that works with any mapping.
This leaves get_annotate_function() not very useful, so remove it.
I started with just moving ForwardRefTests to test_annotationlib,
but found that it contained a number of tests for no_type_check, which
I moved to a new class in test_typing, as well as a number of tests that
are more appropriately classified as tests for get_type_hints().
One test, test_forward_equality_namespace(), was somewhat accidentally
depending on a global class A in test_typing. I added a class A in the
annotationlib tests instead.
Also add a useful comment in annotationlib.
Often, ForwardRefs represent a single simple name. In that case, we
can avoid going through the overhead of creating AST nodes and code
objects and calling eval(): we can simply look up the name directly
in the relevant namespaces.
Co-authored-by: Victor Stinner <vstinner@python.org>
We were sometimes passing None as the globals argument to eval(), which makes it
inherit the globals from the calling scope. Instead, ensure that globals is always
non-None. The test was passing accidentally because I passed "annotationlib" as a
module object; fix that. Also document the parameters to ForwardRef() and remove
two unused private ones.
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>