Skip to content

Commit

Permalink
Enable reportUnnecessaryTypeIgnoreComment (#487)
Browse files Browse the repository at this point in the history
* Enable reportUnnecessaryTypeIgnoreComment

* fix comments
  • Loading branch information
twoertwein authored Dec 29, 2022
1 parent ab1de1f commit 0b46778
Show file tree
Hide file tree
Showing 15 changed files with 77 additions and 93 deletions.
4 changes: 2 additions & 2 deletions pandas-stubs/_libs/interval.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -193,15 +193,15 @@ class Interval(IntervalMixin, Generic[_OrderableT]):
@overload
def __le__(self: IntervalT, other: IntervalIndex[IntervalT]) -> np_ndarray_bool: ...
@overload
def __eq__(self, other: Interval[_OrderableT]) -> bool: ... # type: ignore[misc]
def __eq__(self, other: Interval[_OrderableT]) -> bool: ... # type: ignore[misc] # pyright: ignore[reportOverlappingOverload]
@overload
def __eq__(self: IntervalT, other: IntervalIndex[IntervalT]) -> np_ndarray_bool: ... # type: ignore[misc]
@overload
def __eq__(self, other: Series[_OrderableT]) -> Series[bool]: ... # type: ignore[misc]
@overload
def __eq__(self, other: object) -> Literal[False]: ...
@overload
def __ne__(self, other: Interval[_OrderableT]) -> bool: ... # type: ignore[misc]
def __ne__(self, other: Interval[_OrderableT]) -> bool: ... # type: ignore[misc] # pyright: ignore[reportOverlappingOverload]
@overload
def __ne__(self: IntervalT, other: IntervalIndex[IntervalT]) -> np_ndarray_bool: ... # type: ignore[misc]
@overload
Expand Down
4 changes: 2 additions & 2 deletions pandas-stubs/_libs/tslibs/period.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class Period(PeriodMixin):
# ignore[misc] here because we know all other comparisons
# are False, so we use Literal[False]
@overload
def __eq__(self, other: Period) -> bool: ... # type: ignore[misc]
def __eq__(self, other: Period) -> bool: ... # type: ignore[misc] # pyright: ignore[reportOverlappingOverload]
@overload
def __eq__(self, other: PeriodIndex) -> npt.NDArray[np.bool_]: ... # type: ignore[misc]
@overload
Expand Down Expand Up @@ -131,7 +131,7 @@ class Period(PeriodMixin):
# ignore[misc] here because we know all other comparisons
# are False, so we use Literal[False]
@overload
def __ne__(self, other: Period) -> bool: ... # type: ignore[misc]
def __ne__(self, other: Period) -> bool: ... # type: ignore[misc] # pyright: ignore[reportOverlappingOverload]
@overload
def __ne__(self, other: PeriodIndex) -> npt.NDArray[np.bool_]: ... # type: ignore[misc]
@overload
Expand Down
4 changes: 2 additions & 2 deletions pandas-stubs/_libs/tslibs/timedeltas.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ class Timedelta(timedelta):
def __rtruediv__(self, other: timedelta | Timedelta | NaTType) -> float: ...
# Override due to more types supported than dt.timedelta
@overload
def __eq__(self, other: timedelta | Timedelta | np.timedelta64) -> bool: ... # type: ignore[misc]
def __eq__(self, other: timedelta | Timedelta | np.timedelta64) -> bool: ... # type: ignore[misc] # pyright: ignore[reportOverlappingOverload]
@overload
def __eq__(self, other: TimedeltaSeries | Series[pd.Timedelta]) -> Series[bool]: ... # type: ignore[misc]
@overload
Expand All @@ -323,7 +323,7 @@ class Timedelta(timedelta):
def __eq__(self, other: object) -> Literal[False]: ...
# Override due to more types supported than dt.timedelta
@overload
def __ne__(self, other: timedelta | Timedelta | np.timedelta64) -> bool: ... # type: ignore[misc]
def __ne__(self, other: timedelta | Timedelta | np.timedelta64) -> bool: ... # type: ignore[misc] # pyright: ignore[reportOverlappingOverload]
@overload
def __ne__(self, other: TimedeltaSeries | Series[pd.Timedelta]) -> Series[bool]: ... # type: ignore[misc]
@overload
Expand Down
4 changes: 2 additions & 2 deletions pandas-stubs/_libs/tslibs/timestamps.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -217,15 +217,15 @@ class Timestamp(datetime):
self, other: npt.NDArray[np.timedelta64]
) -> npt.NDArray[np.datetime64]: ...
@overload
def __eq__(self, other: Timestamp | datetime | np.datetime64) -> bool: ... # type: ignore[misc]
def __eq__(self, other: Timestamp | datetime | np.datetime64) -> bool: ... # type: ignore[misc] # pyright: ignore[reportOverlappingOverload]
@overload
def __eq__(self, other: TimestampSeries | Series[Timestamp]) -> Series[bool]: ... # type: ignore[misc]
@overload
def __eq__(self, other: npt.NDArray[np.datetime64] | Index) -> np_ndarray_bool: ... # type: ignore[misc]
@overload
def __eq__(self, other: object) -> Literal[False]: ...
@overload
def __ne__(self, other: Timestamp | datetime | np.datetime64) -> bool: ... # type: ignore[misc]
def __ne__(self, other: Timestamp | datetime | np.datetime64) -> bool: ... # type: ignore[misc] # pyright: ignore[reportOverlappingOverload]
@overload
def __ne__(self, other: TimestampSeries | Series[Timestamp]) -> Series[bool]: ... # type: ignore[misc]
@overload
Expand Down
2 changes: 1 addition & 1 deletion pandas-stubs/core/algorithms.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ from pandas._typing import (
# with extension types return the same type while standard type return ndarray

@overload
def unique(values: PeriodIndex) -> PeriodIndex: ... # type: ignore[misc]
def unique(values: PeriodIndex) -> PeriodIndex: ... # type: ignore[misc] # pyright: ignore[reportOverlappingOverload]
@overload
def unique(values: CategoricalIndex) -> CategoricalIndex: ... # type: ignore[misc]
@overload
Expand Down
5 changes: 2 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -171,17 +171,18 @@ strict_equality = true
show_error_context = false
show_column_numbers = false
show_error_codes = true
always_true = "IS_TYPE_CHECKER_MYPY"

[tool.pyright]
typeCheckingMode = "strict"
stubPath = "."
include = ["tests", "pandas-stubs"]
enableTypeIgnoreComments = false # use pyright-specific ignores
# disable subset of strict
reportInconsistentConstructor = false
reportMissingParameterType = false
reportMissingTypeArgument = false
reportMissingTypeStubs = false
reportUnnecessaryTypeIgnoreComment = true
reportUnknownArgumentType = false
reportUnusedExpression = false
reportUnknownLambdaType = false
Expand All @@ -193,5 +194,3 @@ reportUnusedVariable = false
reportPrivateUsage = false
# enable optional checks
reportMissingModuleSource = true
defineConstant = { IS_TYPE_CHECKER_MYPY = false }

1 change: 0 additions & 1 deletion tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
TYPE_CHECKING_INVALID_USAGE: Final = TYPE_CHECKING
WINDOWS = os.name == "nt" or "cygwin" in platform.system().lower()
PD_LTE_15 = Version(pd.__version__) < Version("1.5.999")
IS_TYPE_CHECKER_MYPY = True

lxml_skip = pytest.mark.skipif(
sys.version_info >= (3, 11), reason="lxml is not available for 3.11 yet"
Expand Down
10 changes: 1 addition & 9 deletions tests/test_dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,7 @@ def test_sparse_dtype() -> None:
check(assert_type(pd.SparseDtype(np.timedelta64), pd.SparseDtype), pd.SparseDtype)
check(assert_type(pd.SparseDtype("datetime64"), pd.SparseDtype), pd.SparseDtype)
check(assert_type(pd.SparseDtype(), pd.SparseDtype), pd.SparseDtype)
# pyright ignore because mypy does not like non-minimal unions, while pyright
# can't minimize to check
check(
assert_type(
s_dt.fill_value, # pyright: ignore[reportGeneralTypeIssues]
Union[Scalar, None],
),
int,
)
check(assert_type(s_dt.fill_value, Union[Scalar, None]), int)


def test_string_dtype() -> None:
Expand Down
32 changes: 15 additions & 17 deletions tests/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
from pandas._typing import Scalar

from tests import (
IS_TYPE_CHECKER_MYPY,
PD_LTE_15,
TYPE_CHECKING_INVALID_USAGE,
check,
Expand Down Expand Up @@ -981,7 +980,7 @@ def test_types_window() -> None:
df.expanding()
df.expanding(axis=1)
if TYPE_CHECKING_INVALID_USAGE:
df.expanding(axis=1, center=True) # type: ignore[call-arg]
df.expanding(axis=1, center=True) # type: ignore[call-arg] # pyright: ignore[reportGeneralTypeIssues]

df.rolling(2)
df.rolling(2, axis=1, center=True)
Expand Down Expand Up @@ -1780,18 +1779,17 @@ def test_set_columns() -> None:
# https://github.com/python/mypy/issues/3004
# pyright accepts this, so we only type check for pyright,
# and also test the code with pytest
if (TYPE_CHECKING and not IS_TYPE_CHECKER_MYPY) or not TYPE_CHECKING:
df.columns = ["c", "d"]
df.columns = [1, 2]
df.columns = [1, "a"]
df.columns = np.array([1, 2])
df.columns = pd.Series([1, 2])
df.columns = np.array([1, "a"])
df.columns = pd.Series([1, "a"])
df.columns = (1, 2)
df.columns = (1, "a")
if TYPE_CHECKING_INVALID_USAGE:
df.columns = "abc" # pyright: ignore[reportGeneralTypeIssues]
df.columns = ["c", "d"] # type: ignore[assignment]
df.columns = [1, 2] # type: ignore[assignment]
df.columns = [1, "a"] # type: ignore[assignment]
df.columns = np.array([1, 2]) # type: ignore[assignment]
df.columns = pd.Series([1, 2]) # type: ignore[assignment]
df.columns = np.array([1, "a"]) # type: ignore[assignment]
df.columns = pd.Series([1, "a"]) # type: ignore[assignment]
df.columns = (1, 2) # type: ignore[assignment]
df.columns = (1, "a") # type: ignore[assignment]
if TYPE_CHECKING_INVALID_USAGE:
df.columns = "abc" # type: ignore[assignment] # pyright: ignore[reportGeneralTypeIssues]


def test_frame_index_numpy() -> None:
Expand Down Expand Up @@ -1828,9 +1826,9 @@ def test_func(h: Hashable):
pass

if TYPE_CHECKING_INVALID_USAGE:
test_func(pd.DataFrame()) # type: ignore[arg-type]
test_func(pd.Series([], dtype=object)) # type: ignore[arg-type]
test_func(pd.Index([])) # type: ignore[arg-type]
test_func(pd.DataFrame()) # type: ignore[arg-type] # pyright: ignore[reportGeneralTypeIssues]
test_func(pd.Series([], dtype=object)) # type: ignore[arg-type] # pyright: ignore[reportGeneralTypeIssues]
test_func(pd.Index([])) # type: ignore[arg-type] # pyright: ignore[reportGeneralTypeIssues]


def test_columns_mixlist() -> None:
Expand Down
16 changes: 8 additions & 8 deletions tests/test_interval.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ def test_interval_length() -> None:

check(assert_type(idres, "pd.Interval[pd.Timestamp]"), pd.Interval, pd.Timestamp)
if TYPE_CHECKING_INVALID_USAGE:
20 in i1 # type: ignore[operator]
i1 + pd.Timestamp("2000-03-03") # type: ignore[operator]
i1 * 3 # type: ignore[operator]
i1 * pd.Timedelta(seconds=20) # type: ignore[operator]
20 in i1 # type: ignore[operator] # pyright: ignore[reportGeneralTypeIssues]
i1 + pd.Timestamp("2000-03-03") # type: ignore[operator] # pyright: ignore[reportGeneralTypeIssues]
i1 * 3 # type: ignore[operator] # pyright: ignore[reportGeneralTypeIssues]
i1 * pd.Timedelta(seconds=20) # type: ignore[operator] # pyright: ignore[reportGeneralTypeIssues]

i2 = pd.Interval(10, 20)
check(assert_type(i2.length, int), int)
Expand All @@ -69,8 +69,8 @@ def test_interval_length() -> None:
check(assert_type(i2 * 4.2, "pd.Interval[float]"), pd.Interval, float)

if TYPE_CHECKING_INVALID_USAGE:
pd.Timestamp("2001-01-02") in i2 # type: ignore[operator]
i2 + pd.Timedelta(seconds=20) # type: ignore[type-var]
pd.Timestamp("2001-01-02") in i2 # type: ignore[operator] # pyright: ignore[reportGeneralTypeIssues]
i2 + pd.Timedelta(seconds=20) # type: ignore[type-var] # pyright: ignore[reportGeneralTypeIssues]
i3 = pd.Interval(13.2, 19.5)
check(assert_type(i3.length, float), float)
check(assert_type(i3.left, float), float)
Expand All @@ -82,5 +82,5 @@ def test_interval_length() -> None:
check(assert_type(i3 + 3, "pd.Interval[float]"), pd.Interval, float)
check(assert_type(i3 * 3, "pd.Interval[float]"), pd.Interval, float)
if TYPE_CHECKING_INVALID_USAGE:
pd.Timestamp("2001-01-02") in i3 # type: ignore[operator]
i3 + pd.Timedelta(seconds=20) # type: ignore[operator]
pd.Timestamp("2001-01-02") in i3 # type: ignore[operator] # pyright: ignore[reportGeneralTypeIssues]
i3 + pd.Timedelta(seconds=20) # type: ignore[operator] # pyright: ignore[reportGeneralTypeIssues]
14 changes: 7 additions & 7 deletions tests/test_pandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -1208,24 +1208,24 @@ def test_merge_ordered() -> None:
rs,
left_on="left",
right_on="right",
left_by="left", # pyright: ignore
right_by="right", # pyright: ignore
left_by="left", # pyright: ignore[reportGeneralTypeIssues]
right_by="right", # pyright: ignore[reportGeneralTypeIssues]
)
pd.merge_ordered( # type: ignore[call-overload]
ls,
rf, # pyright: ignore
rf, # pyright: ignore[reportGeneralTypeIssues]
left_on="left",
right_on="b",
left_by="left", # pyright: ignore
right_by="b", # pyright: ignore
left_by="left", # pyright: ignore[reportGeneralTypeIssues]
right_by="b", # pyright: ignore[reportGeneralTypeIssues]
)
pd.merge_ordered( # type: ignore[call-overload]
lf,
rs,
left_on="a",
right_on="right",
left_by="a", # pyright: ignore
right_by="right", # pyright: ignore
left_by="a", # pyright: ignore[reportGeneralTypeIssues]
right_by="right", # pyright: ignore[reportGeneralTypeIssues]
)


Expand Down
58 changes: 27 additions & 31 deletions tests/test_scalars.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
from pandas._libs.tslibs.timedeltas import Components

from tests import (
IS_TYPE_CHECKER_MYPY,
PD_LTE_15,
TYPE_CHECKING_INVALID_USAGE,
check,
Expand Down Expand Up @@ -607,14 +606,14 @@ def test_timedelta_add_sub() -> None:
# TypeError: as_period, as_timestamp, as_datetime, as_date, as_datetime64,
# as_period_index, as_datetime_index, as_ndarray_dt64
if TYPE_CHECKING_INVALID_USAGE:
td - as_period # type: ignore[operator]
td - as_timestamp # type: ignore[operator]
td - as_datetime # type: ignore[operator]
td - as_date # type: ignore[operator]
td - as_datetime64 # type: ignore[operator]
td - as_period_index # type: ignore[operator]
td - as_datetime_index # type: ignore[operator]
td - as_ndarray_dt64 # type: ignore[operator]
td - as_period # type: ignore[operator] # pyright: ignore[reportGeneralTypeIssues]
td - as_timestamp # type: ignore[operator] # pyright: ignore[reportGeneralTypeIssues]
td - as_datetime # type: ignore[operator] # pyright: ignore[reportGeneralTypeIssues]
td - as_date # type: ignore[operator] # pyright: ignore[reportGeneralTypeIssues]
td - as_datetime64 # type: ignore[operator] # pyright: ignore[reportGeneralTypeIssues]
td - as_period_index # type: ignore[operator] # pyright: ignore[reportGeneralTypeIssues]
td - as_datetime_index # type: ignore[operator] # pyright: ignore[reportGeneralTypeIssues]
td - as_ndarray_dt64 # type: ignore[operator] # pyright: ignore[reportGeneralTypeIssues]

check(assert_type(td - td, pd.Timedelta), pd.Timedelta)
check(assert_type(td - as_dt_timedelta, pd.Timedelta), pd.Timedelta)
Expand Down Expand Up @@ -746,14 +745,14 @@ def test_timedelta_mul_div() -> None:
# TypeError: md_int, md_float, md_ndarray_intp, md_ndarray_float, mp_series_int,
# mp_series_float, md_int64_index, md_float_index
if TYPE_CHECKING_INVALID_USAGE:
md_int // td # type: ignore[operator]
md_float // td # type: ignore[operator]
md_ndarray_intp // td # type: ignore[operator]
md_ndarray_float // td # type: ignore[operator]
mp_series_int // td # type: ignore[operator]
md_series_float // td # type: ignore[operator]
md_int64_index // td # type: ignore[operator]
md_float_index // td # type: ignore[operator]
md_int // td # type: ignore[operator] # pyright: ignore[reportGeneralTypeIssues]
md_float // td # type: ignore[operator] # pyright: ignore[reportGeneralTypeIssues]
md_ndarray_intp // td # type: ignore[operator] # pyright: ignore[reportGeneralTypeIssues]
md_ndarray_float // td # type: ignore[operator] # pyright: ignore[reportGeneralTypeIssues]
mp_series_int // td # type: ignore[operator] # pyright: ignore[reportGeneralTypeIssues]
md_series_float // td # type: ignore[operator] # pyright: ignore[reportGeneralTypeIssues]
md_int64_index // td # type: ignore[operator] # pyright: ignore[reportGeneralTypeIssues]
md_float_index // td # type: ignore[operator] # pyright: ignore[reportGeneralTypeIssues]

check(assert_type(td / td, float), float)
check(assert_type(td / pd.NaT, float), float)
Expand All @@ -780,14 +779,14 @@ def test_timedelta_mul_div() -> None:
# TypeError: md_int, md_float, md_ndarray_intp, md_ndarray_float, mp_series_int,
# mp_series_float, md_int64_index, md_float_index
if TYPE_CHECKING_INVALID_USAGE:
md_int / td # type: ignore[operator]
md_float / td # type: ignore[operator]
md_ndarray_intp / td # type: ignore[operator]
md_ndarray_float / td # type: ignore[operator]
mp_series_int / td # type: ignore[operator]
md_series_float / td # type: ignore[operator]
md_int64_index / td # type: ignore[operator]
md_float_index / td # type: ignore[operator]
md_int / td # type: ignore[operator] # pyright: ignore[reportGeneralTypeIssues]
md_float / td # type: ignore[operator] # pyright: ignore[reportGeneralTypeIssues]
md_ndarray_intp / td # type: ignore[operator] # pyright: ignore[reportGeneralTypeIssues]
md_ndarray_float / td # type: ignore[operator] # pyright: ignore[reportGeneralTypeIssues]
mp_series_int / td # type: ignore[operator] # pyright: ignore[reportGeneralTypeIssues]
md_series_float / td # type: ignore[operator] # pyright: ignore[reportGeneralTypeIssues]
md_int64_index / td # type: ignore[operator] # pyright: ignore[reportGeneralTypeIssues]
md_float_index / td # type: ignore[operator] # pyright: ignore[reportGeneralTypeIssues]


def test_timedelta_mod_abs_unary() -> None:
Expand Down Expand Up @@ -826,12 +825,9 @@ def test_timedelta_mod_abs_unary() -> None:
pd.TimedeltaIndex,
)

if TYPE_CHECKING and IS_TYPE_CHECKER_MYPY:
# mypy reports dt.timedelta, even though __abs__ returns Timedelta
check(assert_type(abs(td), pd.Timedelta), pd.Timedelta) # type: ignore[assert-type]
else:
# This is valid for pyright
check(assert_type(abs(td), pd.Timedelta), pd.Timedelta)
# mypy reports dt.timedelta, even though __abs__ returns Timedelta
check(assert_type(abs(td), pd.Timedelta), pd.Timedelta) # type: ignore[assert-type]

check(assert_type(td.__abs__(), pd.Timedelta), pd.Timedelta)
check(assert_type(-td, pd.Timedelta), pd.Timedelta)
check(assert_type(+td, pd.Timedelta), pd.Timedelta)
Expand Down
6 changes: 3 additions & 3 deletions tests/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ def test_types_sort_values() -> None:
s = pd.Series([4, 2, 1, 3])
check(assert_type(s.sort_values(), pd.Series), pd.Series)
if TYPE_CHECKING_INVALID_USAGE:
check(assert_type(s.sort_values(0), pd.Series), pd.Series) # type: ignore[assert-type,call-overload]
check(assert_type(s.sort_values(0), pd.Series), pd.Series) # type: ignore[assert-type,call-overload] # pyright: ignore[reportGeneralTypeIssues]
check(assert_type(s.sort_values(axis=0), pd.Series), pd.Series)
check(assert_type(s.sort_values(ascending=False), pd.Series), pd.Series)
assert assert_type(s.sort_values(inplace=True, kind="quicksort"), None) is None
Expand Down Expand Up @@ -560,7 +560,7 @@ def test_types_window() -> None:
s.expanding()
s.expanding(axis=0)
if TYPE_CHECKING_INVALID_USAGE:
s.expanding(axis=0, center=True) # type: ignore[call-arg]
s.expanding(axis=0, center=True) # type: ignore[call-arg] # pyright: ignore[reportGeneralTypeIssues]

s.rolling(2)
s.rolling(2, axis=0, center=True)
Expand Down Expand Up @@ -748,7 +748,7 @@ def add1(x: int) -> int:
s6: None = pd.Series([1, 2, 3]).rename("A", inplace=True)

if TYPE_CHECKING_INVALID_USAGE:
s7 = pd.Series([1, 2, 3]).rename({1: [3, 4, 5]}) # type: ignore[dict-item]
s7 = pd.Series([1, 2, 3]).rename({1: [3, 4, 5]}) # type: ignore[dict-item] # pyright: ignore[reportGeneralTypeIssues]


def test_types_ne() -> None:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def test_types_assert_series_equal() -> None:
check_datetimelike_compat=True,
)
if TYPE_CHECKING_INVALID_USAGE:
assert_series_equal( # type: ignore[call-overload]
assert_series_equal( # type: ignore[call-overload] # pyright: ignore[reportGeneralTypeIssues]
s1,
s2,
check_dtype=True,
Expand Down
Loading

0 comments on commit 0b46778

Please sign in to comment.