Skip to content

Commit

Permalink
Fix type checking issue with service_ports
Browse files Browse the repository at this point in the history
This worked in Pyright 1.1.314, but not in 1.1.315 or 1.1.316.

The type of service_ports is
List[Tuple[str, Literal[3000], Literal[3000]]], which doesn't type
check as List[Tuple[str, int, int]] -- which is very unintuitive, but
oh well.

I believe this is by design, see
microsoft/pyright#5366 and
https://microsoft.github.io/pyright/#/type-inference?id=tuple-expressions

The Pyright fixes were probably one of
microsoft/pyright#5321 or
microsoft/pyright#5323
  • Loading branch information
benhoyt committed Jun 27, 2023
1 parent 89d2d96 commit c992a88
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import time
from io import StringIO
from pathlib import Path
from typing import Any, Callable, Dict
from typing import Any, Callable, Dict, List, Tuple
from urllib.parse import ParseResult, urlparse

import yaml
Expand Down Expand Up @@ -573,7 +573,7 @@ def _on_dashboards_changed(self, event) -> None:
def _patch_k8s_service(self):
"""Fix the Kubernetes service that was setup by Juju with correct port numbers."""
if self.unit.is_leader() and not self._stored.k8s_service_patched: # type: ignore[truthy-function]
service_ports = [
service_ports: List[Tuple[str, int, int]] = [
(self.app.name, PORT, PORT),
]
try:
Expand Down

0 comments on commit c992a88

Please sign in to comment.