Skip to content

Commit

Permalink
Update mypy configuration in StaticTypeChecker to skip imports (#1134)
Browse files Browse the repository at this point in the history
Uses the `--follow-imports=skip` command-line argument to mypy.
  • Loading branch information
herenali authored Jan 22, 2025
1 parent 9564ebe commit a02e735
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ and adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

### 🐛 Bug fixes

- Fixed issue in `static-type-checker` such that mypy no longer checks imported modules in the file being checked

### 🔧 Internal changes

- Configured CI tests to run on environments with and without `z3` dependency.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Imports a module with mypy errors, but mypy should not report any errors when checking this file
import e9952_incompatible_assignment
5 changes: 1 addition & 4 deletions python_ta/checkers/static_type_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,7 @@ class StaticTypeChecker(BaseRawFileChecker):
def process_module(self, node: nodes.NodeNG) -> None:
"""Run Mypy on the current file and handle type errors."""
filename = node.stream().name
mypy_options = [
"--ignore-missing-imports",
"--show-error-end",
]
mypy_options = ["--ignore-missing-imports", "--show-error-end", "--follow-imports=skip"]
result, _, _ = api.run([filename] + mypy_options)

for line in result.splitlines():
Expand Down
12 changes: 12 additions & 0 deletions tests/test_custom_checkers/test_static_type_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,3 +217,15 @@ def test_no_errors_in_static_type_checker_no_error(self) -> None:
mod = MANAGER.ast_from_file(file_path)
with self.assertNoMessages():
self.checker.process_module(mod)

def test_imports_no_error(self) -> None:
"""Imports a module with mypy errors, no errors raised."""
file_path = os.path.normpath(
os.path.join(
__file__,
"../../../examples/custom_checkers/static_type_checker_examples/imports_no_error.py",
)
)
mod = MANAGER.ast_from_file(file_path)
with self.assertNoMessages():
self.checker.process_module(mod)

0 comments on commit a02e735

Please sign in to comment.