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

dev: Add pyright as a pre-commit hook [WOR-1318] #29280

Merged
merged 1 commit into from
Oct 13, 2021
Merged

Conversation

ahmedetefy
Copy link
Contributor

@ahmedetefy ahmedetefy commented Oct 13, 2021

Adds Pyright as a pre-commit hook check for potential unbound variables, and all type checks are disabled given that we use mypy for that

Future Preventive measures against https://getsentry.atlassian.net/browse/INC-31
In my particular case, PyCharm linter usually alerts me when there is a potential unbound variable. However, in this case it didn't because the code block was wrapped in a context manager, and so adding Pyright to alert in the future against unbound local variables

Screenshot 2021-10-13 at 11 26 04

@ahmedetefy ahmedetefy requested review from a team as code owners October 13, 2021 09:17
@ahmedetefy ahmedetefy removed request for a team October 13, 2021 09:19
@ahmedetefy ahmedetefy marked this pull request as draft October 13, 2021 09:19
@ahmedetefy ahmedetefy changed the title dev: Add pyright as a pre-commit hook dev: Add pyright as a pre-commit hook [WOR-1318] Oct 13, 2021
@ahmedetefy ahmedetefy marked this pull request as ready for review October 13, 2021 09:33
@ahmedetefy ahmedetefy requested review from a team, wedamija and untitaker October 13, 2021 09:33
"src"
],

"exclude": [
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if .venv needs to be excluded as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Its excluded by default


"ignore": [],

"strictListInference": false,
Copy link
Member

Choose a reason for hiding this comment

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

We might have future rules to add to this list.

I personally would prefer if we only used pyright but I understand how they each might catch different set of problems.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Apparently there is a "typeCheckingMode" mode flag that can be set and suppresses all errors instead of setting all the rules statuses
It doesn't suppress warnings for some rules tho but just for two rules so I guess its better adding these two rules specifically so they don't show in warnings

"useLibraryCodeForTypes": false,

"pythonVersion": "3.6",
"pythonPlatform": "Linux"
Copy link
Member

Choose a reason for hiding this comment

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

What are the implications of these two last settings?
What happens when we move to Python 3.8? Does this work well on Mac OS?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What happens when we move to Python 3.8?

If a version is provided, pyright will generate errors if the source code makes use of language features that are not supported in that version.
I guess we can remove this, since we are using pyright only for un bound local variable inspection.

Does this work well on Mac OS?

Should be one of "Windows", "Darwin" or "Linux". If specified, pyright will tailor its use of type stub files, which conditionalize type definitions based on the platform. If no platform is specified, pyright will use the current platform.
I guess we could remove it here as well

Copy link
Member

@armenzg armenzg 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 looking into this!

Adds Pyright as a pre-commit hook check for
potential unbound variables
@wedamija
Copy link
Member

Nice, thanks for putting this check in place!

@@ -103,6 +103,7 @@
"prism-sentry": "^1.0.2",
"process": "^0.11.10",
"prop-types": "^15.6.0",
"pyright": "^1.1.178",
Copy link
Member

Choose a reason for hiding this comment

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

not that it matters much but should pyright be in devDependencies?

@github-actions github-actions bot locked and limited conversation to collaborators Oct 30, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants