Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: tell type checkers that the config options are strings (trivial) #208

Merged
merged 2 commits into from
Apr 16, 2024

Conversation

tonyandrewmeyer
Copy link
Contributor

Applicable spec: N/A

Overview

ops<=2.12 wrongly has self.config[x] typed as str, when actually it could be an int, float, bool, or str, depending on the config type. We're fixing this in ops:#1183, but that will break static checking that currently assumes that the config is a str (because ops doesn't validate the schema, so all options will be bool|int|float|str).

This PR adds a typing.cast call where the config values are loaded and used where the type should be str.

Rationale

Covered in the overview.

Juju Events Changes

N/A

Module Changes

N/A

Library Changes

N/A

Checklist

No docs changes required.

@tonyandrewmeyer tonyandrewmeyer requested a review from a team as a code owner April 11, 2024 05:34
@yanksyoon
Copy link
Collaborator

/canonical/self-hosted-runners/run-workflows 22207de

@arturo-seijas
Copy link
Collaborator

/canonical/self-hosted-runners/run-workflows 2bc4cd7

Copy link
Contributor

Test coverage for 2bc4cd7

Name                Stmts   Miss Branch BrPart  Cover   Missing
---------------------------------------------------------------
src/charm.py          540     35    184     33    91%   162, 203-206, 370, 429->433, 582, 613, 619, 636-640, 670, 705-706, 764, 773, 877->890, 889, 891, 896-897, 957, 977, 984, 1074, 1083, 1095, 1116, 1125, 1144, 1148, 1177, 1230, 1362, 1384, 1391->1393, 1436->exit, 1448, 1458, 1496
src/cos.py             21      0      0      0   100%
src/exceptions.py      17      1      2      1    89%   41
src/state.py           34      0      4      0   100%
src/types_.py          16      0      0      0   100%
---------------------------------------------------------------
TOTAL                 628     36    190     34    91%

Static code analysis report

Run started:2024-04-16 08:52:05.609996

Test results:
  No issues identified.

Code scanned:
  Total lines of code: 4586
  Total lines skipped (#nosec): 1
  Total potential issues skipped due to specifically being disabled (e.g., #nosec BXXX): 0

Run metrics:
  Total issues (by severity):
  	Undefined: 0
  	Low: 0
  	Medium: 0
  	High: 0
  Total issues (by confidence):
  	Undefined: 0
  	Low: 0
  	Medium: 0
  	High: 0
Files skipped (0):

@arturo-seijas arturo-seijas merged commit f37e046 into canonical:main Apr 16, 2024
25 of 29 checks passed
@tonyandrewmeyer tonyandrewmeyer deleted the fix-config-types branch April 18, 2024 01:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants