Skip to content

Instantly share code, notes, and snippets.

@dimaqq
Last active August 28, 2024 01:17
Show Gist options
  • Save dimaqq/d00d6c2d72762ad3b4a3df986f849690 to your computer and use it in GitHub Desktop.
Save dimaqq/d00d6c2d72762ad3b4a3df986f849690 to your computer and use it in GitHub Desktop.
Fixing ops.main() type hints, the protocol version
from typing import Protocol, cast
import ._main
import .main as _legacy_main
class Main(Protocol):
def __call__(self, arg1: Arg1, ...): ...
def main(self, arg1: Arg1, ...): ...
main = cast(Main, _main.main)
main.main = _legacy_main.main
# Move code from today's ops/main.py here
def _emit_charm_event(...):
code code
def main(arg1: Arg1, ...):
code code
# Warning: this module is deprecated, kept only for backwards compatibility
# todo: warnings.deprecated is py 3.13 feature, we'd vendor a simplified copy
from warnings import deprecated
import ._main
main = deprecated("Call opa.main() instead")(_main.main)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment