Skip to content

fix(logger): residual fixes before 5.0.0 - #91

Merged
wolph merged 54 commits into
developfrom
fix/5.0-residuals-logger
Dec 4, 2026
Merged

wolph merged 54 commits into
developfrom
fix/5.0-residuals-logger

Conversation

@wolph

@wolph wolph commented Dec 4, 2026

Copy link
Copy Markdown
Owner

Summary

Residual fixes for the logger, terminal and import area before 5.0.0, after the last review rounds on the merged #85.

Logged / Logurud mixed classes
  copied descriptors: special methods bound as Python does, instance dict first
  init decision of the allocator retry read without descriptors or colliding keys
import_ / terminal
  the import system gets the stored text of a name, not a str subclass
  a given-up Windows pipe reader stops (peek before read)
error labels
  standard values read only through code of their own module

Evidence

  • Before: on develop, the 5.0 work differed from 4.2.2 in the cases below, each pinned by a regression test that fails on the commit before its fix.
    After: all four residual branches merged together on develop (res6/integration, tree d0a2276):
    • full tox matrix GREEN, 14 of 14 environments: 4843 tests on CPython 3.10 to 3.13 and PyPy 3.10/3.11, 4845 on 3.14 and 3.15, combined coverage 100%
    • lint, mypy, pyright, pyrefly, codespell and docs pass
    • progressbar2 4.7.1's own suite: 1818 passed, 35 skipped, the same as with python-utils 4.2.2
    • full suite on real CPython 3.10.6: passed
  • Each branch merges cleanly on develop on its own, and the four together merge without conflicts in any order (only CHANGELOG.md is shared, auto-merged).
  • Mixed-class descriptor fixtures (property setters and deleters, super(), unresolved subclasses, staticmethod and classmethod hooks, set-only descriptors): develop matches 4.2.2 on 8 of 16, this branch on 17 of 25, on CPython and PyPy. The 8 that differ are the documented limit below.

Merge Danger

Door: two-way

Blast Radius: logger

super().name on a class that mixes a logger into a class with a descriptor of its own returns an instance attribute of that name, where 4.2.2 bound the method of the next class. super() and a direct read call __get__ the same way, so the copy cannot tell them apart. This is in the CHANGELOG and the docstring.

Constructing a class whose base has a Python __new__(cls), so that every construction raises and retries, is slower than develop: own __init__ +33%, inherited +129%, a staticmethod __init__ +59%. Ordinary log calls are within 3%.

The Windows pipe peek has no native Windows run yet: the CI matrix has no Windows runner.

wolph added 30 commits December 3, 2026 17:04
…R14-EXCEPTION-ANNOTATION)

raise_exception accepts every BaseException subclass at run time since
S20, but its parameter kept the type[Exception] annotation of 4.2.2, so
a typed raise_exception(KeyboardInterrupt) failed mypy, basedpyright and
pyrefly. The parameter is now type[BaseException], and
test_raise_exception_accepts_base_exceptions calls it typed instead of
through an Any alias, so the type checkers hold the annotation to the
run-time check.
…85-R14-CONTROLLING-FD)

_get_terminal_size_linux opened the controlling terminal, asked its
window size and closed it inside contextlib.suppress(Exception). A
KeyboardInterrupt from the ioctl went past that handler and skipped
os.close, as in 4.2.2, so an application that catches the interrupt
kept the descriptor. The descriptor is now closed when the ioctl raises
anything, and an OSError of that close does not replace the interrupt.

test_controlling_terminal_is_closed_on_an_interrupt interrupts the ioctl
of the fake controlling terminal, with a close that works and one that
fails, and checks the interrupt and the close.
…-PROBE-ORDER)

With standard output redirected, get_terminal_size asked the optional
blessings library before the window size ioctl of standard input and
standard error, so a terminal of 132 by 50 on standard error gave the
(100, 40) that blessings reported instead of (131, 50), against S5 and
the docstring. 4.2.2 returned (79, 24) there. The ioctl probes and the
Windows console now come first, and blessings is asked when none of
them measures a terminal, with its size returned as it reports it.

test_native_terminal_comes_before_blessings gives standard error a
terminal and blessings a size, then takes the terminal away.
…T-WINDOWS-PATHEXT-CASE)

On real Windows with PATHEXT unset or '.EXE', _find_tput finds the
fixture's tput.exe as tput.EXE on a case-insensitive file system, and
FakeTerminal.popen and test_tput_is_started_by_its_absolute_path compare
that path with tput.exe as exact strings, so the fallback swallowed the
assertion and the tests saw (79, 24). The fake fixture now sets PATHEXT
to '.exe', the extension of its file, so the exact comparisons hold.
test_fixture_pathext_names_the_windows_tput checks that the Windows
search finds that file by that name. CI has no Windows runner, so this
is checked on macOS only.
…-TOKEN-OVERLAP)

On a shared pipe the reader looks for a token of 16 random bytes after
the output. A token with an end that is also its start, such as one
repeated byte, matched one byte early when the output ended like the
token begins, so that byte was not counted and 65 bytes of output
passed the limit of 64 (probe on develop 16b5173: total 64, no
overflow). 4.2.2 had no limit. _without_overlap now changes every other
copy of the first byte of the token in its lowest bit, so the token has
no such end and the find cannot start inside the output. A token whose
first byte is unique, as the fixed TOKEN of the tests, stays as it is.

test_pipe_reader_token_cannot_overlap_itself draws the bytes as b'A' * 16,
writes 64 bytes and the first byte of the token, then the token, and
checks that 65 bytes count and the child is killed.
…3-IMPORT-PARENT-FORMAT)

When an attribute was missing on a module on the way of a dotted
import_global name, _get_attribute put the submodule name together with
f'{module.__name__}.{attr}', which ran the __format__ of a str subclass
__name__. A detached module whose __name__ formats with a RuntimeError
made import_global raise that error past exceptions=ImportError, as in
4.2.2. _module_name now reads __name__ as before and copies a str
subclass to its stored text, and a __name__ that is no string gives the
ImportError of the missing module, which is where 4.2.2 ended up for an
int or None too.

test_import_global_missing_below_a_module_with_an_odd_name covers the
str subclass, an int and None.
…ER-RESTORE)

calls_of installs a profile function with sys.setprofile and puts back
what sys.getprofile returned. Under cProfile on CPython 3.10 and 3.11
that is the native Profile object, which sys.setprofile installs as a
Python callback, so the next profile event raised TypeError: 'Profile'
object is not callable. On develop 16b5173 under
python -m cProfile -m pytest on CPython 3.10.6,
test_logurud_drops_early_only_what_cannot_differ failed that way. It
passes after this change.

The assertions on the bind and opt calls now run in
drops_early_scenario through run_alone. The test makes the same calls
in its own process as well, without a profile function, so the early
drop and the full path stay covered by the measured process. The
assertions themselves are unchanged.
…IT-ERROR-LOOKUP)

When an allocator written in Python rejected the constructor arguments
at the call, _arguments_can_be_for_init looked the __init__ of the class
up through type.__getattribute__, which ran the __get__ of an __init__
descriptor before the allocator was judged. A __get__ that raised
SystemExit went past the except Exception and replaced the TypeError of
Child(1, 2), which 4.2.2 raised because its retry failed the binding as
well. Both logging mixins use the helper.

The allocator is now judged first, and _raw_init reads __init__ from
the namespaces along the method resolution order with _class_attribute.
It looks through a function, staticmethod, classmethod and, from
Python 3.14 on, functools.partial by the __get__ of their own types,
compared by identity, and returns None for any other descriptor, which
keeps the TypeError. An object without a __get__, such as the
Initialiser of test_new_falls_back_for_an_init_object, is called as it
is and judged as before.

test_new_reads_no_init_descriptor_for_its_decision runs for Logged and
Logurud: on develop 16b5173 the SystemExit of the descriptor escaped.
…CLASS-NAMESPACE-HOOK)

Since 86053a7, ClassLogger.__get__ reads the two cache entries of a
class whose metaclass is neither type nor abc.ABCMeta from vars(owner).
vars asks the __getattribute__ of the metaclass for __dict__, so a
metaclass that allowed that read while the caches were filled and
refused it later broke Child.logger and every log call, where b773747
read the cache attributes directly. The namespace is now read through
type.__dict__['__dict__'], in __get__ and in the scan of the classes
after the holder of the lookup, so the metaclass does not see the read.
The type and abc.ABCMeta path of the ordinary classes is unchanged.

test_logger_lookup_reads_no_namespace_through_a_metaclass warms a
Child of an abc.ABCMeta subclass up, then refuses __dict__ and reads
the logger on the class and the instance and logs, for Logged and
Logurud. On develop 16b5173 both raised the RuntimeError of the
metaclass.
…-INHERITED-DISPATCH)

_resolve assigns to a class that inherits both logging mixins the
methods of the earlier mixin from the classes after it, such as
Mid.info for Both(Logurud, Mid). A subclass Child(Both, Other), with
Other(Mid) overriding info as well, found that copy on Both first and
reached Mid.info, where 4.2.2 followed Child, Both, Logurud, Other, Mid
and reached Other.info (probe on 4.2.2 and develop 16b5173).

_copy_methods now records the copies of each class under
_python_utils_copies, and _definer does not count a copy that is still
in place as a definition of its class, so the resolution of Child looks
past the copy on Both and takes Other.info. A copy of an earlier
resolution of the same class that the new order no longer needs is
removed. A class with one logging mixin skips all of this, as before.

test_subclass_of_a_mixed_class_reaches_its_own_override failed on
develop with ('mid', 'ready'). test_new_bases_drop_the_copies_that_are_not_needed
covers the removal after a change of __bases__.
… (PR85-R11-IMPORT-DIR)

import_global took the names of a module that has a __dir__, or whose
namespace has a key that is not a plain str, from dir(module), and
dir() sorts what __dir__ returns. The __lt__ of a str subclass among
the names ran there, and its error propagated, as in 4.2.2. The round
13 ruling had narrowed the contract to that 4.2.2 behaviour. The
residual round asked for the fix where exact-str handling keeps every
supported case.

_directory now lists what dir() lists without the ordering of a name:
it calls the __dir__ of the type, ModuleType.__dir__ for a plain module
and otherwise the special method found through the descriptors of type,
bound through the __get__ of its own type (an object without one is
called as it is, as dir() calls it). A list of plain str is sorted only
where the order counts, which is the set of names that import_global
writes into the scope when there is no __all__: built from the sorted
names, that set iterates in the order of 4.2.2, which built it from
dir(). A list with str subclasses is copied to the stored text and the
copies are sorted, so no __lt__ of a subclass runs. A listing with any
other entry is sorted as dir() sorts it, so a namespace with an int key
keeps raising the TypeError of 4.2.2 (PR85-R12-IMPORT-DIR-FASTPATH).
The listing still comes before the lookup of __all__, as 4.2.2 called
dir() for the default of getattr.

Tests changed with this finding: test_import_global_dir_names_are_sorted_as_in_4_2_2
pinned the sort and is replaced by test_import_global_dir_names_are_not_ordered,
and the str subclass key case of
test_import_global_namespace_with_other_keys_goes_through_dir moves to
test_import_global_namespace_with_a_str_subclass_key, which imports the
names now. The int key case is unchanged. test_import_global_dir_object_without_get
covers a __dir__ object without __get__. All five new cases fail on
develop 16b5173 with the RuntimeError of the ordering.
test_import_global_writes_the_names_in_the_order_of_4_2_2 compares the
order of the writes with set(dir(module)) under two hash seeds that
showed a different order when the names were not sorted, and
test_import_global_dir_without_strings_imports_nothing covers a listing
of comparable entries that are no strings. A probe over four hash seeds
and 150 names writes the same order as 4.2.2, with and without a
__dir__.

Perf, CPython 3.13.14, best of 3 alternating runs of 7 against develop
16b5173: import_global os.path [sep] 2982.1 to 2856.0 ns,
import_global os.path (all) 6817.7 to 6499.3 ns. The default listing
no longer builds a set when the module declares __all__.
…1-IMPORT-PARENT)

With __package__ set in the scope of a relative import_global,
_package read __spec__.parent once and _SpecView handed that object to
__import__, which compares it with __package__. For a str subclass
parent that ran its __eq__ or __ne__, as in 4.2.2, and an error of it
stopped the import. The round 13 ruling had narrowed the contract to
that 4.2.2 behaviour. The residual round asked for the fix where
exact-str handling keeps every supported case.

_package now copies a str or str subclass parent to its stored text
before it goes into the view, so the import system compares two plain
strings. A parent whose text differs from __package__ still gets the
warning of the running interpreter, and a parent that is no string is
handed over as it was read, as before.

test_import_global_spec_parent_is_compared_as_in_4_2_2 pinned the
comparison of the subclass and is replaced by
test_import_global_spec_parent_is_compared_by_its_text: a same and a
different text with a raising __eq__ and __ne__, and None, each with
the warnings of a native import of the same scope. The same and
different cases fail on develop 16b5173 with the RuntimeError of the
comparison. Checked on CPython 3.10, 3.13 and 3.15 and PyPy 3.11.
…ANDON)

When os.dup fails the end token never reaches a shared tput pipe. Where
a selector can wait for a pipe, the reader thread waits in steps and
stops once the parent gives it up. On Windows no selector can wait for
a pipe, so every read waited for data or the end of the pipe, and a
descendant of tput that kept the write end open kept the thread and
the read end alive for as long as it ran.

read_peeking now takes the fallback path. _pipe_peek asks
kernel32.PeekNamedPipe, through the msvcrt handle of the descriptor
passed as a pointer, how many bytes the pipe holds. The thread reads
only when that is above zero. While the pipe is empty it pauses for 1
ms, doubling up to 10 ms (_PEEK_PAUSES), and starts over after every
read, so an ordinary tput call on Windows, which always uses the shared
pipe, gets its answer within milliseconds instead of waiting out a
_POLL_INTERVAL of 100 ms. It stops through give_up once the parent
abandons it, with the bytes held
back as a possible start of the token kept as output, as the selector
path does. A failed peek, which is what PeekNamedPipe gives once the
writers are gone, falls through to the read, which finds the end.
Where msvcrt or ctypes.windll is missing the old waiting reads stay,
and ctypes is not imported there.

No Windows runner is available here, so the tests simulate it:
select stands in for PeekNamedPipe on a real pipe with a selector that
refuses pipes (on Windows the real PeekNamedPipe runs in the same
tests), a reader that peeks must read output that arrives after a wait
well under a _POLL_INTERVAL made 30 s long, a stand-in msvcrt and ctypes.windll check the handle
(wider than a C int) and the DWORD that _pipe_peek passes, and a peek
that fails reads to the end. These fail on develop 16b5173, where the
reader has no peek. test_shared_reader_ends_by_the_deadline_without_its_signal
now expects the stop on every platform, which only Windows CI can
confirm for the real PeekNamedPipe.
…IPE-TOKEN-OVERLAP)

The lambda that 98c2f6f put in place of os.urandom has an untyped
parameter, which basedpyright reports as reportUnknownLambdaType. A
typed local function replaces it. The test is unchanged otherwise.
…name (PR85-R15-LABEL-CLASS-TRUST)

The labels of shown, which raise_exception and the other error messages
use, look the classes of datetime and decimal up in sys.modules. With
datetime.date rebound to a subclass of date whose year is a property,
a value of that subclass matched the looked-up class exactly, so the
label took it for the real date and read the property, which ran code
of the caller.

_genuine now checks a looked-up class before a value is read through
it: its qualified name must be the name it was looked up by, and no
class after it in its method resolution order may have that name, which
rules out a subclass in its place under its own name or under the name
of the real class. The names are read through the descriptors of type
and must be plain str, so no metaclass or str subclass code runs. A
class that is not genuine is not used, and the value gets the label by
type, such as <Day object>. The check runs only when a value matched
the class, and a class that passed is remembered by id with its order,
so a label of any other value pays nothing.

test_rebound_datetime_class_is_not_trusted (a subclass under its own
name and under the name date) records the calls of the property and
fails on develop 16b5173, where the property ran.
test_datetime_name_that_holds_no_trusted_class covers a name that holds
no class and a class whose qualified name is a str subclass.

containers.py has its own copy of _loaded_class with the same lookups,
which is outside this area and is left as it is.

Perf, CPython 3.13.14, best of 3 alternating runs of 7 against develop
16b5173: shown(datetime) 5323.1 to 5423.0 ns, shown(Decimal) 963.8 to
1084.2 ns, shown(object()) 1684.3 to 1704.3 ns. Labels are written only
for error messages.
…FINAL-01)

The labels of shown looked names up in the namespace of datetime and
decimal (_loaded_class) and in the namespace of every class in the order
of a value (__module__, _numerator and _denominator in _fraction_slots).
A lookup compares the name with each stored key of the same hash, and a
key of a str subclass ran its own __eq__ there. This is the twin in
_shown.py of CVF-FINAL-01, fixed for converters in 6440e6a, and follows
its rule.

_fraction_slots compares the name of each class with str.__eq__ first
and reads only a class named Fraction. It asks only a namespace whose
keys are all exact str. setattr on a class stores an exact str, so the
verdict is kept per class, by id with the class as the value.
_loaded_class asks a module namespace only when all its keys are exact
str, read in C. A module can get another key at any time, so that check
is not cached. Instead it runs only for a value with a class named like
the one looked up (_named over the stored names of the order), so a
label of any other value reads no module namespace.

_python_utils_tests/colliding.py is copied byte for byte from 6440e6a.
test_fraction_class_with_a_colliding_key (three targets),
test_fraction_classes_are_checked_once,
test_module_namespace_with_a_colliding_key and
test_value_of_no_standard_class_reads_no_module fail on develop 16b5173.
The module test fails there with the recorded __eq__ of the colliding
key.

Perf, CPython 3.13.14, best of 3 alternating runs of 7 against develop
16b5173. Labels are written only for error messages:
shown(object()) 1736.8 to 1252.6 ns, shown(1.5) 462.5 to 469.4 ns,
shown('spam') 568.7 to 578.0 ns, shown(Fraction) 1348.6 to 1640.4 ns,
shown(datetime) 5338.8 to 6127.8 ns, shown(Decimal) 975.8 to 1872.0 ns.
The last three pay for the key checks.
A descriptor class can take the __get__ of staticmethod or classmethod.
_raw_init matched that binder by identity and read __func__ of an object
that is no staticmethod, whose TypeError replaced the error of the
allocator. An explicit __get__ = None counted as no __get__, so the
descriptor itself was judged as the initialiser.

The type of the object now has to be the one that owns the binder, and an
absent __get__ is told apart from one that holds None, which counts as an
unknown descriptor (PR85-R20-INIT-BINDER-RECEIVER).
A Logged class with an allocator that takes only the class and an
__init__ made with functools.partialmethod was retried without the
arguments in 4.2.2, because the lookup of __init__ gave a Python
function. Reading the raw __init__ treated the partialmethod as an
unknown descriptor, so the TypeError of the allocator came out.

An object of exactly functools.partialmethod is now judged by the
function that it keeps in its instance namespace, read without the
__eq__ of a key that is not an exact str (PR85-R20-INIT-PARTIALMETHOD).
Child(Both, Other) with an info of its own that calls super().info
found the copy of Mid.info that the resolution of Both had assigned to
Both, where 4.2.2 reached Other.info. A subclass whose resolution a base
skipped found the same copy on a plain lookup.

The log methods that _resolve copies are now descriptors that give the
copied method for the class that holds them, and for any other class
look the method up in its own method resolution order after the holder,
past a logging mixin that it does not log through, resolving that class
first. The helpers that a log call looks up stay plain copies
(PR85-R20-LOGGER-COPIED-SUPER).
A class rebound as datetime.date that is unrelated to the real class,
named date with a year property of its own, passed the check by names,
and the label read the property while raise_exception prepared its
TypeError. A SystemExit from it replaced that error. The same held for
Decimal, timedelta and the __getinitargs__ of timezone.

A field or method is now used only when it is a native descriptor of the
class that holds it, or a function or property getter whose globals are
the namespace of the standard module, found in namespaces of exact str
keys. Otherwise the value is shown by its type. A Decimal whose __str__
is no native one is written from its stored fields
(PR85-R20-LABEL-CLASS-IDENTITY).
dir() calls the __get__ that the type of a __dir__ descriptor holds as
it is, without binding it: a staticmethod is called with the
descriptor, the object and its type, and a classmethod raises
TypeError, on every interpreter of the matrix. The listing that
replaced dir() does the same, for given names and for the discovery of
all names, as 4.2.2 did (PR85-R20-IMPORT-DIRECTORY-BINDING).
The release hands the read end over and tells the reader to stop. Inside
an assert it would not run where assertions are stripped, and the test
would join a reader that was never told to stop. It runs once now, also
when an earlier step fails, and the thread is joined before the writer
is closed (PR85-R20-PIPE-ASSERT-RELEASE).
The regression for the token that overlapped itself failed on the code
before the fix at its assertion about the first byte of the token,
before the reader ran. The reader runs first now, so the test fails on
6a6b3bc because 64 bytes are counted where 65 arrived, and the shape of
the token is checked after the behaviour (PR85-R20-PIPE-OVERLAP-
REGRESSION).
The changelog said that the names are imported in the order of dir(),
and two test docstrings said that a listing of strings is not sorted.
The stored text of the names is sorted, the sorted names go into a set,
and the scope receives them in the order of that set, as in 4.2.2
(PR85-R20-IMPORT-ORDER-DOCS).
The lookup of a functools.partialmethod on its class gives the Python
_method wrapper of functools for a stored builtin, a callable without a
__get__ and a functools.partial, and a partial of the function for a
staticmethod or classmethod. 4.2.2 judged that result, so it retried a
cls-only allocator for all of them, where 92556c7 judged a builtin by
itself. The stored callable is classified that way now, and any other
descriptor keeps the error of the allocator without its __get__ running
(PR85-R20-INIT-PARTIALMETHOD).
A date made at run time could pass the anchor of 83240db with a getter
built by types.FunctionType on the globals of datetime, which then ran,
or with slots of its own named year, month and day, which gave it the
label of a real date. Where the module written in C is loaded, its
classes are static types on 3.10 to 3.15, so a class in their place that
is a heap type is shown by its type. The colliding-key regression uses
Decimal now, which still reaches the namespace scan
(PR85-R20-LABEL-CLASS-IDENTITY).
The cleanup of the peeking reader test releases and joins the reader in
a try block whose finally closes the writer, and joins only a thread
that was started (PR85-R20-PIPE-ASSERT-RELEASE).
A property with a setter that a mixed class got from an earlier mixin
was wrapped in a copy that only binds, so an assignment went to the
instance dictionary and a deletion removed it from there, where 4.2.2
ran the setter and the deleter (PR85-R21-LOGGER-DATA-DESCRIPTOR).
wolph added 23 commits December 3, 2026 19:12
The lookups of the __init__, of the __get__ of the callable that a
partialmethod __init__ stores and of the __call__ of an __init__ ran the
__eq__ of a namespace key of a str subclass with the same hash, so code
of the caller could replace the error of the allocator. Such a namespace
is not read now, and the error stays
(PR85-R21-PARTIALMETHOD-CALLABLE-LOOKUP).
The __call__ of an allocator that is no function was looked up in a
namespace with a colliding key as well, which no test reached
(PR85-R21-PARTIALMETHOD-CALLABLE-LOOKUP).
The data descriptor that a mixed class got from an earlier mixin was
taken as it is, so super() of a subclass and an instance of a subclass
that was not resolved yet reached the one of the order of Both, where
4.2.2 reached the one of their own order. A copy that is a data
descriptor itself forwards a read, an assignment and a deletion to the
descriptor that the class of the instance finds
(PR85-R21-LOGGER-DATA-DESCRIPTOR).
The cache of the classes that _fraction_slots recognised held each one
strongly, so every load of fractions that a label saw stayed alive with
its module globals. It holds weak references now, keyed by id and
compared by identity, and is emptied at 16 classes, as in the
converters (PR85-R21-FRACTION-CACHE-LIFETIME).
The check for keys that are no exact str read every key of every
namespace on the way, the one of the function type included, on each
construction that retries the allocator. A builtin type holds the names
that Python gave it, so only a class made at run time is checked
(PR85-R21-PARTIALMETHOD-CALLABLE-LOOKUP).
A function of exactly the function type binds with its own __get__ and
runs itself, so its binder is not looked up and the namespace of the
function type is not read. A construction that retries the allocator
is about 280 ns faster for it (PR85-R21-PERFORMANCE-GATE).
A class put in place of decimal.Decimal that defines only a __repr__
found the __str__ of object through its order, whose owner is object,
so the check of the owner held and the label called it, which ran the
__repr__ of the caller. A native slot of object is refused now
(PR85-R20-LABEL-CLASS-IDENTITY).
The copy that forwarded a data descriptor called its __set__ and
__delete__ unbound, which failed for a staticmethod setter and a
classmethod deleter, took precedence over the instance dictionary for a
descriptor without a __get__, and read the class of the descriptor when
the mixed class was made. Only a function, classmethod or staticmethod
is wrapped now. Any other attribute is copied as it is, as at e86d1a2,
so Python binds it and weighs it as in 4.2.2
(PR85-R22-LOGGER-DESCRIPTOR-BINDING,
PR85-R22-LOGGER-DESCRIPTOR-READ-PRECEDENCE,
PR85-R22-LOGGER-DESCRIPTOR-CLASS-LOOKUP,
PR85-R22-LOGGER-DESCRIPTOR-ASSERT-SIDE-EFFECTS).
The function type no longer goes through the known binders, so these
wrappers, and a functools.partial from 3.14 on, are what reach them
(PR85-R20-INIT-BINDER-RECEIVER).
A construction that retries the allocator read the namespaces along the
order of the class and judged its __init__ each time. The decision for
an __init__ that is a function, staticmethod or classmethod is kept now,
on the class with its order and entry, and the class by a weak reference
keyed by id, so the retry is as fast as at 16b5173
(PR85-R22-LOGGER-RETRY-PERFORMANCE).
A partialmethod of a staticmethod or classmethod of a native callable
keeps the error of the allocator, where 4.2.2 retried and called it
(PR85-R22-PARTIALMETHOD-STATICMETHOD-DOCS).
49c29bc stored the kept init decision on the class itself, so a class
gained a name in vars(), which changes copying and pickling and fails on
a class that refuses new attributes. The decision now lives only in the
module-level cache, keyed by id with a weak reference to the class and a
weak reference to the __init__ function, and is used while that function
is still the first __init__ along the order. The function is held weakly
because one that calls super() holds its class in a cell. Only a plain
function is kept, since a staticmethod or classmethod cannot be held
weakly (PR85-R22-LOGGER-RETRY-PERFORMANCE).
The copy of a data descriptor called __set__ and __delete__ unbound,
treated one set to None as missing, and came before the instance
dictionary even when the descriptor it forwards to has no __get__ or is
no data descriptor. The special methods are now bound through their own
type, an absent one is told apart from None, a read checks the instance
dictionary first where Python does, and __get__ is called the way the
interpreter calls it: raw on CPython, bound for an instance on PyPy
(PR85-R22-LOGGER-DESCRIPTOR-BINDING,
PR85-R22-LOGGER-DESCRIPTOR-READ-PRECEDENCE,
PR85-R22-LOGGER-DESCRIPTOR-ASSERT-SIDE-EFFECTS,
PR85-R23-LOGGER-DESCRIPTOR-MRO).
An instance can have a dict subclass as its __dict__, and the read of a
data descriptor without __get__ called the get of that subclass, which
Python does not (PR85-R24-INSTANCE-DICT-GET-HOOK).
They assign and delete, which an assert stripped by -O would skip
(PR85-R24-DESCRIPTOR-ASSERT-OPERATIONS).
A super() read and a direct read call the __get__ of the copy with the
same instance and class, and the copy gave the instance dictionary to
both. A resolved subclass now gets an entry of its own in front of every
copy of a base that its direct lookup would reach first, so the copy is
reached past such an entry only by super(), which never reads the
instance dictionary. The first super() read of a class that is not
resolved yet cannot be told apart and is taken as a direct read
(PR85-R24-SUPER-INSTANCE-SHADOW).
…imit

The R24 cases stay: a direct read and a super() read on one instance
that holds the name, in both orders, resolved and not, past a subclass
with its own entry, after the class is resolved again and past a
colliding key. Where the copy gives the instance value for super(), the
test pins it with a note of what 4.2.2 gave
(PR85-R24-SUPER-INSTANCE-SHADOW).
On a class that mixes a logger into a class with a descriptor of its
own, super().name returns an instance attribute of that name where 4.2.2
bound the method of the next class (PR85-R24-SUPER-INSTANCE-SHADOW).
The test waited for all four bytes of b'132\n' in reader.data, but a
random token that starts with the newline, once in 256 runs, holds the
newline back as a possible start of the token until the token or the
end of the pipe arrives. The test writes neither, so the wait ran into
its 30 second deadline and saw b'132'. The test now uses the known
token, whose first byte is not in the output. The product is not
affected: _capture returns the data only after the token or the end of
the pipe was read, and both flush the held bytes.
Comment thread _python_utils_tests/test_logger.py Fixed
refused: list[bool] = [False]

class Guarded(abc.ABCMeta):
def __getattribute__(cls, name: str) -> typing.Any:
refused: list[bool] = [False]

class Guarded(abc.ABCMeta):
def __getattribute__(cls, name: str) -> typing.Any:
…nt-assignment)

test_super_read_after_the_class_is_resolved_again assigned
child_class.__bases__ to itself, which CodeQL reports as a redundant
assignment. The bases now go through a tuple of their own first, which
still gives the class a new order and resolves it again.
@wolph
wolph merged commit f42b691 into develop Dec 4, 2026
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants