-
-
Notifications
You must be signed in to change notification settings - Fork 143
CI: check for some unused ignore comments #213
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
Changes from all commits
59a0379
e084859
9dcc7a5
e3e0456
fac6825
5456976
15254cb
bbea9e9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,28 @@ | ||
from __future__ import annotations | ||
|
||
from typing import ( | ||
TYPE_CHECKING, | ||
Final, | ||
) | ||
|
||
def check( | ||
actual: object, klass: type, dtype: type | None = None, attr: str = "left" | ||
) -> None: | ||
from pandas._typing import T | ||
|
||
TYPE_CHECKING_INVALID_USAGE: Final = TYPE_CHECKING | ||
|
||
|
||
def check(actual: T, klass: type, dtype: type | None = None, attr: str = "left") -> T: | ||
|
||
if not isinstance(actual, klass): | ||
raise RuntimeError(f"Expected type '{klass}' but got '{type(actual)}'") | ||
if dtype is None: | ||
return None | ||
return actual # type: ignore[return-value] | ||
|
||
if hasattr(actual, "__iter__"): | ||
value = next(iter(actual)) # type: ignore[call-overload] | ||
else: | ||
assert hasattr(actual, attr) | ||
value = getattr(actual, attr) # type: ignore[attr-defined] | ||
value = getattr(actual, attr) | ||
|
||
if not isinstance(value, dtype): | ||
raise RuntimeError(f"Expected type '{dtype}' but got '{type(value)}'") | ||
return None | ||
return actual # type: ignore[return-value] |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1139,20 +1139,51 @@ def test_types_regressions() -> None: | |
|
||
|
||
def test_read_csv() -> None: | ||
if TYPE_CHECKING: # skip pytest | ||
# https://github.com/microsoft/python-type-stubs/issues/87 | ||
df11: pd.DataFrame = pd.read_csv("foo") | ||
df12: pd.DataFrame = pd.read_csv("foo", iterator=False) | ||
df13: pd.DataFrame = pd.read_csv("foo", iterator=False, chunksize=None) | ||
df14: TextFileReader = pd.read_csv("foo", chunksize=0) | ||
df15: TextFileReader = pd.read_csv("foo", iterator=False, chunksize=0) | ||
df16: TextFileReader = pd.read_csv("foo", iterator=True) | ||
df17: TextFileReader = pd.read_csv("foo", iterator=True, chunksize=None) | ||
df18: TextFileReader = pd.read_csv("foo", iterator=True, chunksize=0) | ||
df19: TextFileReader = pd.read_csv("foo", chunksize=0) | ||
with ensure_clean() as path: | ||
Path(path).write_text("A,B\n1,2") | ||
check(assert_type(pd.read_csv(path), pd.DataFrame), pd.DataFrame) | ||
check( | ||
assert_type(pd.read_csv(path, iterator=False), pd.DataFrame), pd.DataFrame | ||
) | ||
check( | ||
assert_type( | ||
pd.read_csv(path, iterator=False, chunksize=None), pd.DataFrame | ||
), | ||
pd.DataFrame, | ||
) | ||
|
||
with check( | ||
assert_type(pd.read_csv(path, chunksize=1), TextFileReader), TextFileReader | ||
): | ||
pass | ||
with check( | ||
assert_type(pd.read_csv(path, iterator=False, chunksize=1), TextFileReader), | ||
TextFileReader, | ||
): | ||
pass | ||
with check( | ||
assert_type(pd.read_csv(path, iterator=True), TextFileReader), | ||
TextFileReader, | ||
): | ||
pass | ||
with check( | ||
assert_type( | ||
pd.read_csv(path, iterator=True, chunksize=None), TextFileReader | ||
), | ||
TextFileReader, | ||
): | ||
pass | ||
with check( | ||
assert_type(pd.read_csv(path, iterator=True, chunksize=1), TextFileReader), | ||
TextFileReader, | ||
): | ||
pass | ||
|
||
# https://github.com/microsoft/python-type-stubs/issues/118 | ||
pd.read_csv("foo", storage_options=None) | ||
check( | ||
assert_type(pd.read_csv(path, storage_options=None), pd.DataFrame), | ||
pd.DataFrame, | ||
) | ||
|
||
|
||
def test_groupby_series_methods() -> None: | ||
|
@@ -1358,6 +1389,7 @@ def test_set_columns() -> None: | |
df = pd.DataFrame({"a": [1, 2, 3], "b": [0.0, 1, 1]}) | ||
# Next line should work, but it is a mypy bug | ||
# https://github.com/python/mypy/issues/3004 | ||
# pyright doesn't need the ignore | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is almost the only ignore in the tests that is not needed by pyright (there are many in the stubs that are not "needed"). The other two ignores are in If pyright had no unnecessary ignore comments in the tests, we could have a second pyright config for the installed stub check (it only checks the tests using the stubs, but not the stubs). |
||
df.columns = ["c", "d"] # type: ignore[assignment] | ||
|
||
|
||
|
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.
Sounds like a mypy error to me: I think it is of type object because of the instance call where class is just type without a specification which type. Might fallback to object.
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.
Opened python/mypy#13462