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

A variable annotated with 'date' is not compatible with a value of type 'datetime'. #2487

Closed
mvaled opened this issue Sep 26, 2018 · 3 comments

Comments

@mvaled
Copy link
Contributor

mvaled commented Sep 26, 2018

datetime is a subclass of date. In the stubs of 'datetime' there's the following TODO:

class datetime:
    # TODO: Is a subclass of date, but this would make some types incompatible.

Is there any record of the incompatibilities? Should we keep an issue open to address this TODO eventually?

@mvaled
Copy link
Contributor Author

mvaled commented Sep 26, 2018

The following program is rejected by mypy:

from datetime import date, datetime

class Date: ...
class Datetime(Date): ...

now: date = datetime.now()
rightnow: Date = Datetime()

assert isinstance(now, date)
$ mypy bug.py 
bug.py:6: error: Incompatible types in assignment (expression has type "datetime", variable has type "date")

@JelleZijlstra
Copy link
Member

There's probably some incompatible methods. Try modifying the stub to make datetime inherit from date and run tests/mypy_test.py.

We could fix this by just # type: ignoreing the lines with any incompatible methods.

mvaled added a commit to mvaled/typeshed that referenced this issue Sep 26, 2018
mvaled added a commit to mvaled/typeshed that referenced this issue Sep 26, 2018
@mvaled
Copy link
Contributor Author

mvaled commented Sep 26, 2018

@JelleZijlstra I created a PR in #2488

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

2 participants