Spec: More precision on type parameter order
Les mainteneurs répondent en général sous 1 jour
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 2/5
- Temps estimé
- 1-3 heures
- Accessibilité débutants
- 55/100
- Type d'issue
- Documentation
- Clarté
- Clairement spécifiée
- Activité
- À l'abandon
- Stack technique
- python
- Domaine
- documentation
Piste de recherche
Commencez par la section « Arbitrary generic types as base classes » de la spécification des generics, en particulier par sa règle actuelle concernant l’ordre des variables de type. Comparez cette formulation avec les cas proposés dans l’issue pour PEP 695, Generic, Protocol et les classes de base. Le travail est considéré comme terminé lorsque la spécification définit explicitement l’ordre pour chaque cas et correspond aux exemples fournis.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
The spec currently isn't very precise on the order in which type parameters appear in a class. (Given a class C that is generic over type parameters T1 and T2, does C[int, str] mean that T1 is bound to int or that T2 is bound to int?)
I think the rule should be:
- If PEP 695 syntax is used, the order is the order in which the type parameters appear in the type parameter list.
- If the class has
Generic[...]as a syntactic base, the order is the order of the type arguments toGeneric. - If the class has
Protocol[...]as a syntactic base, the order is the order of the type arguments toProtocol. This applies only if Protocol is subscripted, not if the class inherits from bareProtocol. - Otherwise, the order is the order in which the type parameters appear syntactically in the base class list.
As far as I know, this is how all type checkers currently behave, but we just found out it's not how the runtime behaves when Protocol is involved: https://github.com/python/cpython/issues/137191#issuecomment-3132748382.
In these examples, all classes are generic over two parameters T1 and T2, and in all cases the type parameter order is T1, T2:
from typing import Generic, Protocol, TypeVar
class C1[T1, T2]: ... # order is T1, T2
T1 = TypeVar("T1")
T2 = TypeVar("T2")
class C2(C1[T2, T1], Generic[T1, T2]): ... # order is T1, T2
class GenericProto[T1, T2](Protocol): ... # order is T1, T2
class Proto2(GenericProto[T2, T1], Protocol[T1, T2]): ... # order is T1, T2
class Proto3(GenericProto[T1, T2], Protocol): ... # order is T1, T2
class C3(C2[T1, T2]): ... # order is T1, T2
We should change the spec to make this rule explicit. The only current rule appears to be in https://typing.python.org/en/latest/spec/generics.html#arbitrary-generic-types-as-base-classes "Type variables are applied to the defined class in the order in which they first appear in any generic base classes".
- Langage dominant
- Python
- Étoiles
- 1.8k
- Forks
- 302
- Merge moyen
- 4 h 16 min
- PR mergées (30 j)
- 7
Préparer son environnement
Ce projet ne fournit ni conteneur de développement, ni Dockerfile, ni guide de contribution : l'installation est à votre charge. Commencez par son README, et consultez notre guide de la première contribution pour les étapes générales.
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.
Autres issues de python/typing
-
topic: typing spec
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
python/typing#2356 · 2 commentaires · 1 réaction ·
Les mainteneurs répondent en général sous 1 jour
-
topic: typing spec
Difficulté 2/5 1-3 heures Accessibilité débutants 75/100
Les mainteneurs répondent en général sous 1 jour
-
topic: documentation
Difficulté 2/5 1-3 heures Accessibilité débutants 76/100
python/typing#2227 · 2 commentaires ·
Les mainteneurs répondent en général sous 1 jour
-
topic: documentation
Difficulté 2/5 1-3 heures Accessibilité débutants 65/100
python/typing#2150 · 2 commentaires · 2 réactions ·
Les mainteneurs répondent en général sous 1 jour
-
topic: conformance tests topic: typing spec
Difficulté 3/5 1-2 jours Accessibilité débutants 72/100
python/typing#2351 · 2 commentaires ·
Les mainteneurs répondent en général sous 1 jour
Toutes les issues de python/typing
Issues similaires
-
comp/tools duplicate P2 sweeper:risk-compatibility tool/mcp type/bug
Difficulté 1/5 Moins d'une heure Accessibilité débutants 88/100
NousResearch/hermes-agent#132042 ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
deepset-ai/haystack#13092 ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 86/100
EverMind-AI/Raven#845 ·
Les mainteneurs répondent en général sous 1 jour
-
[Feature] 移除「切换到旧版知识库」入口Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
AstrBotDevs/AstrBot#10340 ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
BasedHardware/omi#20401 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour