Skip to content

Commit b2cc802

Browse files
committed
Simplify code in subtypes.py
1 parent bdd8978 commit b2cc802

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

mypy/subtypes.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,6 @@
8585
IS_VAR: Final = 4
8686
IS_EXPLICIT_SETTER: Final = 5
8787

88-
# Disallow datetime.datetime where datetime.date is expected when safe-datetime is enabled.
89-
# While datetime is a subclass of date at runtime, comparing them raises TypeError,
90-
# making this inheritance relationship problematic in practice.
91-
DATETIME_DATE_FULLNAMES: Final = ("datetime.datetime", "datetime.date")
92-
9388
TypeParameterChecker: _TypeAlias = Callable[[Type, Type, int, bool, "SubtypeContext"], bool]
9489

9590

@@ -536,13 +531,14 @@ def visit_instance(self, left: Instance) -> bool:
536531
rname = right.type.fullname
537532
lname = left.type.fullname
538533

539-
# Check if this is the datetime/date relationship that should be blocked
540-
# when safe-datetime is enabled
534+
# Disallow datetime.datetime where datetime.date is expected when safe-datetime is
535+
# enabled. While datetime is a subclass of date at runtime, comparing them raises
536+
# TypeError, making this inheritance relationship problematic in practice.
541537
if (
542538
self.options
543539
and codes.SAFE_DATETIME in self.options.enabled_error_codes
544-
and lname == DATETIME_DATE_FULLNAMES[0]
545-
and rname == DATETIME_DATE_FULLNAMES[1]
540+
and lname == "datetime.datetime"
541+
and rname == "datetime.date"
546542
):
547543
return False
548544

0 commit comments

Comments
 (0)