python / python/typing

[spec] Clarification: Are symbols not listed in `__all__` ever considered public?

Ouverte
#1,829 1 commentaire 0 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

topic: documentation
Langage dominant
Python
Étoiles
1.8k
Forks
302
Merge moyen
23 h
PR mergées (30 j)
8

Description

According to https://typing.readthedocs.io/en/latest/guides/libraries.html#library-interface-public-and-private-symbols:

A module can expose an __all__ symbol at the module level that provides a list of names that are considered part of the interface. This overrides all other rules above, allowing imported symbols or symbols whose names begin with an underscore to be included in the interface.

Does this mean that if __all__ is present: ① A symbol is public if and only if it is listed in __all__ or ② If a symbol is listed in __all__, it is public, but things not listed in __all__ can still be considered public as well?

For example:

# module.py
__all__ = ["identity"]

from typing import TypeVar

T = TypeVar("T")

def identity(x: T) -> T:
    return x

Are TypeVar and T considered public members of module.py? If so, what is the suggested way to exclude them? T could be renamed to _T, but is one supposed to do from typing import TypeVar as _TypeVar, if one wants TypeVar to not be considered a public member of module?

Guide de contribution

Aucun guide de contribution indexé pour ce dépôt

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Piste de recherche

Commencez par le guide lié « Library Interface: Public and Private Symbols » et comparez sa formulation de all avec l’exemple module.py dans l’issue. Le travail est terminé lorsque le comportement des symboles publics est clarifié dans la documentation, notamment la manière dont les noms importés et les déclarations TypeVar doivent être exclus lorsque cela est approprié.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
python
Domaine
documentation
Type d'issue
Documentation
Difficulté
3/5
Temps estimé
1-2 jours
Activité
À l'abandon
Clarté
À clarifier
Accessibilité débutants
25/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.