Skip to content

Commit 8612f1b

Browse files
Merge branch 'main' into pep728
2 parents f143bf6 + 8184ac6 commit 8612f1b

File tree

6 files changed

+539
-96
lines changed

6 files changed

+539
-96
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ jobs:
5252
- "3.11"
5353
- "3.11.0"
5454
- "3.12"
55+
- "3.12.0"
5556
- "3.13"
57+
- "3.13.0"
5658
- "pypy3.8"
5759
- "pypy3.9"
5860
- "pypy3.10"

.github/workflows/third_party.yml

Lines changed: 18 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,20 @@ concurrency:
2626
cancel-in-progress: true
2727

2828
jobs:
29+
skip-schedule-on-fork:
30+
name: Check for schedule trigger on fork
31+
runs-on: ubuntu-latest
32+
# if 'schedule' was the trigger,
33+
# don't run it on contributors' forks
34+
if: >-
35+
github.repository == 'python/typing_extensions'
36+
|| github.event_name != 'schedule'
37+
steps:
38+
- run: true
39+
2940
pydantic:
3041
name: pydantic tests
31-
if: >-
32-
# if 'schedule' was the trigger,
33-
# don't run it on contributors' forks
34-
${{
35-
github.event_name != 'schedule'
36-
|| (
37-
github.repository == 'python/typing_extensions'
38-
&& github.event_name == 'schedule'
39-
)
40-
}}
42+
needs: skip-schedule-on-fork
4143
strategy:
4244
fail-fast: false
4345
matrix:
@@ -72,16 +74,7 @@ jobs:
7274

7375
typing_inspect:
7476
name: typing_inspect tests
75-
if: >-
76-
# if 'schedule' was the trigger,
77-
# don't run it on contributors' forks
78-
${{
79-
github.event_name != 'schedule'
80-
|| (
81-
github.repository == 'python/typing_extensions'
82-
&& github.event_name == 'schedule'
83-
)
84-
}}
77+
needs: skip-schedule-on-fork
8578
strategy:
8679
fail-fast: false
8780
matrix:
@@ -117,16 +110,7 @@ jobs:
117110
118111
pyanalyze:
119112
name: pyanalyze tests
120-
if: >-
121-
# if 'schedule' was the trigger,
122-
# don't run it on contributors' forks
123-
${{
124-
github.event_name != 'schedule'
125-
|| (
126-
github.repository == 'python/typing_extensions'
127-
&& github.event_name == 'schedule'
128-
)
129-
}}
113+
needs: skip-schedule-on-fork
130114
strategy:
131115
fail-fast: false
132116
matrix:
@@ -163,16 +147,7 @@ jobs:
163147
164148
typeguard:
165149
name: typeguard tests
166-
if: >-
167-
# if 'schedule' was the trigger,
168-
# don't run it on contributors' forks
169-
${{
170-
github.event_name != 'schedule'
171-
|| (
172-
github.repository == 'python/typing_extensions'
173-
&& github.event_name == 'schedule'
174-
)
175-
}}
150+
needs: skip-schedule-on-fork
176151
strategy:
177152
fail-fast: false
178153
matrix:
@@ -210,16 +185,7 @@ jobs:
210185
211186
typed-argument-parser:
212187
name: typed-argument-parser tests
213-
if: >-
214-
# if 'schedule' was the trigger,
215-
# don't run it on contributors' forks
216-
${{
217-
github.event_name != 'schedule'
218-
|| (
219-
github.repository == 'python/typing_extensions'
220-
&& github.event_name == 'schedule'
221-
)
222-
}}
188+
needs: skip-schedule-on-fork
223189
strategy:
224190
fail-fast: false
225191
matrix:
@@ -262,16 +228,7 @@ jobs:
262228
263229
mypy:
264230
name: stubtest & mypyc tests
265-
if: >-
266-
# if 'schedule' was the trigger,
267-
# don't run it on contributors' forks
268-
${{
269-
github.event_name != 'schedule'
270-
|| (
271-
github.repository == 'python/typing_extensions'
272-
&& github.event_name == 'schedule'
273-
)
274-
}}
231+
needs: skip-schedule-on-fork
275232
strategy:
276233
fail-fast: false
277234
matrix:
@@ -309,16 +266,7 @@ jobs:
309266
310267
cattrs:
311268
name: cattrs tests
312-
if: >-
313-
# if 'schedule' was the trigger,
314-
# don't run it on contributors' forks
315-
${{
316-
github.event_name != 'schedule'
317-
|| (
318-
github.repository == 'python/typing_extensions'
319-
&& github.event_name == 'schedule'
320-
)
321-
}}
269+
needs: skip-schedule-on-fork
322270
strategy:
323271
fail-fast: false
324272
matrix:

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ aliases that have a `Concatenate` special form as their argument.
2626
- Backport CPython PR [#124795](https://github.com/python/cpython/pull/124795):
2727
fix `TypeAliasType` not raising an error on non-tuple inputs for `type_params`.
2828
Patch by [Daraan](https://github.com/Daraan).
29+
- Backport `evaluate_forward_ref` from CPython PR
30+
[#119891](https://github.com/python/cpython/pull/119891) to evaluate `ForwardRef`s.
31+
Patch by [Daraan](https://github.com/Daraan), backporting a CPython PR by Jelle Zijlstra.
2932
- Fix that lists and ... could not be used for parameter expressions for `TypeAliasType`
3033
instances before Python 3.11.
3134
Patch by [Daraan](https://github.com/Daraan).

doc/index.rst

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -753,6 +753,37 @@ Functions
753753

754754
.. versionadded:: 4.2.0
755755

756+
.. function:: evaluate_forward_ref(forward_ref, *, owner=None, globals=None, locals=None, type_params=None, format=Format.VALUE)
757+
758+
Evaluate an :py:class:`typing.ForwardRef` as a :py:term:`type hint`.
759+
760+
This is similar to calling :py:meth:`annotationlib.ForwardRef.evaluate`,
761+
but unlike that method, :func:`!evaluate_forward_ref` also:
762+
763+
* Recursively evaluates forward references nested within the type hint.
764+
However, the amount of recursion is limited in Python 3.8 and 3.10.
765+
* Raises :exc:`TypeError` when it encounters certain objects that are
766+
not valid type hints.
767+
* Replaces type hints that evaluate to :const:`!None` with
768+
:class:`types.NoneType`.
769+
* Supports the :attr:`Format.FORWARDREF` and
770+
:attr:`Format.STRING` formats.
771+
772+
*forward_ref* must be an instance of :py:class:`typing.ForwardRef`.
773+
*owner*, if given, should be the object that holds the annotations that
774+
the forward reference derived from, such as a module, class object, or function.
775+
It is used to infer the namespaces to use for looking up names.
776+
*globals* and *locals* can also be explicitly given to provide
777+
the global and local namespaces.
778+
*type_params* is a tuple of :py:ref:`type parameters <type-params>` that
779+
are in scope when evaluating the forward reference.
780+
This parameter must be provided (though it may be an empty tuple) if *owner*
781+
is not given and the forward reference does not already have an owner set.
782+
*format* specifies the format of the annotation and is a member of
783+
the :class:`Format` enum.
784+
785+
.. versionadded:: 4.13.0
786+
756787
.. function:: get_annotations(obj, *, globals=None, locals=None, eval_str=False, format=Format.VALUE)
757788

758789
See :py:func:`inspect.get_annotations`. In the standard library since Python 3.10.
@@ -764,7 +795,7 @@ Functions
764795
of the :pep:`649` behavior on versions of Python that do not support it.
765796

766797
The purpose of this backport is to allow users who would like to use
767-
:attr:`Format.FORWARDREF` or :attr:`Format.SOURCE` semantics once
798+
:attr:`Format.FORWARDREF` or :attr:`Format.STRING` semantics once
768799
:pep:`649` is implemented, but who also
769800
want to support earlier Python versions, to simply write::
770801

@@ -911,7 +942,7 @@ Enums
911942
``typing_extensions`` emulates this value on versions of Python which do
912943
not support :pep:`649` by returning the same value as for ``VALUE`` semantics.
913944

914-
.. attribute:: SOURCE
945+
.. attribute:: STRING
915946

916947
Equal to 3. When :pep:`649` is implemented, this format will produce an annotation
917948
dictionary where the values have been replaced by strings containing

0 commit comments

Comments
 (0)