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

test: add type hints to test_model #1015

Merged
merged 17 commits into from
Sep 29, 2023

Conversation

tonyandrewmeyer
Copy link
Contributor

@tonyandrewmeyer tonyandrewmeyer commented Sep 27, 2023

  • One change to ops/charm, but only in the type hints. It looks from the use of Required that the other fields are not meant to be required, so make that the case (this also appears to match the code).
  • Ignore types in the tests that are checking that bad types are handled properly.
  • Help type checkers understand when some optional attributes won't be None.
  • Replace a few bits of code where a minimal object was passed, enough for the test to do it's check, but not of the correct type, with an actual object of the proper type.
  • Sprinkle type hints where required for pyright to understand what's happening.

Partially addresses #1007

Copy link
Collaborator

@benhoyt benhoyt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work! Left a bunch of suggestions to simplify / clean a few things up.

test/test_model.py Show resolved Hide resolved
test/test_model.py Outdated Show resolved Hide resolved
test/test_model.py Outdated Show resolved Hide resolved
test/test_model.py Outdated Show resolved Hide resolved
test/test_model.py Outdated Show resolved Hide resolved
test/test_model.py Outdated Show resolved Hide resolved
test/test_model.py Outdated Show resolved Hide resolved
test/test_model.py Outdated Show resolved Hide resolved
test/test_model.py Outdated Show resolved Hide resolved
test/test_model.py Show resolved Hide resolved
tonyandrewmeyer and others added 8 commits September 28, 2023 13:45
Co-authored-by: Ben Hoyt <benhoyt@gmail.com>
Co-authored-by: Ben Hoyt <benhoyt@gmail.com>
Co-authored-by: Ben Hoyt <benhoyt@gmail.com>
Co-authored-by: Ben Hoyt <benhoyt@gmail.com>
Co-authored-by: Ben Hoyt <benhoyt@gmail.com>
Copy link
Collaborator

@benhoyt benhoyt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the updates! I won't merge this until you make a final decision on those last outstanding comments -- your call as to whether to use typing.Any or whatever there, or keep the annotations.

@benhoyt benhoyt merged commit 52161a1 into canonical:main Sep 29, 2023
19 checks passed
@tonyandrewmeyer tonyandrewmeyer deleted the pyright-test_model-1007 branch September 29, 2023 03:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants