-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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.datetime is not Liskov-substitutable for datetime.date, but it's typed as if it were #3805
Comments
(It seems like mypy is aware of the substitutability problem here, and they've all been type:ignore'd away? typeshed/stdlib/2and3/datetime.pyi Lines 298 to 301 in efebe6b
|
|
@srittau the presence of those four |
There is not much typeshed can do here. The implementation does not adhere to the LSP, the stubs follow that implementation. |
@srittau This is still a bug - where should it be filed? Mypy? Core python? |
Python core decided to violate the LSP with this class hierarchy and mypy decided to warn about LSP violations. Either of those places, although I am sure that the mypy developers see the warning as a feature. |
Consider this code:
Under mypy, it typechecks. Mypy's job is to prevent runtime
TypeError
s, right? At runtime:I think #2487 was wrong, and it actually makes more sense to type
datetime.date
anddatetime.datetime
separately.Perhaps this is a mypy bug though? Maybe just because something's a subclass, doesn't mean it should be a subtype? Or a bug in
datetime
because it shouldn't do this?I'm not sure. But practically speaking this makes any code working with
date
objects in mypy somewhat misleading and fraught.The text was updated successfully, but these errors were encountered: