From 3c69535b458ae95f0b229d4c8b507a7dbecbe1ca Mon Sep 17 00:00:00 2001 From: jorenham Date: Wed, 27 Aug 2025 01:14:01 +0200 Subject: [PATCH 1/2] stubtest: temporary `--ignore-disjoint-bases` flag --- mypy/stubtest.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/mypy/stubtest.py b/mypy/stubtest.py index 31b3fd20b002..d1237d466de6 100644 --- a/mypy/stubtest.py +++ b/mypy/stubtest.py @@ -630,7 +630,11 @@ def verify_typeinfo( return yield from _verify_final(stub, runtime, object_path) - yield from _verify_disjoint_base(stub, runtime, object_path) + + # TODO: Once PEP 800 gets accepted, remove the conditional (always verify) + if "--ignore-disjoint-bases" not in sys.argv[1:]: + yield from _verify_disjoint_base(stub, runtime, object_path) + is_runtime_typeddict = stub.typeddict_type is not None and is_typeddict(runtime) yield from _verify_metaclass( stub, runtime, object_path, is_runtime_typeddict=is_runtime_typeddict @@ -2364,6 +2368,12 @@ def parse_options(args: list[str]) -> _Arguments: action="store_true", help="Ignore errors for whether an argument should or shouldn't be positional-only", ) + # TODO: Remove once PEP 800 is accepted + parser.add_argument( + "--ignore-disjoint-bases", + action="store_true", + help="Disable checks for PEP 800 @disjoint_base classes", + ) parser.add_argument( "--allowlist", "--whitelist", From 1abe75e9f69669b2aaa2d008cc7bb971c3df39fb Mon Sep 17 00:00:00 2001 From: jorenham Date: Wed, 27 Aug 2025 16:41:10 +0200 Subject: [PATCH 2/2] stubtest: make the `--ignore-disjoint-bases` hack less inconsistent --- mypy/stubtest.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/mypy/stubtest.py b/mypy/stubtest.py index d1237d466de6..d4f96a3d9389 100644 --- a/mypy/stubtest.py +++ b/mypy/stubtest.py @@ -140,6 +140,11 @@ def is_positional_only_related(self) -> bool: # TODO: This is hacky, use error codes or something more resilient return "should be positional" in self.message + def is_disjoint_base_related(self) -> bool: + """Whether or not the error is related to @disjoint_base.""" + # TODO: This is hacky, use error codes or something more resilient + return "@disjoint_base" in self.message + def get_description(self, concise: bool = False) -> str: """Returns a description of the error. @@ -630,11 +635,7 @@ def verify_typeinfo( return yield from _verify_final(stub, runtime, object_path) - - # TODO: Once PEP 800 gets accepted, remove the conditional (always verify) - if "--ignore-disjoint-bases" not in sys.argv[1:]: - yield from _verify_disjoint_base(stub, runtime, object_path) - + yield from _verify_disjoint_base(stub, runtime, object_path) is_runtime_typeddict = stub.typeddict_type is not None and is_typeddict(runtime) yield from _verify_metaclass( stub, runtime, object_path, is_runtime_typeddict=is_runtime_typeddict @@ -2185,6 +2186,7 @@ class _Arguments: concise: bool ignore_missing_stub: bool ignore_positional_only: bool + ignore_disjoint_bases: bool allowlist: list[str] generate_allowlist: bool ignore_unused_allowlist: bool @@ -2278,6 +2280,8 @@ def warning_callback(msg: str) -> None: continue if args.ignore_positional_only and error.is_positional_only_related(): continue + if args.ignore_disjoint_bases and error.is_disjoint_base_related(): + continue if error.object_desc in allowlist: allowlist[error.object_desc] = True continue