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

Type annotate PebbleReadyEvent.workload #962

Merged
merged 1 commit into from
Jul 4, 2023

Conversation

benhoyt
Copy link
Collaborator

@benhoyt benhoyt commented Jul 4, 2023

One more thing forgotten from #953. This is annoying because it means that charms that use ops.PebbleReadyEvent annotations when handling pebble-ready can't access any attributes of the workload, as it doesn't have a type.

For example:

/tmp/pytest-of-runner/pytest-0/test_tests_simple_0/src/charm.py
  /tmp/pytest-of-runner/pytest-0/test_tests_simple_0/src/charm.py:44:19 - error: "add_layer" is not a known member of "None" (reportOptionalMemberAccess)
  /tmp/pytest-of-runner/pytest-0/test_tests_simple_0/src/charm.py:46:19 - error: "replan" is not a known member of "None" (reportOptionalMemberAccess)
2 errors, 0 warnings, 0 informations 

benhoyt added a commit to benhoyt/charmcraft that referenced this pull request Jul 4, 2023
Notes:
* Type checkers like the self.on["container"].pebble_ready syntax over
  the magic self.on.container_pebble_ready shorthand, so go with that.
* Unfortunately we need a "type: ignore" on the ops.main() call as
  main() is a special module+function due to canonical/operator#910.
* The "simple" charm will only work with ops>=2.4.1 due to
  canonical/operator#962. Will ship 2.4.1 imminently.
* I've changed the ops version pinning to 2.x (but 2.4 or higher).
@benhoyt
Copy link
Collaborator Author

benhoyt commented Jul 4, 2023

Minor tweak forgotten from #953, and gets in the way of canonical/charmcraft#1137, so going to merge this so I can ship an ops patch release 2.4.1.

@benhoyt benhoyt merged commit eb57958 into canonical:main Jul 4, 2023
@benhoyt benhoyt deleted the pebble-ready-workload-type branch July 4, 2023 04:51
syu-w pushed a commit to canonical/charmcraft that referenced this pull request Jul 4, 2023
This is part of my work in
canonical/operator#920. Notes:

* Type checkers like the `self.on["container"].pebble_ready` syntax over
the magic `self.on.container_pebble_ready` shorthand, so go with that.
* Unfortunately we need a "type: ignore" on the ops.main() call as
main() is a special module+function due to canonical/operator#910.
* The "simple" charm will only work with ops>=2.4.1 due to
canonical/operator#962. Will ship 2.4.1 imminently.
* I've changed the ops version pinning to 2.x (but 2.4 or higher).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant