Type stubs for single-file top-level modules
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 1.8k
- Fork
- 302
- Merge medio
- 23h
- PR unite (30g)
- 8
Descrizione
PEP 561 currently states the following:
Package maintainers who wish to support type checking of their code MUST add a marker file named
py.typedto their package supporting typing.
I consider this requirement to be problematic for Python libraries that are written in another programing language and distributed as compiled .so files. PEP 561 currently does not provide a way to mark .so files residing directly in site-packages/ to be typed, resulting in typed shared libraries needing to introduce an intermediary __init__.py file such as the following:
from ._native import *
__doc__ = _native.__doc__
if hasattr(_native, "__all__"):
__all__ = _native.__all__
While this works for static type checkers I think this is obviously suboptimal because it has several undesired side-effects. Let's take the following as an example:
site-packages
├── my_project
│ ├── __init__.py
│ ├── _native.cpython-36m-x86_64-linux-gnu.so
│ └── py.typed
The unintended side-effects are:
- You can import
my_project._native. _nativeshows up in the documentation generated by pydoc. E.g. under PACKAGE CONTENTS for the documentation ofmy_projectand invoking e.g.help(my_project.foobar)will tell you thatfoobarresides in the modulemy_project._native.my_project.__file__now is the__init__.pyfile instead of the.sofile, potentially misleading developers into thinking the package is implemented in Python
So I really think PEP 561 should be amended to provide some way of marking single-file packages as "typed" without having to resort to hacks such as defining an intermediary __init__.py since that introduces a bunch of undesired side-effects that have the potential to confuse API users.
What do you think about this?
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia leggendo PEP 561 e gli esempi della issue relativi ai moduli compilati in un singolo file, quindi confronta il comportamento descritto con il modo in cui pydoc riporta il contenuto dei package e file. Il lavoro sarà completato quando sarà proposto e documentato un modo accettato per contrassegnare come tipizzati i moduli .so installati direttamente, senza gli effetti collaterali intermedi di init.py.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- documentation
- Tipo di issue
- Funzionalità
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Stato di attività
- Tranquilla
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 38/100