Skip to content

Commit 7bddcf6

Browse files
authored
Remove blocking special cased error for bool subclass (#13420)
This now falls back to being handled due to bool being typed as final
1 parent 76648ba commit 7bddcf6

File tree

4 files changed

+9
-5
lines changed

4 files changed

+9
-5
lines changed

mypy/semanal.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2012,9 +2012,6 @@ def verify_base_classes(self, defn: ClassDef) -> bool:
20122012
if self.is_base_class(info, baseinfo):
20132013
self.fail("Cycle in inheritance hierarchy", defn)
20142014
cycle = True
2015-
if baseinfo.fullname == "builtins.bool":
2016-
self.fail('"%s" is not a valid base class' % baseinfo.name, defn, blocker=True)
2017-
return False
20182015
dup = find_duplicate(info.direct_base_classes())
20192016
if dup:
20202017
self.fail(f'Duplicate base class "{dup.name}"', defn, blocker=True)

mypy/test/testsemanal.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,6 @@ def test_semanal_error(testcase: DataDrivenTestCase) -> None:
132132
alt_lib_path=test_temp_dir,
133133
)
134134
a = res.errors
135-
assert a, f"No errors reported in {testcase.file}, line {testcase.line}"
136135
except CompileError as e:
137136
# Verify that there was a compile error and that the error messages
138137
# are equivalent.

test-data/unit/pythoneval.test

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,12 @@ print(bool(''))
162162
True
163163
False
164164

165+
[case testCannotExtendBoolUnlessIgnored]
166+
class A(bool): pass
167+
class B(bool): pass # type: ignore
168+
[out]
169+
_program.py:1: error: Cannot inherit from final class "bool"
170+
165171
[case testCallBuiltinTypeObjectsWithoutArguments]
166172
import typing
167173
print(int())

test-data/unit/semanal-errors.test

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -775,7 +775,9 @@ class A(Generic[t]):
775775
[out]
776776

777777
[case testTestExtendPrimitives]
778-
class C(bool): pass # E: "bool" is not a valid base class
778+
# Extending bool is not checked here as it should be typed
779+
# as final meaning the type checker will detect it.
780+
class C(bool): pass # ok
779781
class A(int): pass # ok
780782
class B(float): pass # ok
781783
class D(str): pass # ok

0 commit comments

Comments
 (0)