python / python/mypy

I want to be able to declare "naive datetime" or "aware datetime" as types

Offen
#10,067 9 Kommentare 45 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

feature
Vorherrschende Sprache
Python
Sterne
20.6k
Forks
3.3k
PR-Merge-Kennzahlen
PR-Kennzahlen ausstehend

Beschreibung

Feature

I would like to be able to have a way to say foo: datetime but know that foo either:

  • definitely doesn't have a tzinfo
  • has a tzinfo
  • has a tzinfo that specifically is / isn't from pytz

This could be resolved by an Intersection[] type as described in https://github.com/python/mypy/issues/2087 and a protocol that defines the tzinfo attribute appropriately.

Pitch

My database layer can only persist datetimes with a timezone; my timezone parsing code has portions where I want to make sure I haven't associated a timezone yet because to do so and then convert while replacing it would be an error. Really, naive datetimes and aware datetimes are subtly, but profoundly different types of objects, and their arithmetic represents different types of deltas.

Also, pytz requires different sorts of logic on arithmetic and comparison (i.e. possibly normalize is required) than other zoneinfo objects.

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Der Issue nennt keine Dateien, Tests oder Einstiegspunkte. Beginne damit, den vorgeschlagenen Intersection[]-Typ und den Protokollansatz im verlinkten mypy-Issue zu überprüfen; als abgeschlossen gilt die Arbeit, wenn es eine unterstützte Möglichkeit gibt, naive, aware und pytz-spezifische datetime-Typen zu unterscheiden.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
python
Bereich
devtools
Issue-Typ
Feature
Schwierigkeit
5/5
Geschätzter Aufwand
Über eine Woche
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
30/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.