-
Notifications
You must be signed in to change notification settings - Fork 191
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
Bump mypy version to ~=1.13.0 #6630
Changes from 7 commits
3e4f3ef
b6800dc
f415f55
0dabade
2c0948f
ac5473e
7b9e02e
d1cc350
e636253
7b18eab
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1062,7 +1062,7 @@ def presubmit(self, folder: Folder) -> CalcInfo: | |
|
||
def encoder(obj): | ||
if dataclasses.is_dataclass(obj): | ||
return dataclasses.asdict(obj) | ||
return dataclasses.asdict(obj) # type: ignore[arg-type] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure I should cast the type here, for the readability, I ignore the error. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would try to solve this in a subsequent PR |
||
raise TypeError(f' {obj!r} is not JSON serializable') | ||
|
||
subfolder = folder.get_subfolder('.aiida', create=True) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -278,7 +278,7 @@ def array_list_checker(array_list, array_name, orb_length): | |
raise exceptions.ValidationError('Tags must set a list of strings') | ||
self.base.attributes.set('tags', tags) | ||
|
||
def set_orbitals(self, **kwargs): | ||
def set_orbitals(self, **kwargs): # type: ignore[override] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll just leave There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add a TODO comment with the error? The mypy error suggests that this is an actual error? Or do you think it's a false positive? projection.py:281: error: Signature of "set_orbitals" incompatible with supertype "OrbitalData" [override]
projection.py:281: note: Superclass:
projection.py:281: note: def set_orbitals(self, orbitals: Any) -> Any
projection.py:281: note: Subclass:
projection.py:281: note: def set_orbitals(self, **kwargs: Any) -> Any There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Neither, I think it is a design issue to use inheritance everywhere in the code base. Here it makes sense that the ProjectionData is only inheritant from But since this method is just to override and block the method, so the type in the function call doesn't matter. Just ignore to skip the checker. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we just merge it and if this is a problem make an issue out of it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I move this change to #6635, so let's continue the discussion there. |
||
"""This method is inherited from OrbitalData, but is blocked here. | ||
If used will raise a NotImplementedError | ||
""" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,7 +38,7 @@ def __init__(self): | |
def logger(self) -> Logger: | ||
return self._logger | ||
|
||
def get_version_info(self, plugin: str | type) -> dict[t.Any, dict[t.Any, t.Any]]: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @unkcpz FYI I think this has a similar issue that we discussed, I don't think adding Any here is correct. Let's discuss on the other PR, but just flagging it here as well so we don't forget. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The original error was:
Still struggling to understand, will need to experiment a bit. |
||
def get_version_info(self, plugin: str | t.Any) -> dict[t.Any, dict[t.Any, t.Any]]: | ||
"""Get the version information for a given plugin. | ||
|
||
.. note:: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -116,7 +116,7 @@ def test(submit_and_await): | |
from aiida.engine import ProcessState | ||
|
||
def factory( | ||
submittable: 'Process' | 'ProcessBuilder' | 'ProcessNode', | ||
submittable: type[Process] | 'ProcessBuilder' | 'ProcessNode' | t.Any, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because there is an else branch otherwise the branch is unreachable. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, makes sense, sorry I originally missed your comment with the errors. I think the correct fix here is to add type ignores on those branches, since those essentially represent runtime type checking, which we need to enforce. At the same time we don't want to make static type checking weaker. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I may not fully agree. I think types in the function signature plays two functionalities. On the one hand, it partially is the hint for the function behavior, like in this case in the function body it requires to explicitly deal with three types and raise if it doesn't know what to do with certain type. On the other hand, the type in the function signature is for other function to know what should be passed to the function when it is called. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I agree with this sentiment, but introducing
But we don't want to rely on runtime checks only. If we can catch it statically that's certainly better, no? Sorry if I am being terse, I am teaching now, am happy to write more later today if needed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the correct thing to do here is to NOT change the type annotation, since it was correct. add type: ignore to the else branch, where the error originates. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I agree that the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again, I personally don't like the way how subclass of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In mega office, we decide to merge this one and continue the discussion here to not block other PRs. @danielhollas hope you don't mind. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, go ahead
unkcpz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
state: ProcessState = ProcessState.FINISHED, | ||
timeout: int = 20, | ||
**kwargs, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,7 @@ class Model(BaseModel): | |
union_type: t.Union[int, float] = Field(title='Union type') | ||
without_default: str = Field(title='Without default') | ||
with_default: str = Field(title='With default', default='default') | ||
with_default_factory: str = Field(title='With default factory', default_factory=lambda: True) | ||
with_default_factory: str = Field(title='With default factory', default_factory=lambda: True) # type: ignore[assignment] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is test, so I just ignore it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, when I run mypy 1.13 on this, the |
||
|
||
|
||
def test_list_options(entry_points): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Field
seems can return None, if so thefield_info
won't havemetadata
attribute.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice fix. cc @edan-bainglass for visibility