Skip to content

Commit

Permalink
Devops: Update requirements mypy and pre-commit(aiidateam#6408)
Browse files Browse the repository at this point in the history
Also make `mypy` pass for Python 3.12 and newer, which is
failing due to missing `distutils` module in those versions.
  • Loading branch information
danielhollas authored and mikibonacci committed Sep 3, 2024
1 parent efff7e4 commit 3c65a24
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 11 deletions.
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,9 @@ notebook = [
]
pre-commit = [
'aiida-core[atomic_tools,rest,tests,tui]',
'mypy~=1.7.1',
'mypy~=1.10.0',
'packaging~=23.0',
'pre-commit~=2.2',
'pre-commit~=3.5',
'sqlalchemy[mypy]~=2.0',
'tomli',
'types-PyYAML'
Expand Down
18 changes: 12 additions & 6 deletions src/aiida/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,20 @@ def get_strict_version():
:returns: StrictVersion instance with the current version
:rtype: :class:`!distutils.version.StrictVersion`
"""
from distutils.version import StrictVersion
import sys

from aiida.common.warnings import warn_deprecation
if sys.version_info >= (3, 12):
msg = 'Cannot use get_strict_version() with Python 3.12 and newer'
raise RuntimeError(msg)
else:
from distutils.version import StrictVersion

warn_deprecation(
'This method is deprecated as the `distutils` package it uses will be removed in Python 3.12.', version=3
)
return StrictVersion(__version__)
from aiida.common.warnings import warn_deprecation

warn_deprecation(
'This method is deprecated as the `distutils` package it uses will be removed in Python 3.12.', version=3
)
return StrictVersion(__version__)


def get_version() -> str:
Expand Down
2 changes: 1 addition & 1 deletion src/aiida/common/lang.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def wrapped_fn(self, *args, **kwargs):

return func(self, *args, **kwargs)
else:
wrapped_fn = func
wrapped_fn = func # type: ignore[assignment]

return wrapped_fn # type: ignore[return-value]

Expand Down
3 changes: 2 additions & 1 deletion src/aiida/engine/daemon/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ def start_daemon_worker(foreground: bool = False) -> None:

signals = (signal.SIGTERM, signal.SIGINT)
for s in signals:
runner.loop.add_signal_handler(s, lambda s=s: asyncio.create_task(shutdown_worker(runner)))
# https://github.com/python/mypy/issues/12557
runner.loop.add_signal_handler(s, lambda s=s: asyncio.create_task(shutdown_worker(runner))) # type: ignore[misc]

try:
LOGGER.info('Starting a daemon worker')
Expand Down
2 changes: 1 addition & 1 deletion src/aiida/engine/processes/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def get_stack_size(size: int = 2) -> int: # type: ignore[return]
while frame: # type: ignore[truthy-bool]
frame = frame.f_back # type: ignore[assignment]
size += 1
return size - 1
return size - 1 # type: ignore[unreachable]


P = ParamSpec('P')
Expand Down

0 comments on commit 3c65a24

Please sign in to comment.