annotationlib.type_repr() returns "None.list.append" for bound built-in methods
Personne n'a encore pris cette issue.
- Langage dominant
- Python
- Étoiles
- 77.2k
- Forks
- 35.9k
- Métriques de merge des PR
- Métriques de PR en attente
Description
Bug report
annotationlib.type_repr() (a public, documented helper, exported in
__all__) returns a string that names a nonexistent module None for bound
built-in methods:
>>> from annotationlib import type_repr
>>> type_repr([].append)
'None.list.append'
>>> type_repr(dict.fromkeys)
'None.dict.fromkeys'
>>> import random; type_repr(random.random)
'None.Random.random'
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.
Linked PRs
- gh-152693
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Piste de recherche
Commencez par le point d’entrée public annotationlib.type_repr() et examinez comment il formate les objets dont module vaut None. Vérifiez les exemples documentés ainsi que les chemins annotations_to_string() et get_annotations(..., format=Format.STRING) ; le travail est terminé lorsque les méthodes intégrées liées produisent leur qualname sans préfixe None. et restent résolubles.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- python
- Domaine
- api
- Type d'issue
- Bug
- Difficulté
- 2/5
- Temps estimé
- 1-3 heures
- Activité
- À l'abandon
- Clarté
- Clairement spécifiée
- Accessibilité débutants
- 35/100