-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Resolve code review discussions
- Loading branch information
1 parent
0b584be
commit 17d7d72
Showing
7 changed files
with
110 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,58 @@ | ||
# name: test_typing | ||
<class 'list'> [ | ||
<class 'dict'> { | ||
'message': ' | ||
list([ | ||
dict({ | ||
'message': ''' | ||
No overloads for "function_decorator" match the provided arguments | ||
Argument types: (Literal[True]) | ||
', | ||
'range': <class 'dict'> { | ||
'end': <class 'dict'> { | ||
''', | ||
'range': dict({ | ||
'end': dict({ | ||
'character': 47, | ||
'line': 10, | ||
}, | ||
'start': <class 'dict'> { | ||
'line': 15, | ||
}), | ||
'start': dict({ | ||
'character': 9, | ||
'line': 10, | ||
}, | ||
}, | ||
'line': 15, | ||
}), | ||
}), | ||
'rule': 'reportGeneralTypeIssues', | ||
'severity': 'error', | ||
}, | ||
<class 'dict'> { | ||
'message': ' | ||
}), | ||
dict({ | ||
'message': ''' | ||
Argument of type "Literal[2]" cannot be assigned to parameter "scope" of type "str" in function "__call__" | ||
"Literal[2]" is incompatible with "str" | ||
', | ||
'range': <class 'dict'> { | ||
'end': <class 'dict'> { | ||
'character': 26, | ||
'line': 30, | ||
}, | ||
'start': <class 'dict'> { | ||
'character': 25, | ||
'line': 30, | ||
}, | ||
}, | ||
''', | ||
'range': dict({ | ||
'end': dict({ | ||
'character': 22, | ||
'line': 36, | ||
}), | ||
'start': dict({ | ||
'character': 21, | ||
'line': 36, | ||
}), | ||
}), | ||
'rule': 'reportGeneralTypeIssues', | ||
'severity': 'error', | ||
}, | ||
] | ||
--- | ||
}), | ||
dict({ | ||
'message': ''' | ||
Argument of type "Literal[2]" cannot be assigned to parameter "scope" of type "str" in function "__call__" | ||
"Literal[2]" is incompatible with "str" | ||
''', | ||
'range': dict({ | ||
'end': dict({ | ||
'character': 34, | ||
'line': 52, | ||
}), | ||
'start': dict({ | ||
'character': 33, | ||
'line': 52, | ||
}), | ||
}), | ||
'rule': 'reportGeneralTypeIssues', | ||
'severity': 'error', | ||
}), | ||
]) | ||
# --- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,35 @@ | ||
import json | ||
import shutil | ||
import subprocess | ||
|
||
__all__ = ["run_pyright", "pyright_installed"] | ||
|
||
try: | ||
pyright_bin = shutil.which("pyright") | ||
pyright_installed = pyright_bin is not None | ||
except AttributeError: | ||
# shutil.which works from python 3.3 onward | ||
pyright_bin = None | ||
pyright_installed = False | ||
|
||
|
||
def run_pyright(filename): | ||
""" | ||
Executes pyright type checker against a file, and returns json output. | ||
Used together with syrupy snapshot to check if typing is working as expected. | ||
""" | ||
result = subprocess.run( | ||
["pyright", "--outputjson", filename], | ||
[pyright_bin, "--outputjson", filename], | ||
capture_output=True, | ||
text=True, | ||
) | ||
assert result.stdout, result.stderr | ||
output = json.loads(result.stdout) | ||
|
||
def clean_row(data): | ||
def format_row(data): | ||
# Remove "file" from json report, it has no use here. | ||
del data["file"] | ||
return data | ||
|
||
return [clean_row(row) for row in output["generalDiagnostics"]] | ||
return [format_row(row) for row in output["generalDiagnostics"]] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,19 @@ | ||
import pytest | ||
import sys | ||
from .base import run_pyright | ||
|
||
import pytest | ||
|
||
from .base import run_pyright, pyright_installed | ||
|
||
|
||
@pytest.mark.skipif( | ||
sys.version_info < (3, 7), | ||
reason="Requires Python 3.7+", | ||
) | ||
@pytest.mark.skipif( | ||
not pyright_installed, | ||
reason="Pyright not installed", | ||
) | ||
def test_typing(snapshot): | ||
"""Test that pyright detects the typing issues on `test_file` correctly.""" | ||
actual = run_pyright("tests/pyright/test_file.py") | ||
assert actual == snapshot |