Skip to content

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

Open
@glyph

Description

@glyph

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 #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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions