Conversation
tromai
marked this pull request as ready for review
September 10, 2026 05:16
Contributor
Author
|
@SimonRichardson This PR is ready for review. However, it is based on top of #141's branch (I performed a couple of merges). I suggest reviewing and merging #141 first before this one. |
tromai
force-pushed
the
add-pyright
branch
2 times, most recently
from
September 21, 2026 06:55
bf86684 to
637f83a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds type checking with
pyright.The section below discusses the errors raised by
pyright, and my proposed fixes.ops.testing.SIMULATE_CAN_CONNECTnot foundIn
tests/__init__.pySolution: Remove
ops.testing.SIMULATE_CAN_CONNECT = Truefollowing canonical/operator#873.urllib.requestnot recognizedIn both
src/configchangesocket.pyandsrc/controlsocket.py.This is a trivial fix.
body[...] = valuetype mismatchIn
controlsocket.pybodyis inferred asdict[str, str | None]when it is first initialized. However,bool/floatvalues are later inserted to it.Solution: annotate the type of
body._current_open_telemetry_configreturns type mismatchIn
src/charm.pyValues of
self.config(of type ConfigData) has a Union typebool | int | float | str. Therefore,pyrightinfers the returned object as:which doesn't match
tuple[bool, float, str, bool]in the function signature.Solution: use
cast(T, ...)hdrs=Nonetype mismatch inurllib.error.HTTPErrorIn
tests/test_sockets.py:urllib.error.HTTPErrorexpectshdrs: email.message.Message, notNone. See here.Solution: initialize an empty
email.message.Messageobject.test_sockets.py— MockOpener not assignable to OpenerDirectorA
MockOpenerobject is passed intoControlSocketClient, for example:The
openerparameter ofControlSocketClienthas typeurllib.request.OpenerDirector | None = None. Therefore,pyrightflags a non-compatible type.This is an expected type error, but not a serious one. Since this is for testing purposes, and we control the behaviour of
MockOpener, I proposed ignoring this error with# type: ignore.Need close review
JujuControllerCharm.api_portshould return intThe
.portattribute is an int if present, else it's None (see here). The guardif not parsed_url.portis not recommended since a 0 is falsy. I recommend guarding on the None value instead:I also updated the type annotation of this function to
intinstead ofstr.JujuControllerCharm.ca_certreturn type annotationIn theory,
self._controller_runtime_config("ca-cert")can return None, or a value that is not of typestr. I updated this function to strictly handle mis-match type. Other places incharm.pyalready handlesca_certreturning None correctly.As a drive-by, I added
JujuControllerCharm._controller_runtime_configreturn type sinceruntime_conf.get(key)returns None ifkeydoesn't exist.