Skip to content

Commit

Permalink
Remove the type hitn overloads.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tonyandrewmeyer committed Sep 21, 2023
1 parent 53f86b8 commit 384b44d
Showing 1 changed file with 0 additions and 18 deletions.
18 changes: 0 additions & 18 deletions ops/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 384b44d

Please sign in to comment.