Skip to content

Commit

Permalink
Upgraded to mypy 1.5.1
Browse files Browse the repository at this point in the history
We upgraded to mypy 1.5.1 (current latest version) and removed a couple
of unnecessary casts that mypy now does not need anymore.

Since mypy dropped support for Python 3.7, we exclude the check in the
pre-commit script for Python versions below 3.8.
  • Loading branch information
mristin committed Sep 14, 2023
1 parent 1883ed0 commit 8f90547
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 17 deletions.
3 changes: 1 addition & 2 deletions icontract/_recompute.py
Original file line number Diff line number Diff line change
Expand Up @@ -652,8 +652,7 @@ def visit_NamedExpr(self, node: ast.NamedExpr) -> Any:

self.recomputed_values[node] = value

# This assignment is needed to make mypy happy.
target = cast(ast.Name, node.target)
target = node.target

if not isinstance(target.ctx, ast.Store):
raise NotImplementedError(
Expand Down
3 changes: 1 addition & 2 deletions icontract/_represent.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,7 @@ def visit_NamedExpr(self, node: ast.NamedExpr) -> Any:
if node in self._recomputed_values:
value = self._recomputed_values[node]

# This is necessary in order to make mypy happy.
target = cast(ast.Name, node.target)
target = node.target

if _representable(value=value):
self.reprs[target.id] = value
Expand Down
24 changes: 14 additions & 10 deletions precommit.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,23 @@ def main() -> int:
subprocess.check_call(
["yapf", "--diff", "--style=style.yapf", "--recursive"] + yapf_targets, cwd=str(repo_root))

print("Mypy'ing...")
mypy_targets = ["icontract", "tests"]
if sys.version_info >= (3, 6):
mypy_targets.append('tests_3_6')
if sys.version_info < (3, 8):
print("Mypy since 1.5 dropped support for Python 3.7 and "
"you are running Python %s, so skipping.".format(sys.version_info))
else:
print("Mypy'ing...")
mypy_targets = ["icontract", "tests"]
if sys.version_info >= (3, 6):
mypy_targets.append('tests_3_6')

if sys.version_info >= (3, 7):
mypy_targets.append('tests_3_7')
if sys.version_info >= (3, 7):
mypy_targets.append('tests_3_7')

if sys.version_info >= (3, 8):
mypy_targets.append('tests_3_8')
mypy_targets.append('tests_with_others')
if sys.version_info >= (3, 8):
mypy_targets.append('tests_3_8')
mypy_targets.append('tests_with_others')

subprocess.check_call(["mypy", "--strict"] + mypy_targets, cwd=str(repo_root))
subprocess.check_call(["mypy", "--strict"] + mypy_targets, cwd=str(repo_root))

print("Pylint'ing...")
pylint_targets = ['icontract', 'tests']
Expand Down
7 changes: 4 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,12 @@
install_requires=install_requires,
extras_require={
'dev': [
'mypy==0.991', 'pylint==2.13.9', 'yapf==0.20.2', 'tox>=3.0.0', 'pydocstyle>=6.1.1,<7', 'coverage>=4.5.1,<5',
'pylint==2.13.9', 'yapf==0.20.2', 'tox>=3.0.0', 'pydocstyle>=6.1.1,<7', 'coverage>=4.5.1,<5',
'docutils>=0.14,<1', 'pygments>=2.2.0,<3', 'dpcontracts==0.6.0', 'tabulate>=0.8.7,<1',
'py-cpuinfo>=5.0.0,<6', 'typeguard>=2,<3', 'astor==0.8.1', 'numpy>=1,<2'
] + (['deal==4.23.3'] if sys.version_info >= (3, 8) else []) + (['asyncstdlib==3.9.1']
if sys.version_info >= (3, 8) else []),
] + (['mypy==1.5.1'] if sys.version_info >= (3, 8) else []) +
(['deal==4.23.3'] if sys.version_info >= (3, 8) else []) + (['asyncstdlib==3.9.1']
if sys.version_info >= (3, 8) else []),
},
py_modules=['icontract'],
package_data={"icontract": ["py.typed"]},
Expand Down

0 comments on commit 8f90547

Please sign in to comment.