PEP 749: use `annotationlib` as the proposed module name throughout (#3833)

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
This commit is contained in:
qexat 2024-06-10 01:00:31 +02:00 committed by GitHub
parent 93557b3808
commit c5915b3ae0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 5 additions and 5 deletions

View File

@ -498,7 +498,7 @@ These attributes are read-only.
Usually, users would use these attributes in combinations with
``annotationlib.call_evaluate_function``. For example, to get a ``TypeVar``'s bound
in SOURCE format, one could write
``annotationlib.call_evaluate_function(T.evaluate_bound, annotations.Format.SOURCE)``.
``annotationlib.call_evaluate_function(T.evaluate_bound, annotationlib.Format.SOURCE)``.
Miscellaneous implementation details
====================================
@ -670,7 +670,7 @@ Accessing ``.type`` might throw an error:
File "<python-input-4>", line 1, in <module>
field.type
File ".../dataclasses.py", line 308, in type
annos = self._annotate(annotations.Format.VALUE)
annos = self._annotate(annotationlib.Format.VALUE)
File "<python-input-2>", line 3, in __annotate__
x: undefined
^^^^^^^^^
@ -680,9 +680,9 @@ But users could use ``annotationlib.call_evaluate_function`` to get the type in
.. code:: pycon
>>> annotations.call_evaluate_function(field.evaluate_type, annotations.Format.SOURCE)
>>> annotationlib.call_evaluate_function(field.evaluate_type, annotationlib.Format.SOURCE)
'undefined'
>>> annotations.call_evaluate_function(field.evaluate_type, annotations.Format.FORWARDREF)
>>> annotationlib.call_evaluate_function(field.evaluate_type, annotationlib.Format.FORWARDREF)
ForwardRef('undefined')
Other variations are possible. For example, we could leave the ``type`` attribute unchanged,
@ -723,7 +723,7 @@ code execution even with no access to any globals or builtins. For example:
>>> def f(x: (1).__class__.__base__.__subclasses__()[-1].__init__.__builtins__["print"]("Hello world")): pass
...
>>> annotations.get_annotations(f, format=annotations.Format.SOURCE)
>>> annotationlib.get_annotations(f, format=annotationlib.Format.SOURCE)
Hello world
{'x': 'None'}