Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
tamird opened this issue Apr 30, 2024 · 1 comment

Comments

@tamird
Copy link
Contributor

tamird commented Apr 30, 2024

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.

@tamird tamird changed the title datetime factory functions (now, utcnow, maybe others) are annotated as Self but return datetime datetime factory functions (utcnow, maybe others) are annotated as Self but return datetime Apr 30, 2024
@tamird
Copy link
Contributor Author

tamird commented Apr 30, 2024

Actually, this whole issue seems to be a bug in time-machine. See adamchainz/time-machine#445.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant