Skip to content

Conversation

@m-aciek
Copy link

@m-aciek m-aciek commented Dec 20, 2025

Fixes #9015.

This PR introduces unsafe-subtype error code, which makes mypy check fail for unsafe date and datetime classes inheritance, following @JukkaL's comment in the related issue.

Before:

from datetime import date, datetime

if datetime.now() < date.today():  # passing the type checking
    print("that's a surprise!")

After:

from datetime import date, datetime

if datetime.now() < date.today():  # E: Unsupported operand types for < ("datetime" and "date")
    print("that's a surprise!")

This is Copilot agent's work with my prompts' guidance. I reviewed the produced code. The change includes tests and documentation.

Alternatives considered

Possible addition

Copilot AI and others added 11 commits December 19, 2025 22:59
Co-authored-by: m-aciek <9288014+m-aciek@users.noreply.github.com>
Co-authored-by: m-aciek <9288014+m-aciek@users.noreply.github.com>
Co-authored-by: m-aciek <9288014+m-aciek@users.noreply.github.com>
Co-authored-by: m-aciek <9288014+m-aciek@users.noreply.github.com>
Co-authored-by: m-aciek <9288014+m-aciek@users.noreply.github.com>
Co-authored-by: m-aciek <9288014+m-aciek@users.noreply.github.com>
…em redundant

Co-authored-by: m-aciek <9288014+m-aciek@users.noreply.github.com>
Co-authored-by: m-aciek <9288014+m-aciek@users.noreply.github.com>
Co-authored-by: m-aciek <9288014+m-aciek@users.noreply.github.com>
@github-actions
Copy link
Contributor

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

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

Successfully merging this pull request may close these issues.

datetimes and dates are not substitutable but mypy thinks they are

1 participant