Skip to content

Commit 57576fe

Browse files
authored
Merge branch 'main' into dependabot/github_actions/actions-d4b40e172f
2 parents 2c2f6a1 + 2f06414 commit 57576fe

3 files changed

Lines changed: 16 additions & 12 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Unreleased
22

3+
- Make `typing_extensions.TypeAliasType`'s `__module__` attribute writable.
4+
Backport of CPython PR
5+
[#149172](https://github.com/python/cpython/pull/149172).
36
- Fix setting of `__required_keys__` and `__optional_keys__` when inheriting
47
keys with the same name.
58
- Fix incorrect behaviour on Python 3.9 and Python 3.10 that meant that

src/test_typing_extensions.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7114,7 +7114,7 @@ def test_typing_extensions_defers_when_possible(self):
71147114
'AsyncGenerator', 'ContextManager', 'AsyncContextManager',
71157115
'ParamSpec', 'TypeVar', 'TypeVarTuple', 'get_type_hints',
71167116
}
7117-
if sys.version_info < (3, 14):
7117+
if sys.version_info < (3, 15):
71187118
exclude |= {
71197119
'TypeAliasType'
71207120
}
@@ -8286,11 +8286,12 @@ def test_cannot_set_attributes(self):
82868286
"attribute '__parameters__' of 'typing.TypeAliasType' objects is not writable",
82878287
):
82888288
Simple.__parameters__ = (T,)
8289-
with self.assertRaisesRegex(
8290-
AttributeError,
8291-
"attribute '__module__' of 'typing.TypeAliasType' objects is not writable",
8292-
):
8293-
Simple.__module__ = 42
8289+
8290+
# __module__ is the exception---it's assignable
8291+
module_sentinel = object()
8292+
Simple.__module__ = module_sentinel
8293+
self.assertIs(Simple.__module__, module_sentinel)
8294+
82948295
with self.assertRaisesRegex(
82958296
AttributeError,
82968297
"'typing.TypeAliasType' object has no attribute 'some_attribute'",

src/typing_extensions.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3677,14 +3677,14 @@ def __ror__(self, other):
36773677
return typing.Union[other, self]
36783678

36793679

3680-
# Breakpoint: https://github.com/python/cpython/pull/124795
3681-
if sys.version_info >= (3, 14):
3680+
# Breakpoint: https://github.com/python/cpython/pull/149172
3681+
if sys.version_info >= (3, 15):
36823682
TypeAliasType = typing.TypeAliasType
3683-
# <=3.13
3683+
# <=3.14
36843684
else:
36853685
# Breakpoint: https://github.com/python/cpython/pull/103764
36863686
if sys.version_info >= (3, 12):
3687-
# 3.12-3.13
3687+
# 3.12-3.14
36883688
def _is_unionable(obj):
36893689
"""Corresponds to is_unionable() in unionobject.c in CPython."""
36903690
return obj is None or isinstance(obj, (
@@ -3797,7 +3797,7 @@ def __init__(self, name: str, value, *, type_params=()):
37973797
self.__name__ = name
37983798

37993799
def __setattr__(self, name: str, value: object, /) -> None:
3800-
if hasattr(self, "__name__"):
3800+
if hasattr(self, "__name__") and name != "__module__":
38013801
self._raise_attribute_error(name)
38023802
super().__setattr__(name, value)
38033803

@@ -3808,7 +3808,7 @@ def _raise_attribute_error(self, name: str) -> Never:
38083808
# Match the Python 3.12 error messages exactly
38093809
if name == "__name__":
38103810
raise AttributeError("readonly attribute")
3811-
elif name in {"__value__", "__type_params__", "__parameters__", "__module__"}:
3811+
elif name in {"__value__", "__type_params__", "__parameters__"}:
38123812
raise AttributeError(
38133813
f"attribute '{name}' of 'typing.TypeAliasType' objects "
38143814
"is not writable"

0 commit comments

Comments
 (0)