Skip to content

datetime factory functions (utcnow, maybe others) are annotated as Self but return datetime #11849

Closed
@tamird

Description

@tamird
from datetime import datetime
from typing_extensions import assert_type

class MyDT(datetime):
    pass

my_dt = MyDT.utcnow()
assert_type(my_dt, MyDT)
assert type(my_dt) == MyDT

this type checks, but blows up at runtime. Tested with python 3.11.

EDIT: this issue originally claimed that now() was also incorrectly typed, but it seems that was not correct.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions