Skip to content

Commit

Permalink
Improve MyPy configuration
Browse files Browse the repository at this point in the history
Some improvments flagged by Repo-Review: https://learn.scientific-python.org/development/guides/repo-review/

1. Remove now-default show_error_codes.
2. Enable some optional error codes with extra checks.
  • Loading branch information
adamchainz committed Jun 19, 2024
1 parent b8f89ea commit 4d17c1c
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 8 deletions.
6 changes: 5 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,13 @@ source = [
show_missing = true

[tool.mypy]
enable_error_code = [
"ignore-without-code",
"redundant-expr",
"truthy-bool",
]
mypy_path = "src/"
namespace_packages = false
show_error_codes = true
strict = true
warn_unreachable = true

Expand Down
2 changes: 1 addition & 1 deletion src/django_upgrade/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ def decorator(func: ASTFunc[AST_T]) -> ASTFunc[AST_T]:

def _import_fixers() -> None:
# https://github.com/python/mypy/issues/1422
fixers_path: str = fixers.__path__ # type: ignore
fixers_path: str = fixers.__path__ # type: ignore [assignment]
mod_infos = pkgutil.walk_packages(fixers_path, f"{fixers.__name__}.")
for _, name, _ in mod_infos:
__import__(name, fromlist=["_trash"])
Expand Down
3 changes: 1 addition & 2 deletions src/django_upgrade/fixers/assert_form_error.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,7 @@ def visit_Expr(self, node: ast.Expr) -> Any:

def visit_Assign(self, node: ast.Assign) -> Any:
if (
isinstance(node, ast.Assign)
and len(node.targets) == 1
len(node.targets) == 1
and isinstance(node.targets[0], ast.Name)
and node.targets[0].id == self.name
and (
Expand Down
3 changes: 1 addition & 2 deletions src/django_upgrade/fixers/request_headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ def visit_Compare(
parents: list[ast.AST],
) -> Iterable[tuple[Offset, TokenFunc]]:
if (
isinstance(node, ast.Compare)
and len(node.ops) == 1
len(node.ops) == 1
and isinstance(node.ops[0], (ast.In, ast.NotIn))
and len(node.comparators) == 1
and is_request_or_self_request_meta(node.comparators[0])
Expand Down
4 changes: 2 additions & 2 deletions src/django_upgrade/fixers/utils_timezone.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ def visit_Attribute(
and isinstance(node.value, ast.Name)
and node.value.id == "timezone"
and "timezone" in state.from_imports["django.utils"]
and (details := get_import_details(state, parents[0]))
and details.datetime_module is not None
and (details := get_import_details(state, parents[0])).datetime_module
is not None
):
new_src = f"{details.datetime_module}.timezone"
yield ast_start_offset(node), partial(replace, src=new_src)
Expand Down

0 comments on commit 4d17c1c

Please sign in to comment.