Skip to content

Commit d988edd

Browse files
authored
Enable extra error codes for mypy (#3239)
1 parent 5ce853c commit d988edd

File tree

4 files changed

+7
-10
lines changed

4 files changed

+7
-10
lines changed

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ files = ["src/trio/", "docs/source/*.py"]
193193
ignore_missing_imports = true
194194

195195
# Be strict about use of Mypy
196+
enable_error_code = ["truthy-bool", "mutable-override"]
196197
local_partial_types = true
197198
warn_unused_ignores = true
198199
warn_unused_configs = true

src/trio/_repl.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,13 @@
1717

1818
@final
1919
class TrioInteractiveConsole(InteractiveConsole):
20-
# code.InteractiveInterpreter defines locals as Mapping[str, Any]
21-
# but when we pass this to FunctionType it expects a dict. So
22-
# we make the type more specific on our subclass
23-
locals: dict[str, object]
24-
2520
def __init__(self, repl_locals: dict[str, object] | None = None) -> None:
2621
super().__init__(locals=repl_locals)
2722
self.compile.compiler.flags |= ast.PyCF_ALLOW_TOP_LEVEL_AWAIT
2823

2924
def runcode(self, code: types.CodeType) -> None:
30-
func = types.FunctionType(code, self.locals)
25+
# https://github.com/python/typeshed/issues/13768
26+
func = types.FunctionType(code, self.locals) # type: ignore[arg-type]
3127
if inspect.iscoroutinefunction(func):
3228
result = trio.from_thread.run(outcome.acapture, func)
3329
else:

src/trio/_tests/check_type_completeness.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def has_docstring_at_runtime(name: str) -> bool:
4949
"""
5050
# This assert is solely for stopping isort from removing our imports of trio & trio.testing
5151
# It could also be done with isort:skip, but that'd also disable import sorting and the like.
52-
assert trio.testing
52+
assert trio.testing is not None
5353

5454
# figure out what part of the name is the module, so we can "import" it
5555
name_parts = name.split(".")
@@ -116,7 +116,7 @@ def check_type(
116116
expected_errors: list[object],
117117
) -> list[object]:
118118
# convince isort we use the trio import
119-
assert trio
119+
assert trio is not None
120120

121121
# run pyright, load output into json
122122
res = run_pyright(platform)

src/trio/_tests/type_tests/raisesgroup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ def check_multiple_exceptions_1() -> None:
169169
d = a
170170
d = b
171171
d = c
172-
assert d
172+
assert isinstance(d, RaisesGroup)
173173

174174

175175
def check_multiple_exceptions_2() -> None:
@@ -182,7 +182,7 @@ def check_multiple_exceptions_2() -> None:
182182
d = a
183183
d = b
184184
d = c
185-
assert d
185+
assert isinstance(d, RaisesGroup)
186186

187187

188188
def check_raisesgroup_overloads() -> None:

0 commit comments

Comments
 (0)