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

ci: make Pyright report unnecessary type ignore comments #1333

Merged

Conversation

dimaqq
Copy link
Contributor

@dimaqq dimaqq commented Aug 23, 2024

Parent: https://warthogs.atlassian.net/browse/CHARMTECH-232

Covered in the parent epic:

  • charmcraft analyse will validate that charm Python entrypoint calls ops.main
  • it is static type checker’s job to ensure correct arguments to ops.main
  • today, many charms do and have to do ops.main(ThisCharm) # type: ignore
  • thus, type hints need to be improved so that typpe: ignore can be dropped

Plan in this story:

  • upgrade pyright (not sure if strictly necessary, test: bump pyright to 1.1.377 #1332)
  • enabled pyright setting reportUnnecessaryTypeIgnoreComment
  • include code that calls ops.main(SomeCharm) in every which legal way in ops tests somewhere
    • pyright validates the positive case, that ops.main can be called with a charm class
  • include code that calls ops.main() without a charm class
    • pyright now validates that such invocation is detected as an error
    • thus, this invocation is annotated with # type: ignore or similar
    • with the setting above, pyright also enforce that the annotation is actually needed

Ref: "How to write negative type tests?" microsoft/pyright#8803

Part 2, based on #1332

MyPy checks, pinned mypy:

  • nginx-ingress-integrator-operator mypy 1.6.1 OK
  • sdcore-webui-operator mypy 1.11.1 OK

Super-tox, running on host (macos)

  • 58 charms pass against canonical/operator@main
  • 58 charms pass against dimaqq/aoperator@pyright-reportUnnecessaryTypeIgnoreComment

@benhoyt benhoyt changed the title Pyright report unnecessary type ignore comment ci: make Pyright report unnecessary type ignore comments Aug 25, 2024
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.

Similar to my comment on #1332, let's just ensure that removing these doesn't mess with charms that use MyPy for type checking.

Copy link
Contributor

@tonyandrewmeyer tonyandrewmeyer left a comment

Choose a reason for hiding this comment

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

Sorry, I'm not totally following these various PRs. Could you please adjust the description to make it clearer what the aim of this PR is?

@dimaqq
Copy link
Contributor Author

dimaqq commented Aug 26, 2024

I've updated the description.

@dimaqq dimaqq force-pushed the pyright-reportUnnecessaryTypeIgnoreComment branch from ebca0e6 to 0102307 Compare August 27, 2024 07:30
@dimaqq dimaqq force-pushed the pyright-reportUnnecessaryTypeIgnoreComment branch from 0102307 to 7cec1ef Compare August 28, 2024 04:01
@dimaqq dimaqq requested a review from benhoyt August 28, 2024 05:49
@dimaqq
Copy link
Contributor Author

dimaqq commented Aug 28, 2024

re failing o11y tests, it's an upstream issue, a test dep is not pinned:
canonical/prometheus-k8s-operator#638
canonical/alertmanager-k8s-operator#286

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 cleanup, thanks!

@dimaqq dimaqq merged commit 8bc7ad8 into canonical:main Aug 28, 2024
30 of 32 checks passed
@dimaqq dimaqq deleted the pyright-reportUnnecessaryTypeIgnoreComment branch August 28, 2024 21:49
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.

3 participants