Skip to content

Fix types, run typechecker in CI #1393

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

Merged
merged 22 commits into from
Nov 28, 2023
Merged

Fix types, run typechecker in CI #1393

merged 22 commits into from
Nov 28, 2023

Conversation

yorickvP
Copy link
Contributor

@yorickvP yorickvP commented Nov 21, 2023

I fell into a typing hole while setting up pyright-lsp. Nevertheless, I think these are good changes, mostly preventing some annoying crashes (ast_openapi_scha + bytes defaults, cpus being uncountable).

Fixes #1360

@technillogue
Copy link
Contributor

@yorickvP
Copy link
Contributor Author

mypy finds largely the same errors. But lsp-pyright is really good. I can optionally add a tool.pyright section with some config.

extra stuff found by mypy (mostly untyped defs):

python/cog/command/ast_openapi_schema.py:9: error: Function "unparse" could always be true in boolean context  [truthy-function]
python/cog/command/ast_openapi_schema.py:12: error: Incompatible types in assignment (expression has type "Callable[[object], str]", variable has type "Callable[[AST], str]")  [assignment]
python/cog/types.py:264: error: Function is missing a type annotation for one or more arguments  [no-untyped-def]
python/cog/types.py:268: error: Function is missing a type annotation for one or more arguments  [no-untyped-def]
python/cog/server/http.py:77: error: Unsupported dynamic base class "schema.PredictionRequest.with_types"  [misc]
Found 5 errors in 3 files (checked 23 source files)

@yorickvP yorickvP force-pushed the yorickvp/pyright-validate branch from 6800f9d to a1d1130 Compare November 22, 2023 11:11
@yorickvP yorickvP changed the title Fix bugs, make typechecker (pyright) happy Fix types, run typechecker in CI Nov 22, 2023
@yorickvP yorickvP force-pushed the yorickvp/pyright-validate branch 2 times, most recently from 5912594 to 6af971f Compare November 22, 2023 14:23
@@ -54,6 +55,21 @@ disallow_untyped_defs = true
no_implicit_optional = false
exclude = ["python/tests/"]

[tool.pyright]
Copy link
Member

Choose a reason for hiding this comment

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

Should we pick one of pyright or mypy and drop the other?

Copy link
Contributor

Choose a reason for hiding this comment

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

would agree, would kinda lean towards sticking to mypy rather than making changes. pylsp-mypy exists though I assume it's slower

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As a long-time mypy user, I like pyright more:

Notably pyright actually passes the pydantic stuff :)

Copy link
Contributor

Choose a reason for hiding this comment

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

...I've had check-untyped-defs on the entire time I've used mypy. but I have to agree that this is fairly compelling even if the javascript stuff is weird.

Copy link
Contributor

Choose a reason for hiding this comment

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

@yorickvP Thanks for the nudge. I just gave Pyright a look, and found it to be an improvement over mypy. I'd be very happy for us to adopt it across the board. (To that end, I just opened this PR in our Python client)

Comment on lines +89 to +90
class PredictionRequest(schema.PredictionRequest.with_types(input_type=InputType)):
pass
Copy link
Contributor

Choose a reason for hiding this comment

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

why?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

tldr this allows typingchecking PredictionRequest usage by pyright (still not mypy, though)

@yorickvP yorickvP force-pushed the yorickvp/pyright-validate branch from 721d32f to a2971ec Compare November 23, 2023 16:15
Signed-off-by: Yorick van Pelt <[email protected]>
Signed-off-by: Yorick van Pelt <[email protected]>
Signed-off-by: Yorick van Pelt <[email protected]>
Signed-off-by: Yorick van Pelt <[email protected]>
Signed-off-by: Yorick van Pelt <[email protected]>
Signed-off-by: Yorick van Pelt <[email protected]>
@yorickvP yorickvP force-pushed the yorickvp/pyright-validate branch from a2971ec to 2c8a65c Compare November 23, 2023 16:50
@nickstenning
Copy link
Contributor

Love it!

I'd like to request that if we go all in on pyright (which I fully support) then let's also get rid of all mypy references in the codebase (pyproject.toml/Makefile/etc.)

Copy link
Contributor

@nickstenning nickstenning left a comment

Choose a reason for hiding this comment

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

Modulo failing tests (I think we'll have to use "old" ways of defining union types for a while to support <3.10) this seems great, particularly the bit where we typecheck in CI!

Copy link
Contributor

@technillogue technillogue left a comment

Choose a reason for hiding this comment

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

this PR probably shouldn't change async functionality

@yorickvP yorickvP force-pushed the yorickvp/pyright-validate branch from 982b2b8 to 9aca73b Compare November 24, 2023 12:43
Signed-off-by: Yorick van Pelt <[email protected]>
@yorickvP yorickvP merged commit 78caaa3 into main Nov 28, 2023
@yorickvP yorickvP deleted the yorickvp/pyright-validate branch November 28, 2023 14:13
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.

Support new python union syntax
5 participants