-
Notifications
You must be signed in to change notification settings - Fork 629
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
Add type checker #3116
base: main
Are you sure you want to change the base?
Add type checker #3116
Conversation
@@ -1,6 +1,7 @@ | |||
pylint==3.0.2 | |||
httpretty==1.1.4 | |||
mypy==0.931 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be removed. I didn't because I don't know who is using it...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there's no usage on this repo. But we are using mypy in core + a basic setup of pyright with typeCheckingMode off.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I started with this instrumentation because it was the easiest I found to prove that the setup works.
…thon-contrib into add-type-checker
I don't have any preference but I think you missed that we are using mypy in opentelemetry-python |
@@ -963,3 +963,13 @@ deps = | |||
pre-commit | |||
commands = | |||
pre-commit run --color=always --all-files {posargs} | |||
|
|||
[testenv:typecheck] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I would say we can use the name of the tool here, like mypy or pyright. For example: .github/workflows/misc_0.yml
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But... The lint
jobs only run pylint
, and the test
jobs run pytest
. 😅
I was checking opentelemetry-python, and it seems that pyright is also present there? A bit more into it... Seems like if |
I took some time trying to set up mypy to see how that would look like, and it just took too much of my time, and I was not able to make it work properly... I'm happy to close this if people are strong on mypy, but I'm not willing to spend more time trying it. |
I think the mypy setup on It would be great if people could share opinions on this, I want to continue adding type hints, but without regressions. |
This PR adds type checker to
tox
.PyRight Vs MyPy
There's a lot of discussion around about which one to use. I don't think it matters much which one to choose. There are points where Python itself is not specific, and then the type checkers have freedom to choose the behavior they want... Example:
mypy
: On strict mode, you need to add-> None
on the return statement.pyright
: infers that isNone
, so you don't need to add-> None
.PyRight is easier for VSCode users, me included... 👀
About the ecosystem... I think most of them use mypy, but Pydantic for example, uses PyRight.
If you look at the projects I maintain (starlette, uvicorn), I use mypy on them, but I have to say that is a bit more practical to have the type checker match my IDE.
Anyway... I hope this is not an issue, and we can start with this setup.