Skip to content

Commit

Permalink
Fix fatal error on running mypy when duplicate module names (#399)
Browse files Browse the repository at this point in the history
* Fix fatal error on running mypy when duplicate module names

* Update contributors list
  • Loading branch information
sbrunner authored Aug 27, 2021
1 parent 38d530b commit 4da6a19
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
1 change: 1 addition & 0 deletions CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Contributors
* Phil Jones ([@pgjones](https://github.com/pgjones))
* SergeyKosarchuk ([@SergeyKosarchuk](https://github.com/SergeyKosarchuk))
* Shachar Ohana ([@shacharoo](https://github.com/shacharoo))
* Stéphane Brunner ([@sbrunner](https://github.com/sbrunner))
* Steven Myint ([@myint](https://github.com/myint))
* Sushobhit ([@sushobhit27](https://github.com/sushobhit27))
* Yaroslav Kurlaev ([@ykurlaev](https://github.com/ykurlaev))
13 changes: 10 additions & 3 deletions prospector/tools/mypy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,22 @@
def format_message(message):
try:
(path, line, char, err_type, err_msg) = message.split(":", 4)
line = int(line)
character = int(char)
except ValueError:
(path, line, err_type, err_msg) = message.split(":", 3)
character = None
try:
(path, line, err_type, err_msg) = message.split(":", 3)
line = int(line)
character = None
except ValueError:
(path, err_type, err_msg) = message.split(":", 2)
line = 0
character = None
location = Location(
path=path,
module=None,
function=None,
line=int(line),
line=line,
character=character,
)
return Message(
Expand Down
26 changes: 26 additions & 0 deletions tests/tools/mypy/test_mypy_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,29 @@ def test_format_message_without_character(self):
location = Location(path="file.py", module=None, function=None, line=17, character=None)
expected = Message(source="mypy", code="error", location=location, message="Important error")
self.assertEqual(format_message("file.py:17: error: Important error"), expected)

def test_format_dupplicated_module_win(self):
location = Location(path="file.py", module=None, function=None, line=0, character=None)
expected = Message(
source="mypy",
code="error",
location=location,
message="Duplicate module named 'file' (also at 'C:\\Repositories\\file.py')",
)
self.assertEqual(
format_message("file.py: error: Duplicate module named 'file' (also at 'C:\\Repositories\\file.py')"),
expected,
)

def test_format_dupplicated_module_linux(self):
location = Location(path="file.py", module=None, function=None, line=0, character=None)
expected = Message(
source="mypy",
code="error",
location=location,
message="Duplicate module named 'file' (also at '/Repositories/file.py')",
)
self.assertEqual(
format_message("file.py: error: Duplicate module named 'file' (also at '/Repositories/file.py')"),
expected,
)

0 comments on commit 4da6a19

Please sign in to comment.