@@ -255,6 +255,10 @@ inspect
255255 for determining the current state of asynchronous generators.
256256 (Contributed by Thomas Krennwallner in :issue: `35759 `.)
257257
258+ * The performance of :func: `inspect.getattr_static ` has been considerably
259+ improved. Most calls to the function should be around 2x faster than they
260+ were in Python 3.11. (Contributed by Alex Waygood in :gh: `103193 `.)
261+
258262pathlib
259263-------
260264
@@ -418,6 +422,8 @@ tempfile
418422The :class: `tempfile.NamedTemporaryFile ` function has a new optional parameter
419423*delete_on_close * (Contributed by Evgeny Zorin in :gh: `58451 `.)
420424
425+ .. _whatsnew-typing-py312 :
426+
421427typing
422428------
423429
@@ -437,6 +443,39 @@ typing
437443 vice versa. Most users are unlikely to be affected by this change.
438444 (Contributed by Alex Waygood in :gh: `102433 `.)
439445
446+ * The members of a runtime-checkable protocol are now considered "frozen" at
447+ runtime as soon as the class has been created. Monkey-patching attributes
448+ onto a runtime-checkable protocol will still work, but will have no impact on
449+ :func: `isinstance ` checks comparing objects to the protocol. For example::
450+
451+ >>> from typing import Protocol, runtime_checkable
452+ >>> @runtime_checkable
453+ ... class HasX(Protocol):
454+ ... x = 1
455+ ...
456+ >>> class Foo: ...
457+ ...
458+ >>> f = Foo()
459+ >>> isinstance(f, HasX)
460+ False
461+ >>> f.x = 1
462+ >>> isinstance(f, HasX)
463+ True
464+ >>> HasX.y = 2
465+ >>> isinstance(f, HasX) # unchanged, even though HasX now also has a "y" attribute
466+ True
467+
468+ This change was made in order to speed up ``isinstance() `` checks against
469+ runtime-checkable protocols.
470+
471+ * The performance profile of :func: `isinstance ` checks against
472+ :func: `runtime-checkable protocols <typing.runtime_checkable> ` has changed
473+ significantly. Most ``isinstance() `` checks against protocols with only a few
474+ members should be at least 2x faster than in 3.11, and some may be 20x
475+ faster or more. However, ``isinstance() `` checks against protocols with seven
476+ or more members may be slower than in Python 3.11. (Contributed by Alex
477+ Waygood in :gh: `74690 ` and :gh: `103193 `.)
478+
440479sys
441480---
442481
0 commit comments