|
7 | 7 | import mypy.applytype |
8 | 8 | import mypy.constraints |
9 | 9 | import mypy.typeops |
| 10 | +from mypy import errorcodes as codes |
10 | 11 | from mypy.checker_state import checker_state |
11 | 12 | from mypy.erasetype import erase_type |
12 | 13 | from mypy.expandtype import ( |
|
76 | 77 | from mypy.types_utils import flatten_types |
77 | 78 | from mypy.typestate import SubtypeKind, type_state |
78 | 79 | from mypy.typevars import fill_typevars, fill_typevars_with_any |
79 | | -from mypy import errorcodes as codes |
80 | 80 |
|
81 | 81 | # Flags for detected protocol members |
82 | 82 | IS_SETTABLE: Final = 1 |
|
89 | 89 | # Each tuple is (subclass_fullname, superclass_fullname). |
90 | 90 | # These are cases where a class is a subclass at runtime but treating it |
91 | 91 | # as a subtype can cause runtime errors. |
92 | | -UNSAFE_SUBTYPING_PAIRS: Final = [ |
93 | | - ("datetime.datetime", "datetime.date"), |
94 | | -] |
| 92 | +UNSAFE_SUBTYPING_PAIRS: Final = [("datetime.datetime", "datetime.date")] |
95 | 93 |
|
96 | 94 | TypeParameterChecker: _TypeAlias = Callable[[Type, Type, int, bool, "SubtypeContext"], bool] |
97 | 95 |
|
@@ -538,14 +536,14 @@ def visit_instance(self, left: Instance) -> bool: |
538 | 536 | return True |
539 | 537 | rname = right.type.fullname |
540 | 538 | lname = left.type.fullname |
541 | | - |
| 539 | + |
542 | 540 | # Check if this is an unsafe subtype relationship that should be blocked |
543 | 541 | if self.options and codes.UNSAFE_SUBTYPE in self.options.enabled_error_codes: |
544 | 542 | # Block unsafe subtyping relationships when the error code is enabled |
545 | 543 | for subclass, superclass in UNSAFE_SUBTYPING_PAIRS: |
546 | 544 | if lname == subclass and rname == superclass: |
547 | 545 | return False |
548 | | - |
| 546 | + |
549 | 547 | # Always try a nominal check if possible, |
550 | 548 | # there might be errors that a user wants to silence *once*. |
551 | 549 | # NamedTuples are a special case, because `NamedTuple` is not listed |
|
0 commit comments