Repository navigation
Various mypy related updates - #55255
Conversation
|
@rkachach can you please take a look into the final commit in this PR ( |
There was a problem hiding this comment.
i am far from an expert in the rook mgr module, but i think the fix is correct. and probably a better fix would be to initialize sizematcher with AllMatcher('', None) instead, like
sizematcher: Matcher = AllMatcher('', None)
# ...
all
or (device.sys_api['node'] in matching_hosts
and sizematcher.compare(device)
and ...
)There was a problem hiding this comment.
Thanks, that suggestion is much clearer to read. I have pushed a change for that. I'll still wait for a general thumbs-up/down from someone with rook module experience, at least for a day or two.
There was a problem hiding this comment.
@phlogistonjohn I think both your change and the improvement suggested by @tchaikov are correct. Anyway, as far as I know this code is not being used in rook latest versions anymore (it's part of OSDs creation which is now managed by the Rook orch).
rkachach
left a comment
There was a problem hiding this comment.
rook related changes LGTM
Configure mypy not to use namespace packages as the cython source dirs
in src/pybind/{cephfs,rados,rbd}, etc. confuse mypy into thinking
it's an empty namespace package rather than a missing module.
Found using mypy 0.990.
Signed-off-by: John Mulligan <[email protected]>
When run locally mypy complains about the `name` field, possibly due to us using an old mypy version on newer versions of python (we're stuck on a Sept. 2022 version if you weren't aware). However, this could still be an issue in mypy as there are open issues related to the `.name` field of an enum. Regardless, we wouldn't know - so just work around it. Signed-off-by: John Mulligan <[email protected]>
Found using mypy 0.990. Newer versions of mypy see that the callback function passed to `addFilter` are expected to return a bool. Update `cherrypy_filter` to do have the correct type. I did not try to fix the issue that this same function seems copy-pasted into three different files. >:-} Signed-off-by: John Mulligan <[email protected]>
Found using mypy 0.990. Newer mypy versions see the check as tautological because `self.func` is typed as always being `Callable` and thus always true. I don't know if the typing is wrong or if the if-block is tautological (and redundant). For now, silence the error by using `getattr` instead of direct attribute access. Signed-off-by: John Mulligan <[email protected]>
Found using mypy 0.990. Fix mypy error by excluding both imports in the try-except block. Type-narrow the `ex.request` variable with an assert. Signed-off-by: John Mulligan <[email protected]>
Found using mypy 0.990. The `yaml_representer` function returns a Node type, not Any. Newer versions of mypy understand this and complain. Signed-off-by: John Mulligan <[email protected]>
Namespace package support confuses mypy in regards to the
pybind/{cephfs,rados,rbd}, etc when using mypy >= 0.990.
Turning them off seems to not be a problem for the ceph code.
Signed-off-by: John Mulligan <[email protected]>
60cc055 to
8090a80
Compare
|
hi John, thank you for fixing the mypy issues! mypy did help us to address quite a few issues lurking around in the mgr modules when we introduced the type annotation system to the source tree. i am very glad it is still very helpful with your efforts.
so, IIUC, there are still some issues identified by newer version of mypy even after your change, right? |
|
All required checks are passing... moving to ready for review. |
Unless I overlooked something, no - the codebase should be clean for all currently released versions of mypy. However, not all versions of mypy work with all the python versions ceph currently supports. Plus, the way the tox.ini files are written in the ceph tree makes it difficult to try different combinations of mypy / python. On top of that I wanted to research if we could use the python version option. And I was hesitant to change it before the work getting centos 9 working was done. So I chose to wait and make the version bump in a later pr. |
There was a problem hiding this comment.
I'd apply the same treatment to fio_size_mb on line 606 for consistency. cc @petrutlucian94
There was a problem hiding this comment.
Done. I wasn't sure if you preferred to have just the default value changed or changed + type annotated so I did the latter. I can undo it if that's an issue.
adk3798
left a comment
There was a problem hiding this comment.
cephadm/orchestrator pieces LGTM
There was a problem hiding this comment.
just curious, did mypy actually complain about the use of Any here, or did you just want to make the type more specific
There was a problem hiding this comment.
It complained. But after looking into it again, it's not merely a new version of mypy alone but a newer version of types-PyYAML is also needed to get the errors:
orchestrator/__init__.py:6: note: In module imported here:
orchestrator/_interface.py:1284: error: Argument 2 to "add_representer" has incompatible type "Callable[[SafeDumper, DaemonDescription], Any]"; expected "Callable[[Dumper, DaemonDescription], Node]" [arg-type]
orchestrator/_interface.py:1417: error: Argument 2 to "add_representer" has incompatible type "Callable[[SafeDumper, ServiceDescription], Any]"; expected "Callable[[Dumper, ServiceDescription], Node]" [arg-type]
orchestrator/__init__.py:3: note: In module imported here:
orchestrator/module.py:136: error: Argument 2 to "add_representer" has incompatible type "Callable[[SafeDumper, HostDetails], Any]"; expected "Callable[[Dumper, HostDetails], Node]" [arg-type]
Found using mypy 1.1.1. Signed-off-by: John Mulligan <[email protected]>
Typing issue was found by mypy 1.5.1. The type only accepted values of str but based on the data and code using set_column data the boolean assignments to the 'isHidden' key were correct and so I updated the type to also accept bool. A more correct fix might be to use typing.TypedDict - this would require python 3.8 (or typing extensions) and someone more familiar with the dashboard code :-) Signed-off-by: John Mulligan <[email protected]>
Issue found by mypy 1.6.1. The previous code was: `and ((sizematcher != None) or sizematcher.compare(device)` meaning that if sizematcher is not none "return" true, but if sizematcher is not none execute the compare method. This is of course impossible as None will never have a compare method. I assume that the At Kefu Chai's suggestion we can replace the None condition with an AllMatcher object when no size is provided to create a size matcher. This both corrects the error and makes the code much simpler and more readable. Signed-off-by: John Mulligan <[email protected]>
Every time I looked at these functions my brain would be thrown off by
`all or ...` as I see all as the builtin function `all`:
https://docs.python.org/3/library/functions.html#all
Rename `all` so that it avoids shadowing the function `all` and avoid
some confusion for people like me.
Signed-off-by: John Mulligan <[email protected]>
8090a80 to
a450820
Compare
Pegonzal
left a comment
There was a problem hiding this comment.
the mgr/dashboard changes look good as well
|
@adk3798 I think we have sufficient reviews from the various functional areas to look towards merging. Let me know if there's anything else that needs to be handled before then. |
In PR ceph#55255 I updated various files to be valid on newer versions of mypy. Update the constrains file to specify mypy 1.1.1. This certainly is not the newest version of mypy, but because ceph uses various older versions of python I am being cautious and trying to only incrementally update the mypy version. This version fixed an issue or two I hit while working on a prototype manager module compared to the previous version in the mypy-constrains.txt file. Signed-off-by: John Mulligan <[email protected]>
In PR ceph#55255 I updated various files to be valid on newer versions of mypy. Update the constrains file to specify mypy 1.1.1. This certainly is not the newest version of mypy, but because ceph uses various older versions of python I am being cautious and trying to only incrementally update the mypy version. This version fixed an issue or two I hit while working on a prototype manager module compared to the previous version in the mypy-constrains.txt file. Signed-off-by: John Mulligan <[email protected]> (cherry picked from commit 6873a5c)
In PR ceph#55255 I updated various files to be valid on newer versions of mypy. Update the constrains file to specify mypy 1.1.1. This certainly is not the newest version of mypy, but because ceph uses various older versions of python I am being cautious and trying to only incrementally update the mypy version. This version fixed an issue or two I hit while working on a prototype manager module compared to the previous version in the mypy-constrains.txt file. Signed-off-by: John Mulligan <[email protected]>
In PR ceph#55255 I updated various files to be valid on newer versions of mypy. Update the constrains file to specify mypy 1.1.1. This certainly is not the newest version of mypy, but because ceph uses various older versions of python I am being cautious and trying to only incrementally update the mypy version. This version fixed an issue or two I hit while working on a prototype manager module compared to the previous version in the mypy-constrains.txt file. Signed-off-by: John Mulligan <[email protected]> (cherry picked from commit b1fc58e)
While working on one task I ran into some mypy related issue that I thought may be fixed in newer versions of mypy. But I was not easily able to try a newer version because the version is pinned in a "global" mypy constraints file - and updating the version there caused various new issues to appear.
After a period of groaning I decided that trying to make the codebase work on newer versions of mypy was worthwhile and something I had thought of doing previously anyway. I've tested on versions of mypy from 0.990 - 1.8.0. This PR does not change the pinned version of mypy it just makes it easier to make that change in the future.
Most everything the newer versions of mypy found were valid, with the exception of the detecting the cython based extension sources as empty namespace packages forcing me the turn off namespace package support. However, this seems to have had no negative side effects so it seems like a valid workaround for now.
One change (currently prefixed by
xxxin the commit message) in the rook module seems to have a legit logical error. But I wasn't clear if my fix is correct. So I may need some help verifying it before taking the PR out of draft.Checklist
Show available Jenkins commands
jenkins retest this pleasejenkins test classic perfjenkins test crimson perfjenkins test signedjenkins test make checkjenkins test make check arm64jenkins test submodulesjenkins test dashboardjenkins test dashboard cephadmjenkins test apijenkins test docsjenkins render docsjenkins test ceph-volume alljenkins test ceph-volume toxjenkins test windowsjenkins test rook e2e