Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make bool error ignorable #13420

Merged
merged 3 commits into from Aug 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 0 additions & 3 deletions mypy/semanal.py
Expand Up @@ -1957,9 +1957,6 @@ def verify_base_classes(self, defn: ClassDef) -> bool:
if self.is_base_class(info, baseinfo):
self.fail("Cycle in inheritance hierarchy", defn)
cycle = True
if baseinfo.fullname == "builtins.bool":
self.fail('"%s" is not a valid base class' % baseinfo.name, defn, blocker=True)
return False
dup = find_duplicate(info.direct_base_classes())
if dup:
self.fail(f'Duplicate base class "{dup.name}"', defn, blocker=True)
Expand Down
1 change: 0 additions & 1 deletion mypy/test/testsemanal.py
Expand Up @@ -132,7 +132,6 @@ def test_semanal_error(testcase: DataDrivenTestCase) -> None:
alt_lib_path=test_temp_dir,
)
a = res.errors
assert a, f"No errors reported in {testcase.file}, line {testcase.line}"
except CompileError as e:
# Verify that there was a compile error and that the error messages
# are equivalent.
Expand Down
6 changes: 6 additions & 0 deletions test-data/unit/pythoneval.test
Expand Up @@ -162,6 +162,12 @@ print(bool(''))
True
False

[case testCannotExtendBoolUnlessIgnored]
class A(bool): pass
class B(bool): pass # type: ignore
[out]
_program.py:1: error: Cannot inherit from final class "bool"

[case testCallBuiltinTypeObjectsWithoutArguments]
import typing
print(int())
Expand Down
4 changes: 3 additions & 1 deletion test-data/unit/semanal-errors.test
Expand Up @@ -775,7 +775,9 @@ class A(Generic[t]):
[out]

[case testTestExtendPrimitives]
class C(bool): pass # E: "bool" is not a valid base class
# Extending bool is not checked here as it should be typed
# as final meaning the type checker will detect it.
class C(bool): pass # ok
class A(int): pass # ok
class B(float): pass # ok
class D(str): pass # ok
Expand Down