add updates libs

This commit is contained in:
Christoph Brandau
2026-06-18 17:21:58 +02:00
parent 91ce762570
commit 41f331d4c4
150 changed files with 8249 additions and 2550 deletions
+91 -18
View File
@@ -14,6 +14,7 @@ import types as _types
import typing
import warnings
# Breakpoint: https://github.com/python/cpython/pull/119891
if sys.version_info >= (3, 14):
import annotationlib
@@ -70,6 +71,7 @@ __all__ = [
'clear_overloads',
'dataclass_transform',
'deprecated',
'disjoint_base',
'Doc',
'evaluate_forward_ref',
'get_overloads',
@@ -100,6 +102,7 @@ __all__ = [
'TypeGuard',
'TypeIs',
'TYPE_CHECKING',
'type_repr',
'Never',
'NoReturn',
'ReadOnly',
@@ -151,6 +154,7 @@ __all__ = [
# for backward compatibility
PEP_560 = True
GenericMeta = type
# Breakpoint: https://github.com/python/cpython/pull/116129
_PEP_696_IMPLEMENTED = sys.version_info >= (3, 13, 0, "beta")
# Added with bpo-45166 to 3.10.1+ and some 3.9 versions
@@ -168,6 +172,7 @@ class _Sentinel:
_marker = _Sentinel()
# Breakpoint: https://github.com/python/cpython/pull/27342
if sys.version_info >= (3, 10):
def _should_collect_from_parameters(t):
return isinstance(
@@ -189,6 +194,7 @@ T_co = typing.TypeVar('T_co', covariant=True) # Any type covariant containers.
T_contra = typing.TypeVar('T_contra', contravariant=True) # Ditto contravariant.
# Breakpoint: https://github.com/python/cpython/pull/31841
if sys.version_info >= (3, 11):
from typing import Any
else:
@@ -277,6 +283,7 @@ class _ExtensionsSpecialForm(typing._SpecialForm, _root=True):
Final = typing.Final
# Breakpoint: https://github.com/python/cpython/pull/30530
if sys.version_info >= (3, 11):
final = typing.final
else:
@@ -315,11 +322,39 @@ else:
return f
if hasattr(typing, "disjoint_base"): # 3.15
disjoint_base = typing.disjoint_base
else:
def disjoint_base(cls):
"""This decorator marks a class as a disjoint base.
Child classes of a disjoint base cannot inherit from other disjoint bases that are
not parent classes of the disjoint base.
For example:
@disjoint_base
class Disjoint1: pass
@disjoint_base
class Disjoint2: pass
class Disjoint3(Disjoint1, Disjoint2): pass # Type checker error
Type checkers can use knowledge of disjoint bases to detect unreachable code
and determine when two types can overlap.
See PEP 800."""
cls.__disjoint_base__ = True
return cls
def IntVar(name):
return typing.TypeVar(name)
# A Literal bug was fixed in 3.11.0, 3.10.1 and 3.9.8
# Breakpoint: https://github.com/python/cpython/pull/29334
if sys.version_info >= (3, 10, 1):
Literal = typing.Literal
else:
@@ -480,6 +515,7 @@ Text = typing.Text
TYPE_CHECKING = typing.TYPE_CHECKING
# Breakpoint: https://github.com/python/cpython/pull/118681
if sys.version_info >= (3, 13, 0, "beta"):
from typing import AsyncContextManager, AsyncGenerator, ContextManager, Generator
else:
@@ -590,6 +626,7 @@ def _caller(depth=1, default='__main__'):
# `__match_args__` attribute was removed from protocol members in 3.13,
# we want to backport this change to older Python versions.
# Breakpoint: https://github.com/python/cpython/pull/110683
if sys.version_info >= (3, 13):
Protocol = typing.Protocol
else:
@@ -770,6 +807,7 @@ else:
cls.__init__ = _no_init
# Breakpoint: https://github.com/python/cpython/pull/113401
if sys.version_info >= (3, 13):
runtime_checkable = typing.runtime_checkable
else:
@@ -830,6 +868,7 @@ runtime = runtime_checkable
# Our version of runtime-checkable protocols is faster on Python <=3.11
# Breakpoint: https://github.com/python/cpython/pull/112717
if sys.version_info >= (3, 12):
SupportsInt = typing.SupportsInt
SupportsFloat = typing.SupportsFloat
@@ -1159,6 +1198,7 @@ else:
mutable_keys.add(annotation_key)
readonly_keys.discard(annotation_key)
# Breakpoint: https://github.com/python/cpython/pull/119891
if sys.version_info >= (3, 14):
def __annotate__(format):
annos = {}
@@ -1249,6 +1289,7 @@ else:
raise TypeError("TypedDict takes either a dict or keyword arguments,"
" but not both")
if kwargs:
# Breakpoint: https://github.com/python/cpython/pull/104891
if sys.version_info >= (3, 13):
raise TypeError("TypedDict takes no keyword arguments")
warnings.warn(
@@ -1458,6 +1499,7 @@ else: # <=3.13
hint = typing.get_type_hints(
obj, globalns=globalns, localns=localns, include_extras=True
)
# Breakpoint: https://github.com/python/cpython/pull/30304
if sys.version_info < (3, 11):
_clean_optional(obj, hint, globalns, localns)
if include_extras:
@@ -1530,7 +1572,8 @@ else: # <=3.13
# Python 3.9 has get_origin() and get_args() but those implementations don't support
# ParamSpecArgs and ParamSpecKwargs, so only Python 3.10's versions will do.
if sys.version_info[:2] >= (3, 10):
# Breakpoint: https://github.com/python/cpython/pull/25298
if sys.version_info >= (3, 10):
get_origin = typing.get_origin
get_args = typing.get_args
# 3.9
@@ -2096,6 +2139,7 @@ def _concatenate_getitem(self, parameters):
# 3.11+; Concatenate does not accept ellipsis in 3.10
# Breakpoint: https://github.com/python/cpython/pull/30969
if sys.version_info >= (3, 11):
Concatenate = typing.Concatenate
# <=3.10
@@ -2432,7 +2476,9 @@ For more information, see PEP 646 and PEP 692.
"""
if sys.version_info >= (3, 12): # PEP 692 changed the repr of Unpack[]
# PEP 692 changed the repr of Unpack[]
# Breakpoint: https://github.com/python/cpython/pull/104048
if sys.version_info >= (3, 12):
Unpack = typing.Unpack
def _is_unpack(obj):
@@ -2695,8 +2741,9 @@ else: # <=3.10
raise AssertionError(f"Expected code to be unreachable, but got: {value}")
# dataclass_transform exists in 3.11 but lacks the frozen_default parameter
# Breakpoint: https://github.com/python/cpython/pull/99958
if sys.version_info >= (3, 12): # 3.12+
# dataclass_transform exists in 3.11 but lacks the frozen_default parameter
dataclass_transform = typing.dataclass_transform
else: # <=3.11
def dataclass_transform(
@@ -2827,6 +2874,7 @@ else: # <=3.11
# Python 3.13.3+ contains a fix for the wrapped __new__
# Breakpoint: https://github.com/python/cpython/pull/132160
if sys.version_info >= (3, 13, 3):
deprecated = warnings.deprecated
else:
@@ -2956,6 +3004,7 @@ else:
return arg(*args, **kwargs)
if asyncio.coroutines.iscoroutinefunction(arg):
# Breakpoint: https://github.com/python/cpython/pull/99247
if sys.version_info >= (3, 12):
wrapper = inspect.markcoroutinefunction(wrapper)
else:
@@ -2969,6 +3018,7 @@ else:
f"a class or callable, not {arg!r}"
)
# Breakpoint: https://github.com/python/cpython/pull/23702
if sys.version_info < (3, 10):
def _is_param_expr(arg):
return arg is ... or isinstance(
@@ -3045,6 +3095,7 @@ if not hasattr(typing, "TypeVarTuple"):
expect_val = f"at least {elen}"
# Breakpoint: https://github.com/python/cpython/pull/27515
things = "arguments" if sys.version_info >= (3, 10) else "parameters"
raise TypeError(f"Too {'many' if alen > elen else 'few'} {things}"
f" for {cls}; actual {alen}, expected {expect_val}")
@@ -3238,6 +3289,7 @@ else:
# This was explicitly disallowed in 3.9-3.10, and only half-worked in <=3.8.
# On 3.12, we added __orig_bases__ to call-based NamedTuples
# On 3.13, we deprecated kwargs-based NamedTuples
# Breakpoint: https://github.com/python/cpython/pull/105609
if sys.version_info >= (3, 13):
NamedTuple = typing.NamedTuple
else:
@@ -3313,6 +3365,7 @@ else:
# using add_note() until py312.
# Making sure exceptions are raised in the same way
# as in "normal" classes seems most important here.
# Breakpoint: https://github.com/python/cpython/pull/95915
if sys.version_info >= (3, 12):
e.add_note(msg)
raise
@@ -3461,6 +3514,7 @@ else:
# NewType is a class on Python 3.10+, making it pickleable
# The error message for subclassing instances of NewType was improved on 3.11+
# Breakpoint: https://github.com/python/cpython/pull/30268
if sys.version_info >= (3, 11):
NewType = typing.NewType
else:
@@ -3513,6 +3567,7 @@ else:
def __reduce__(self):
return self.__qualname__
# Breakpoint: https://github.com/python/cpython/pull/21515
if sys.version_info >= (3, 10):
# PEP 604 methods
# It doesn't make sense to have these methods on Python <3.10
@@ -3524,10 +3579,12 @@ else:
return typing.Union[other, self]
# Breakpoint: https://github.com/python/cpython/pull/124795
if sys.version_info >= (3, 14):
TypeAliasType = typing.TypeAliasType
# <=3.13
else:
# Breakpoint: https://github.com/python/cpython/pull/103764
if sys.version_info >= (3, 12):
# 3.12-3.13
def _is_unionable(obj):
@@ -3723,6 +3780,7 @@ else:
def __call__(self):
raise TypeError("Type alias is not callable")
# Breakpoint: https://github.com/python/cpython/pull/21515
if sys.version_info >= (3, 10):
def __or__(self, right):
# For forward compatibility with 3.12, reject Unions
@@ -3835,15 +3893,19 @@ if _CapsuleType is not None:
__all__.append("CapsuleType")
if sys.version_info >= (3,14):
if sys.version_info >= (3, 14):
from annotationlib import Format, get_annotations
else:
# Available since Python 3.14.0a3
# PR: https://github.com/python/cpython/pull/124415
class Format(enum.IntEnum):
VALUE = 1
VALUE_WITH_FAKE_GLOBALS = 2
FORWARDREF = 3
STRING = 4
# Available since Python 3.14.0a1
# PR: https://github.com/python/cpython/pull/119891
def get_annotations(obj, *, globals=None, locals=None, eval_str=False,
format=Format.VALUE):
"""Compute the annotations dict for an object.
@@ -4031,23 +4093,13 @@ else:
# as a way of emulating annotation scopes when calling `eval()`
type_params = getattr(owner, "__type_params__", None)
# type parameters require some special handling,
# as they exist in their own scope
# but `eval()` does not have a dedicated parameter for that scope.
# For classes, names in type parameter scopes should override
# names in the global scope (which here are called `localns`!),
# but should in turn be overridden by names in the class scope
# (which here are called `globalns`!)
# Type parameters exist in their own scope, which is logically
# between the locals and the globals. We simulate this by adding
# them to the globals.
if type_params is not None:
globals = dict(globals)
locals = dict(locals)
for param in type_params:
param_name = param.__name__
if (
_FORWARD_REF_HAS_CLASS and not forward_ref.__forward_is_class__
) or param_name not in globals:
globals[param_name] = param
locals.pop(param_name, None)
globals[param.__name__] = param
arg = forward_ref.__forward_arg__
if arg.isidentifier() and not keyword.iskeyword(arg):
@@ -4181,6 +4233,7 @@ class Sentinel:
def __call__(self, *args, **kwargs):
raise TypeError(f"{type(self).__name__!r} object is not callable")
# Breakpoint: https://github.com/python/cpython/pull/21515
if sys.version_info >= (3, 10):
def __or__(self, other):
return typing.Union[self, other]
@@ -4192,6 +4245,26 @@ class Sentinel:
raise TypeError(f"Cannot pickle {type(self).__name__!r} object")
if sys.version_info >= (3, 14, 0, "beta"):
type_repr = annotationlib.type_repr
else:
def type_repr(value):
"""Convert a Python value to a format suitable for use with the STRING format.
This is intended as a helper for tools that support the STRING format but do
not have access to the code that originally produced the annotations. It uses
repr() for most objects.
"""
if isinstance(value, (type, _types.FunctionType, _types.BuiltinFunctionType)):
if value.__module__ == "builtins":
return value.__qualname__
return f"{value.__module__}.{value.__qualname__}"
if value is ...:
return "..."
return repr(value)
# Aliases for items that are in typing in all supported versions.
# We use hasattr() checks so this library will continue to import on
# future versions of Python that may remove these names.