From 384b44d2aea044114ceadb3945a7954eca6eeba0 Mon Sep 17 00:00:00 2001 From: Tony Meyer Date: Fri, 22 Sep 2023 08:40:52 +1200 Subject: [PATCH] Remove the type hitn overloads. In other repos, there's code like this: Unfortunately, pyright cannot tell that the protocol argument is always 'tcp' in this case, only that the protocol is one of tcp/udp/icmp, and that's too broad to fit the righter overloaded specs, so it complains. This could be handled with changes in the upstream places, but I don't see any simple way to handle it within ops itself. This was a minor improvement and not really needed, plus it's in the two methods that we're wanting to move people away from, so drop this change. --- ops/model.py | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/ops/model.py b/ops/model.py index d45594d9d..fcd6597df 100644 --- a/ops/model.py +++ b/ops/model.py @@ -593,15 +593,6 @@ def add_secret(self, content: Dict[str, str], *, owner='unit') return Secret(self._backend, id=id, label=label, content=content) - if typing.TYPE_CHECKING: - @typing.overload - def open_port(self, protocol: typing.Literal['tcp', 'udp'], port: int) -> None: # noqa - ... - - @typing.overload - def open_port(self, protocol: typing.Literal['icmp'], port: None = None) -> None: # noqa - ... - def open_port(self, protocol: typing.Literal['tcp', 'udp', 'icmp'], port: Optional[int] = None) -> None: """Open a port with the given protocol for this unit. @@ -637,15 +628,6 @@ def open_port(self, protocol: typing.Literal['tcp', 'udp', 'icmp'], raise ModelError(f"{normalised_protocol} must have a port number specified") self._backend.open_port(normalised_protocol, port) - if typing.TYPE_CHECKING: - @typing.overload - def close_port(self, protocol: typing.Literal['tcp', 'udp'], port: int) -> None: # noqa - ... - - @typing.overload - def close_port(self, protocol: typing.Literal['icmp'], port: None = None) -> None: # noqa - ... - def close_port(self, protocol: typing.Literal['tcp', 'udp', 'icmp'], port: Optional[int] = None) -> None: """Close a port with the given protocol for this unit.