-
-
Notifications
You must be signed in to change notification settings - Fork 129
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
CI: enable a few more mypy checks #60
Conversation
The goal of those tests are code that would raise an |
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.
As I wrote here: #60 (comment) I'm hesitant to make these changes. We want to have tests that the type checker should pick up as being invalid code. Not sure if we change the stubs to make both mypy
and pyright
pick them up, or we leave the warn_unused_ignores
as it was.
Also, see discussion here: microsoft/pyright#2839
pyright
did add a feature reportUnnecessaryTypeIgnoreComment
as a result of that issue, and maybe you could experiment with that as well.
pyproject.toml
Outdated
# Miscellaneous strictness flags | ||
allow_untyped_globals = false | ||
allow_redefinition = false | ||
local_partial_types = false | ||
implicit_reexport = true | ||
implicit_reexport = false |
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.
Can you add comment here and with enable_error_code
that these are changes from pandas?
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.
implicit_reexport
is still true in pandas
tests/test_timefuncs.py
Outdated
@@ -175,6 +175,6 @@ def fail_on_adding_two_timestamps() -> None: | |||
s1 = pd.Series(pd.to_datetime(["2022-05-01", "2022-06-01"])) | |||
s2 = pd.Series(pd.to_datetime(["2022-05-15", "2022-06-15"])) | |||
if TYPE_CHECKING: | |||
ssum: pd.Series = s1 + s2 # type: ignore | |||
ssum: pd.Series = s1 + s2 |
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.
So this should have a # type: ignore
, because we should be picking up that this is not allowed, i.e., you can't add two series consisting of Timestamps.
tests/test_interval.py
Outdated
i1 + pd.Timestamp("2000-03-03") # type: ignore | ||
i1 * 3 # type: ignore | ||
i1 * pd.Timedelta(seconds=20) # type: ignore | ||
20 in i1 |
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.
Removing this type: ignore
means we think this code is legal, but it shouldn't be. You can't check that an int
is contained inside of an Interval[Timestamp]
, so the type checker should pick that up.
I'm hesitant to make this change unless we can fix the stub to error out on this line.
I'm pretty sure at one point it did used to pick that up - not sure what changed.
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 it will take quite some effort to remove annotations like these
def __add__(self, other: TimestampSeries) -> TimestampSeries: ...
def __add__(self, other: Timestamp) -> TimestampSeries: ..
but also allow legit combinations.
tests/test_interval.py
Outdated
pd.Timestamp("2001-01-02") in i2 # type: ignore | ||
i2 + pd.Timedelta(seconds=20) # type: ignore | ||
pd.Timestamp("2001-01-02") in i2 # pyright: ignore[reportGeneralTypeIssues] | ||
i2 + pd.Timedelta(seconds=20) # pyright: ignore[reportGeneralTypeIssues] |
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 is one of these cases where pyright
is correctly picking up the error, but mypy
is not.
Great, I wasn't aware that there are already negative test cases!
The current way of having the ignore comments but not checking whether they are needed, doesn't test these negative test cases. As you mentioned it would be good to also use pyright to check whether it needs the ignore comments. I will try to look into why mypy/pyright accept some of these negative tests. If we are not able to make mypy/pyright error on the negative tests, should we simply create an issue to keep track of these negative tests being accepted? |
Maybe we should move all of the negative tests to a separate test file, keep the ones (with the correct |
I will separate this PR into two PRs: w/wo |
It will be difficult to have mypy and pyright both reporting which ignores the don't need as mypy has no mypy-specific ignore comments (python/mypy#12358) but pyright does not need a lot of the ignores in the pandas-stubs itself:
|
Yes, and that creates the dilemma for us. We have to put in I'm presuming that this PR is not ready to be reviewed, given you said you'd split it into two. |
I think it should be ready to merge: I removed Personally, I think it would be an improvement to already enable |
Thanks @twoertwein |
Actually, I didn't add any negative tests. It turned out that using |
enable_error_code = "ignore-without-code"
)as
or in__all__
, pyright does the same,implicit_reexport
)warn_unused_ignores
)What is the goal of the tests inside
TYPE_CHECKING
? Is that for compatibility with older versions or are these placeholder for future "not-tests"?