-
Notifications
You must be signed in to change notification settings - Fork 119
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
fix: rework ops.main type hints to allow different flavours (callable module) #1331
Conversation
b9b0f87
to
87b340b
Compare
Some tests fail under py 3.8, investigating... |
We don't actually want people doing these other than two of them, though. Is the purpose of the PR to allow more ways to invoke main? I don't see why we would want that. Or is this to improve the type annotation situation? If that's the case it seems good, but we should have the PR description say that.
What's the story now given that #1327 is closed not merged? |
4008077
to
d8b491d
Compare
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! It will be great to get rid of those # type:ignore
s in all the charms.
A couple of small queries/suggestions.
1175cf7
to
4af441a
Compare
Re failing tests: this is a bit weird... I need to check if maybe something got unmocked wrong or some other inter-test dependency is at play. I've tried a few of these tests and they pass individually. |
4af441a
to
8e182f6
Compare
I was able to reproduce the GHA test failure. Example:
Fails under Python 3.8, 3.9, 3.10; Edit: fixed now. I understand the failure and I'm actually surprised how on earth it worked under newer Python. Perhaps unittest.mock.patch got really really clever in py 3.11. |
Doc fail:
Now wonder when this commit is in my fork, not canonical. |
aca6448
to
cdebf33
Compare
That PR became irrelevant after JujuContext landed. |
85b6700
to
bf4a7ba
Compare
bf4a7ba
to
b4347e4
Compare
b4347e4
to
3aef186
Compare
True, but we don't want to break existing charms, do we? |
Yes, I agree completely that we have to support any way of calling main that we currently do now. But we don't need to remove the need to use |
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.
Looks good, thanks - just a couple of small queries.
Thanks for doing the broad test against charms (super_tox) - it's good to be confident in how this will impact everyone.
class IdleCharm(ops.CharmBase): | ||
def __init__(self, framework: ops.Framework): | ||
super().__init__(framework) |
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.
Is there any need to have this and not just use CharmBase
?
|
||
def type_test_dummy(_arg: Callable[[Type[ops.CharmBase], bool], None]): | ||
""" | ||
Helper to verify that |
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.
It seems like maybe there were meant to be more words there?
Closing in favour of #1345 |
Rework the callable module to support any of the existing ops entry point invocations:
Manual mypy tests:
nginx-ingress-integrator-operator
mypy 1.6.1 OKsdcore-webui-operator
mypy 1.11.1 OKSuper-tox: 114/115 (ran on host)
One lint failure in
hardware-observer-operator
:error: Unused "type: ignore" comment [unused-ignore]
Code in question:
This is mypy complaining, because this project includes
warn_unused_ignores = true
in[tool.mypy]
settings.