Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make mypy pass with Python 3.12 #6408

Merged
merged 1 commit into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading