Skip to content

Bump mypy to 1.16.0 #6858

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

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open

Conversation

danielhollas
Copy link
Collaborator

This is a nice bump since we can remove a lot of type: ignore comments!

@@ -122,17 +122,17 @@ def profile_setup():
"""Set up a new profile."""


@verdi_profile.command('configure-rabbitmq') # type: ignore[arg-type]
@verdi_profile.command('configure-rabbitmq')
@click.pass_context
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not quite sure why, but moving pass_context here fixed the following error:

src/aiida/cmdline/commands/cmd_profile.py:135: error: Argument 1 to "pass_context" has incompatible type "Callable[[Any, Any, Any, Any, KwArg(Any)], Any]"; expected "Callable[[Context, Any, Any, Any, KwArg(Any)], Any]"  [arg-type]
src/aiida/cmdline/commands/cmd_profile.py:135: note: This is likely because "profile_configure_rabbitmq" has named arguments: "ctx". Consider marking them positional-only

except Exception as exception:
LOGGER.warning(f'function `{func.__name__}` has a docstring that could not be parsed: {exception}')
param_help_string = {}
if func.__doc__ is None:
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fixes:

src/aiida/engine/processes/functions.py:377: error: Argument 1 to "parse" has incompatible type "str | None"; expected "str"  [arg-type]

Github is very confused, the diff here is actually not that bad, we're just handling the func.__doc__ is None case pre-emptively. (We could also log a warning if a calcfunction is missing a docstring, but that seems overly pedantic)

@@ -435,7 +439,7 @@ def define(cls, spec):
def indirect_default(value=default):
return to_aiida_type(value)
else:
indirect_default = default
indirect_default = default # type: ignore[assignment]
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not super clear how to solve this one, since indirect_default can be basically anything

src/aiida/engine/processes/functions.py:438: error: Incompatible types in assignment (expression has type "Any | tuple[()]", variable has type "Callable[[Any], Any]") [assignment]

@@ -80,7 +80,7 @@ class Process(PlumpyProcess):
class SaveKeys(enum.Enum):
"""Keys used to identify things in the saved instance state bundle."""

CALC_ID: str = 'calc_id'
CALC_ID = 'calc_id'
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

src/aiida/engine/processes/process.py:83: error: Enum members must be left unannotated [misc]
src/aiida/engine/processes/process.py:83: note: See https://typing.readthedocs.io/en/latest/spec/enums.html#defining-members

Copy link

codecov bot commented May 6, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 78.59%. Comparing base (edb8c7e) to head (4db11f8).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6858      +/-   ##
==========================================
- Coverage   78.60%   78.59%   -0.00%     
==========================================
  Files         567      567              
  Lines       43096    43099       +3     
==========================================
+ Hits        33870    33871       +1     
- Misses       9226     9228       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@agoscinski
Copy link
Contributor

agoscinski commented May 6, 2025

Note to me: There seems to be also mypy fixes here #6641 Need to check this too. I think we first merge this PR and then rebase the other

@agoscinski
Copy link
Contributor

I approve the changes. Just waiting till we release v2.7.0 before merge

@danielhollas
Copy link
Collaborator Author

I think we first merge this PR and then rebase the other

Yes, I think merging this first makes sense since clearly mypy got better at inferring some types. I also have three typing PRs in progress, #6833 #6707 and #6704, which I will rebase once this is merged.

@danielhollas danielhollas changed the title Bump mypy to 1.15.0 Bump mypy to 1.16.0 Jun 3, 2025
@@ -78,7 +78,7 @@ repos:
- id: mypy
name: mypy
entry: mypy
args: [--config-file=pyproject.toml]
args: [--config-file=pyproject.toml, --pretty]
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't know about the --pretty option before, but it results in much friendlier error messages!

@@ -137,7 +137,7 @@ def apply_options(func):
shared_options.reverse()

for option in shared_options:
func = option(func)
func = option(func) # type: ignore[operator]
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand why this is needed all of a sudden, especially given that we have basically identical code couple lines above that apparently is fine. mypy error:

src/aiida/cmdline/groups/dynamic.py:140: error: "Option" not callable  [operator]

@@ -231,7 +231,7 @@ def get_code_helper(cls, label, machinename=None, backend=None):
return result[0]

@classmethod
def get(cls, pk=None, label=None, machinename=None):
def get(cls, pk=None, label=None, machinename=None): # type: ignore[override]
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand why mypy complains here:

src/aiida/orm/nodes/data/code/legacy.py:234: error: Signature of "get"
incompatible with supertype "Entity"  [override]
        def get(cls, pk=None, label=None, machinename=None):
        ^
src/aiida/orm/nodes/data/code/legacy.py:234: note:      Superclass:
src/aiida/orm/nodes/data/code/legacy.py:234: note:          @classmethod
src/aiida/orm/nodes/data/code/legacy.py:234: note:          def get(cls, **kwargs: Any) -> Any
src/aiida/orm/nodes/data/code/legacy.py:234: note:      Subclass:
src/aiida/orm/nodes/data/code/legacy.py:234: note:          @classmethod
src/aiida/orm/nodes/data/code/legacy.py:234: note:          def get(cls, pk: Any = ..., label: Any = ..., machinename: Any = ...) -> Any

@@ -924,7 +924,7 @@ def _import_links(
raise ImportUniquenessError(
f'Node {in_id} already has an outgoing {link_type.value!r} link with label {link_label!r}'
)
if 'out_id' in link_uniqueness and out_id in existing_out_id_label:
if 'out_id' in link_uniqueness and out_id in existing_out_id:
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a genuine bug! Please see the surrounding code to understand the fix.

Also note how the --pretty mypy output is helpful here!

src/aiida/tools/archive/imports.py:927: error: Non-overlapping container check (element type: "int", container item type: "tuple[Any, Any]")  [comparison-overlap]
    ...              if 'out_id' in link_uniqueness and out_id in existing_ou...
                                                        ^~~~~~~~~~~~~~~~~~~~~...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: In review
Development

Successfully merging this pull request may close these issues.

2 participants