Skip to content

CI: Upgrade mypy to 0.990 #49626

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 4 commits into from
Nov 16, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v2.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ If installed, we now require:
+-----------------+-----------------+----------+---------+
| Package | Minimum Version | Required | Changed |
+=================+=================+==========+=========+
| mypy (dev) | 0.981 | | X |
| mypy (dev) | 0.990 | | X |
+-----------------+-----------------+----------+---------+
| python-dateutil | 2.8.2 | X | X |
+-----------------+-----------------+----------+---------+
Expand Down
2 changes: 1 addition & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ dependencies:
- flake8=5.0.4
- flake8-bugbear=22.7.1 # used by flake8, find likely bugs
- isort>=5.2.1 # check that imports are in the right order
- mypy=0.981
- mypy=0.990
- pre-commit>=2.15.0
- pycodestyle # used by flake8
- pyupgrade
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ def agg_dict_like(self) -> DataFrame | Series:

axis: AxisInt = 0 if isinstance(obj, ABCSeries) else 1
result = concat(
{k: results[k] for k in keys_to_use}, # type: ignore[misc]
{k: results[k] for k in keys_to_use},
axis=axis,
keys=keys_to_use,
)
Expand Down
6 changes: 4 additions & 2 deletions pandas/core/arrays/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1646,10 +1646,12 @@ def __array_ufunc__(self, ufunc: np.ufunc, method: str, *inputs, **kwargs):


class ExtensionArraySupportsAnyAll(ExtensionArray):
def any(self, *, skipna: bool = True) -> bool:
def any(self, *, skipna: bool = True) -> bool: # type: ignore[empty-body]
Copy link
Member

Choose a reason for hiding this comment

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

Another option I think is to make these abstract methods - I haven't checked if that's viable, and maybe not something you'd want to handle here.

Copy link
Member Author

Choose a reason for hiding this comment

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

Would be ok with doing that, but would like to keep things separated

# error: Missing return statement
pass

def all(self, *, skipna: bool = True) -> bool:
def all(self, *, skipna: bool = True) -> bool: # type: ignore[empty-body]
# error: Missing return statement
pass


Expand Down
4 changes: 1 addition & 3 deletions pandas/core/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1112,9 +1112,7 @@ def _memory_usage(self, deep: bool = False) -> int:
are not components of the array if deep=False or if used on PyPy
"""
if hasattr(self.array, "memory_usage"):
# https://github.com/python/mypy/issues/1424
# error: "ExtensionArray" has no attribute "memory_usage"
return self.array.memory_usage(deep=deep) # type: ignore[attr-defined]
return self.array.memory_usage(deep=deep)

v = self.array.nbytes
if deep and is_object_dtype(self) and not PYPY:
Expand Down
12 changes: 5 additions & 7 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -5446,9 +5446,8 @@ def fillna(
) -> DataFrame | None:
...

# error: Signature of "fillna" incompatible with supertype "NDFrame"
@doc(NDFrame.fillna, **_shared_doc_kwargs)
def fillna( # type: ignore[override]
def fillna(
self,
value: Hashable | Mapping | Series | DataFrame = None,
*,
Expand Down Expand Up @@ -5537,9 +5536,8 @@ def replace(
) -> None:
...

# error: Signature of "replace" incompatible with supertype "NDFrame"
@doc(NDFrame.replace, **_shared_doc_kwargs)
def replace( # type: ignore[override]
def replace(
self,
to_replace=None,
value=lib.no_default,
Expand Down Expand Up @@ -6684,10 +6682,9 @@ def sort_values(
...

# TODO: Just move the sort_values doc here.
# error: Signature of "sort_values" incompatible with supertype "NDFrame"
@Substitution(**_shared_doc_kwargs)
@Appender(NDFrame.sort_values.__doc__)
def sort_values( # type: ignore[override]
def sort_values(
self,
by: IndexLabel,
*,
Expand Down Expand Up @@ -9204,8 +9201,9 @@ def any(
) -> DataFrame | Series:
...

# error: Missing return statement
@doc(NDFrame.any, **_shared_doc_kwargs)
def any(
def any( # type: ignore[empty-body]
self,
axis: Axis = 0,
bool_only: bool | None = None,
Expand Down
3 changes: 2 additions & 1 deletion pandas/core/interchange/column.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,11 @@ def __init__(self, column: pd.Series, allow_copy: bool = True) -> None:
self._col = column
self._allow_copy = allow_copy

def size(self) -> int:
def size(self) -> int: # type: ignore[override]
"""
Size of the column, in elements.
"""
# error: Signature of "size" incompatible with supertype "Column" [override]
return self._col.size

@property
Expand Down
18 changes: 6 additions & 12 deletions pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -1655,14 +1655,9 @@ def to_string(
return result
else:
if hasattr(buf, "write"):
# error: Item "str" of "Union[str, PathLike[str], WriteBuffer
# [str]]" has no attribute "write"
buf.write(result) # type: ignore[union-attr]
buf.write(result)
else:
# error: Argument 1 to "open" has incompatible type "Union[str,
# PathLike[str], WriteBuffer[str]]"; expected "Union[Union[str,
# bytes, PathLike[str], PathLike[bytes]], int]"
with open(buf, "w") as f: # type: ignore[arg-type]
with open(buf, "w") as f:
f.write(result)
return None

Expand Down Expand Up @@ -4447,8 +4442,9 @@ def any(
) -> Series | bool:
...

# error: Missing return statement
@doc(NDFrame.any, **_shared_doc_kwargs)
def any(
def any( # type: ignore[empty-body]
self,
axis: Axis = 0,
bool_only: bool | None = None,
Expand Down Expand Up @@ -5061,9 +5057,8 @@ def fillna(
) -> Series | None:
...

# error: Signature of "fillna" incompatible with supertype "NDFrame"
@doc(NDFrame.fillna, **_shared_doc_kwargs)
def fillna( # type: ignore[override]
def fillna(
self,
value: Hashable | Mapping | Series | DataFrame = None,
*,
Expand Down Expand Up @@ -5136,14 +5131,13 @@ def replace(
) -> None:
...

# error: Signature of "replace" incompatible with supertype "NDFrame"
@doc(
NDFrame.replace,
klass=_shared_doc_kwargs["klass"],
inplace=_shared_doc_kwargs["inplace"],
replace_iloc=_shared_doc_kwargs["replace_iloc"],
)
def replace( # type: ignore[override]
def replace(
self,
to_replace=None,
value=lib.no_default,
Expand Down
6 changes: 2 additions & 4 deletions pandas/io/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -1053,8 +1053,7 @@ def __getattr__(self, name: str):

def readable(self) -> bool:
if hasattr(self.buffer, "readable"):
# error: "BaseBuffer" has no attribute "readable"
return self.buffer.readable() # type: ignore[attr-defined]
return self.buffer.readable()
return True

def seekable(self) -> bool:
Expand All @@ -1064,8 +1063,7 @@ def seekable(self) -> bool:

def writable(self) -> bool:
if hasattr(self.buffer, "writable"):
# error: "BaseBuffer" has no attribute "writable"
return self.buffer.writable() # type: ignore[attr-defined]
return self.buffer.writable()
return True


Expand Down
3 changes: 1 addition & 2 deletions pandas/plotting/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1835,8 +1835,7 @@ def _load_backend(backend: str) -> types.ModuleType:
# entry_points lost dict API ~ PY 3.10
# https://github.com/python/importlib_metadata/issues/298
if hasattr(eps, "select"):
# error: "Dict[str, Tuple[EntryPoint, ...]]" has no attribute "select"
entry = eps.select(group=key) # type: ignore[attr-defined]
entry = eps.select(group=key)
else:
entry = eps.get(key, ())
for entry_point in entry:
Expand Down
8 changes: 1 addition & 7 deletions pandas/util/_decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,13 +397,7 @@ def decorator(decorated: F) -> F:
if docstring is None:
continue
if hasattr(docstring, "_docstring_components"):
# error: Item "str" of "Union[str, Callable[..., Any]]" has no attribute
# "_docstring_components"
# error: Item "function" of "Union[str, Callable[..., Any]]" has no
# attribute "_docstring_components"
docstring_components.extend(
docstring._docstring_components # type: ignore[union-attr]
)
docstring_components.extend(docstring._docstring_components)
elif isinstance(docstring, str) or docstring.__doc__:
docstring_components.append(docstring)

Expand Down
2 changes: 1 addition & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ cpplint
flake8==5.0.4
flake8-bugbear==22.7.1
isort>=5.2.1
mypy==0.981
mypy==0.990
pre-commit>=2.15.0
pycodestyle
pyupgrade
Expand Down