Proposal: Programmatically create types
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Anfängerfreundlichkeit
- 20/100
Rechercherichtung
Beginne mit dem Proposal und den darin verlinkten Referenzen auf tjax leaky_integral.py, NumPy-Typannotationen und JAX-pytrees. Prüfe den vorgeschlagenen SyntheticType-Workflow, den Schritt zur Sammlung des Type-Checkers, das Format der generierten Stubs und die Dataclass-Transformation; ermittle anschließend, ob der Umfang zu einem abgestimmten Design werden kann. Erledigt wäre die Aufgabe erst mit einer festgelegten Richtung oder Spezifikation und nicht mit einer kleinen isolierten Änderung.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
This proposal is aimed at solving two related problem. First, when defining a multi-ary operator on Numpy arrays, e.g., leaky integral, then you ideally want to bake in Numpy type promotion rules. However, even Numpy doesn't use its own type promotion rules in its type annotations.
So, my suggestion is the following:
from typing import SyntheticType
def ResultType(*args: Any) -> SyntheticType[DType]:
return result_type(*args) # Something like this, but would have to deal with e.g., numpy.ndarray[typing.Any, numpy.dtype[numpy.floating[typing.Any]]]
# Then...
@overload
def __add__(self: T, other: U) -> NDArray[ResultType[T, U]]: ... # type: ignore[misc]
The type checker could be called with a special argument, like --create_synthetic_stubs. This would
- Run type checking and collect a list of unique argument tuples to synthetic type functions like
ResultType. - Start a Python interpreter and call the synthetic type functions using the the arguments (which are Python objects representing types, e.g.,
T=floatandU=numpy.ndarray[typing.Any, numpy.dtype[numpy.floating[typing.Any]]]). - It would then write the results to some
pyifile in some canonical table-like format, like:
`ResultType: SyntheticTypeMapping = {(float, float): float, ...}
The table could either be just stored in the cache. Users of the library would have to generate this file, which means type checkers run code in the library.
The other problem this solves is one that I would like to annotate dataclasses whose elements can be None or int besides whatever they've specified as. See here for a description as to why. It would be pretty easy to code a Python transformation from a dataclass type to a new dataclass type with the transformed field types.
I realize this is pretty extreme, but the payoff would be commensurate.
- Vorherrschende Sprache
- Python
- Sterne
- 1.8k
- Forks
- 302
- Ø Merge
- 23 Std.
- Gemergte PRs (30 T.)
- 8
Beitragsleitfaden
Für dieses Repository ist kein Beitragsleitfaden indexiert
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus python/typing
-
topic: typing spec
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
-
topic: typing spec
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 75/100
-
topic: documentation
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 76/100
-
topic: documentation
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 65/100
-
topic: conformance tests topic: typing spec
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 72/100
Ähnliche Issues
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 65/100
qgis/QGIS-Documentation#11275 ·
-
bug priority:normal ready-for-dev
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 88/100
OpenHands/extensions#626 · 1 Kommentar ·
-
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 90/100
CSCfi/sd-search-api#39 ·
-
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 90/100
-
please add to porn list Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
StevenBlack/hosts#3255 ·