Skip to content

Commit

Permalink
Update flush_errors to support different versions of mypy (#139)
Browse files Browse the repository at this point in the history
mypy's flush_errors function has a different arity for different
versions.
<mypy-1.8.0: 2
>=mypy-1.8.0: 3 (our flush_errors discards the first 'filename'
parameter)
  • Loading branch information
antecrescent committed Feb 29, 2024
1 parent c92accd commit 0c2163e
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions pytest_mypy_plugins/item.py
Expand Up @@ -82,10 +82,11 @@ def run_mypy_typechecking(cmd_options: List[str], stdout: TextIO, stderr: TextIO

error_messages = []

# discard filename parameter '_'. Mypy uses it to generate
# one junit-xml test entry per file with failures (--junit-format per_file)
# and we don't support mypy's --junit-xml option in the first place.
def flush_errors(_: str | None, new_messages: List[str], serious: bool) -> None:
# Different mypy versions have different arity of `flush_errors`: 2 and 3 params
def flush_errors(*args: Any) -> None:
new_messages: List[str]
serious: bool
*_, new_messages, serious = args
error_messages.extend(new_messages)
f = stderr if serious else stdout
try:
Expand Down

0 comments on commit 0c2163e

Please sign in to comment.