-
Notifications
You must be signed in to change notification settings - Fork 123
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
fix: use mypy
pre-commit in local environment
#1966
Conversation
i like the look of this, thanks for doing it it looks like this fails in pre-commit-ci, so we may need to find another way of running it in ci? (i'm not averse to removing pre-commit-ci) |
Thanks @MarcoGorelli ! β€οΈ This could be a possible approach that doesn't change super much what we currently have:
The errors are now showing up in the CI! Happy to hear your thoughts (also @FBruzzesi and @dangotbanned ) |
nice, happy to go with this - if we can get it green and then gradually address things, happy to get this in |
This comment was marked as outdated.
This comment was marked as outdated.
narwhals/_duckdb/dataframe.py
Outdated
@@ -159,7 +159,7 @@ def select( | |||
): | |||
return self._from_native_frame( | |||
self._native_frame.aggregate( | |||
[val.alias(col) for col, val in new_columns_map.items()] | |||
[val.alias(col) for col, val in new_columns_map.items()] # type: ignore[arg-type] |
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.
based on the duckdb stubs, only str
are allowed in .aggregate
. π€
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.
looks wrong, it should be str | list[Expression]
, right? want to make a PR to duckdb?
"narwhals[tests]", | ||
"narwhals[typing]", |
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 we should separate the dev dependencies into tests
and typing
.
The latest pinned mypy
is available for python >=3.9 and if we simply include it in dev
our python 3.8 tests will fail.
`DuckDBPyRelation.cross` isn't in the stubs
This comment was marked as resolved.
This comment was marked as resolved.
The last warning seems legit to me https://github.com/narwhals-dev/narwhals/actions/runs/13240255809/job/36953842381?pr=1966 Both uses of narwhals/narwhals/_pandas_like/series.py Lines 1057 to 1067 in 4b1d778
I don't see any tests covering The one @camriddell just wanted to run this by you following #1859 - feel like I must be missing something UpdateResolved in (fd192f2) This code provides the narrowing at runtime. Lines 2591 to 2601 in 60e5705
|
- The real solution would be simplifying the control flow - There's too much going on here, but `nw.Series` has mutually exclusive logic that prevents the bug narwhals-dev#1966 (comment)
``` Argument of type "Hashable | None" cannot be assigned to parameter "name" of type "str" in function "alias" Β Β Type "Hashable | None" is not assignable to type "str" Β Β Β Β "Hashable" is not assignable to "str" ```
@MarcoGorelli I'm reasonably happy with where the typing is at after (#1966 (commits)) Of these modules, Will try to look into those after this and #1979 have merged |
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.
mypy
pre-commit in local environmentmypy
pre-commit in local environment
@dangotbanned seems like you resolved everything there, thanks! If it is useful to you in a post-hoc sense Lines 2591 to 2601 in 60e5705
The high-level
I decided to split broad smoke-tests into 2 separate functions:
Thanks for resolving all of these typing issue. In the future, it could be worth refactoring these two behaviors into separate functions for each backend and dispatch the correct call from the |
What type of PR is this? (check all applicable)
Related issues
mypy
passing withpyarrow-stubs
installedΒ #1961Checklist
If you have comments or can explain your changes, please do so below
I did some digging, looking for how other projects run typing and general best practices with
mypy
.One thing people seem to agree with is that
mirrors-mypy
has its gotchas and may not be ideal for every project.In our case we would need to add every backend dependencies as
additional-dependencies
. In this case we would have to maintain a script that keep those dependencies up to date.One alternative would be to run mypy in the local environment where all the dependencies are already installed. This is what this PR is trying to do.
I have still some open questions, making this draft to test the CI too.~I am expecting to see
300 errors frommypy
πUpdate: I propose to move to this solution where we:
pre-commit
for linting but movemypy
to run in the local env -> this is to avoid having to add manyadditional-dependencies
make typing
mypy
in a separate CI pipeline on the entire code