-
-
Notifications
You must be signed in to change notification settings - Fork 421
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 annotation into untyped functions automatically #354
Conversation
pyproject.toml
Outdated
@@ -65,6 +67,8 @@ release = "python tasks/release.py" | |||
test = "pytest tests/" | |||
doc = {shell = "cd docs && mkdocs serve", help = "Start the dev server for doc preview"} | |||
lint = "pre-commit run --all-files" | |||
format = {shell = "black ./pdm ./tests && isort ./pdm ./tests && flake8 ./pdm ./tests"} | |||
typecheck = "mypy ./pdm ./tests" |
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.
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.
Not true, it turns out there are ~500 errors to fix, which is a huge amount
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.
It was actually blocking mypy.
After I excluded that directory -> and removed tests from mypy checking, it shows all errors correctly.
I first of all fixed "missing a type" errors in this PR.
It used to cause "missing a type" errors more than 50 functions, Now all errors of them are gone.
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.
Just a quick look, there must be many more untyped testing functions. But I don't see it necessary to annotate testing funcs, it doesn't seem conventional.
Oh I'm sorry for having you review many things. |
Sorry, I noticed that now. Imade mistake when applying, so I'm going to add more fix commit in this PR. |
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.
Too much to review, I suggest some of them, others should be similar
@ulwlu thanks for your effort in adding typing, but can we just leave This will dramatically reduce the work to review this PR. |
Reason: typing in tests is not required #354 (comment)
Added pyannotate when declaring typing into many defs, but it will not be used in the future.
Hi, I am sorry for causing you trouble by adding to many files. I removed typing from tests, and fixed the all codes with based on what you pointed out. I believed this would make the project more maintainable, and I found myself hooked into adding typing, but if there are parts you don't want, feel free to point out. |
@frostming I also wrote one question.
|
That is really huge, if you don't mind I will merge it to a temporary branch and do more modifications based on that. |
Sure, thank you very much. Since I see you start applying suggestions, I stop modifying here. |
Thank you, since this PR needs to be resolved first otherwise it will likely cause many merge conflicts. |
Reason: typing in tests is not required pdm-project/pdm#354 (comment)
Pull Request Check List
news/
describing what is new.Describe what you have changed in this PR
Remarks
I believe adding type annotations into all variables is anti-pattern.
It is because,
parent-to-child
. If you import type from other module, but that other module requires others, then it errors out.So, I only add typing into functions.
How to use pyannotate
pyannotate is made by Guido and his team in dropbox. It's easy and powerful to use compared to monkeytype by instagram because monkeytype doesn't support pytest integration officially
Add below lines into tests/conftest.py. (I don't add this code in this PR, because I think this requires only this time.)
Then run
pytest
.It generates the typing informations of all functions what pytest run through into type_info.json.
It is based on sys.setprofile.
When you want to add typing into actual code, run below.
The code will have typing automatically.