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

Configure Pyright #1246

Merged
merged 2 commits into from
May 22, 2024
Merged

Configure Pyright #1246

merged 2 commits into from
May 22, 2024

Conversation

victorlin
Copy link
Member

@victorlin victorlin commented Jun 29, 2023

Description of proposed changes

Add the necessary configuration including rule exceptions to make the linter run without error on the code as-is. This means the check is mostly useless except to prevent any violations of rules that aren't currently violated, but it allows for incremental adoption of rules rather than needing to address all violations at once.

List of exceptions determined using command:

npx pyright --outputjson \
| jq --raw-output '.generalDiagnostics.[] | .rule' \
| sort -u

Pyright supports some checks and type inference that Mypy does not¹.

¹ https://github.com/microsoft/pyright/blob/1.1.316/docs/mypy-comparison.md

Checklist

  • Pyright is run via Pytest in CI (evidence)
  • Checks pass
  • Add a message in CHANGES.md summarizing the changes in this PR that are end user focused. Keep headers and formatting consistent with the rest of the file. no functional changes
  • Post-merge: create issue to audit rule exceptions individually: Review Pyright rule exceptions #1472

@victorlin victorlin self-assigned this Jun 29, 2023
@victorlin victorlin force-pushed the victorlin/add-type-checking branch 2 times, most recently from 8c19b75 to 2a74460 Compare June 30, 2023 20:31
Base automatically changed from victorlin/add-type-checking to master June 30, 2023 20:57
@victorlin victorlin force-pushed the victorlin/use-pyright branch 2 times, most recently from 67b16d2 to 3469831 Compare July 3, 2023 20:05
@victorlin victorlin mentioned this pull request May 6, 2024
2 tasks
@jameshadfield
Copy link
Member

(1 year later - I must have missed this at the time)

I think this is a great direction to go in. My not-extensive understanding of type checking in python indicates pyright is preferred over mypy. It seems strange to me to use both typecheckers in the same project, but this seems to be rather common in python.

Copy link
Member Author

Choose a reason for hiding this comment

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

I've changed the direction of this PR from trying to address all violations to just setting up Pyright and ignoring violations explicitly. This reflects similar work done in nextstrain/nextstrain.org#778.

Here's commits from the old direction: 9e8c9e0...3469831 and new direction: fda57c5

@victorlin victorlin marked this pull request as ready for review May 17, 2024 00:51
@victorlin victorlin requested a review from a team May 17, 2024 00:51
docs/contribute/DEV_DOCS.md Outdated Show resolved Hide resolved
tests/test_pyright.py Show resolved Hide resolved
pyrightconfig.json Show resolved Hide resolved
Copy link
Contributor

@genehack genehack left a comment

Choose a reason for hiding this comment

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

Looks good; concur with James that we should add pyright as an explicit dev-dep.

Add the necessary configuration including rule exceptions to make the
linter run without error on the code as-is. This means the check is
mostly useless except to prevent any violations of rules that aren't
currently violated, but it allows for incremental adoption of rules
rather than needing to address all violations at once.

List of exceptions determined using command:

    npx pyright --outputjson \
    | jq --raw-output '.generalDiagnostics.[] | .rule' \
    | sort -u

Invocation via pytest mirrors that of mypy. Both were ported from
existing setup in Nextstrain CLI.¹

¹ <https://github.com/nextstrain/cli/blob/14a392eaf40f779a7ef9431bbe0a116e93d98580/doc/development.md?plain=1#L143>
I'm unsure why these don't show up locally on the same Pyright version.
They were flagged by CI so I'm adding them to the list from the previous
commit.
@victorlin victorlin mentioned this pull request May 17, 2024
@victorlin victorlin changed the title Add type checking (pyright) Configure Pyright May 17, 2024
Copy link
Contributor

@genehack genehack left a comment

Choose a reason for hiding this comment

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

good to go, yeah?

@victorlin victorlin merged commit 1694a3f into master May 22, 2024
20 checks passed
@victorlin victorlin deleted the victorlin/use-pyright branch May 22, 2024 17:10
@victorlin victorlin mentioned this pull request May 22, 2024
17 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

4 participants