Skip to content

Commit

Permalink
Update the TYPE_ERR_MSG to be compatible with mypy 1.7
Browse files Browse the repository at this point in the history
  • Loading branch information
maerteijn committed Nov 15, 2023
1 parent 363bd6b commit d32b452
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions test/test_plugin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import collections
import os
import re
import subprocess
import sys
from pathlib import Path
Expand All @@ -18,7 +19,10 @@
DOC_URI = f"file:/{Path(__file__)}"
DOC_TYPE_ERR = """{}.append(3)
"""
TYPE_ERR_MSG = '"Dict[<nothing>, <nothing>]" has no attribute "append"'

# Mypy 1.7 changed <nothing> into "Never", so make this a regex to be compatible
# with multiple versions of mypy
TYPE_ERR_MSG_REGEX = r"\"Dict\[(.+)]\" has no attribute \"append\""

TEST_LINE = 'test_plugin.py:279:8:279:16: error: "Request" has no attribute "id" [attr-defined]'
TEST_LINE_NOTE = (
Expand Down Expand Up @@ -66,7 +70,7 @@ def test_plugin(workspace, last_diagnostics_monkeypatch):

assert len(diags) == 1
diag = diags[0]
assert diag["message"] == TYPE_ERR_MSG
assert re.search(TYPE_ERR_MSG_REGEX, diag["message"])
assert diag["range"]["start"] == {"line": 0, "character": 0}
# Running mypy in 3.7 produces wrong error ends this can be removed when 3.7 reaches EOL
if sys.version_info < (3, 8):
Expand Down Expand Up @@ -365,7 +369,7 @@ def test_config_exclude(tmpdir, workspace):
plugin.pylsp_settings(workspace._config)
workspace.update_config({"pylsp": {"plugins": {"pylsp_mypy": {}}}})
diags = plugin.pylsp_lint(workspace._config, workspace, doc, is_saved=False)
assert diags[0]["message"] == TYPE_ERR_MSG
assert re.search(TYPE_ERR_MSG_REGEX, diags[0]["message"])

# Add the path of our document to the exclude patterns
exclude_path = doc.path.replace(os.sep, "/")
Expand Down

0 comments on commit d32b452

Please sign in to comment.