You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
annotationlib.type_repr() returns "None.list.append" for bound built-in methods #152692
annotationlib.type_repr() (a public, documented helper, exported in __all__) returns a string that names a nonexistent module None for bound
built-in methods:
Bound built-in methods (and C-accelerator functions) are BuiltinFunctionType
with __module__ set to None, so f"{value.__module__}.{value.__qualname__}"
interpolates the literal None. Every other object in this family produces a
resolvable name -- len -> 'len', os.getpid -> 'posix.getpid';
this is the only one that emits a None. prefix. 'None.list.append' is
also an active hazard: a STRING-format consumer that resolves it gets AttributeError on the literal None.
annotations_to_string() and get_annotations(obj, format=Format.STRING)
propagate it when an annotation value is such a method.
Note for completeness: this is reached when a live method object is passed to type_repr (its documented purpose), not from natural annotation source
syntax -- def f(x: [].append) is stringified correctly via the AST path.
The defect is the public-API output of type_repr itself.
Fix
Return __qualname__ ('list.append') when __module__ is None,
exactly as already done for the "builtins" module. repr() is not a
usable fallback: it embeds a non-deterministic heap address and is not
re-parseable.
Activity
gh-152692: Fix annotationlib.type_repr() for bound built-in methods (#…
[3.15] gh-152692: Fix annotationlib.type_repr() for bound built-in me…
[3.14] gh-152692: Fix annotationlib.type_repr() for bound built-in me…