Skip to content

TYP: Autotyping #48191

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 13 commits into from
Sep 8, 2022
2 changes: 1 addition & 1 deletion pandas/core/computation/engines.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def _is_aligned(self) -> bool:
return self.aligned_axes is not None and self.result_type is not None

@abc.abstractmethod
def _evaluate(self) -> None:
def _evaluate(self):
"""
Return an evaluated expression.

Expand Down
3 changes: 2 additions & 1 deletion pandas/core/dtypes/dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -675,8 +675,9 @@ class DatetimeTZDtype(PandasExtensionDtype):
def na_value(self) -> NaTType:
return NaT

# error: Signature of "str" incompatible with supertype "PandasExtensionDtype"
@cache_readonly
def str(self) -> str:
def str(self) -> str: # type: ignore[override]
return f"|M8[{self._unit}]"

def __init__(self, unit: str_type | DatetimeTZDtype = "ns", tz=None) -> None:
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/interchange/dataframe_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ class DataFrame(ABC):
version = 0 # version of the protocol

@abstractmethod
def __dataframe__(self, nan_as_null: bool = False, allow_copy: bool = True) -> None:
def __dataframe__(self, nan_as_null: bool = False, allow_copy: bool = True):
"""Construct a new interchange object, potentially changing the parameters."""
pass

Expand Down
4 changes: 3 additions & 1 deletion pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -1327,7 +1327,9 @@ def _maybe_update_cacher(
# ----------------------------------------------------------------------
# Unsorted

@property
# error: Cannot override final attribute "_is_mixed_type" (previously declared
# in base class "NDFrame")
@property # type: ignore[misc]
def _is_mixed_type(self) -> bool:
Copy link
Member Author

Choose a reason for hiding this comment

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

NDFrame declares _is_mixed_type as final! This method should not exist or the parent method should not be final.

Not sure why mypy didn't find this earlier.

Choose a reason for hiding this comment

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

Mypy generally doesn't check unannotated methods. It should probably still check @final though.

return False

Expand Down
94 changes: 47 additions & 47 deletions pandas/core/strings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,23 @@ def _str_getitem(self, key):
return self._str_get(key)

@abc.abstractmethod
def _str_count(self, pat, flags=0) -> None:
def _str_count(self, pat, flags=0):
pass

@abc.abstractmethod
def _str_pad(self, width, side="left", fillchar=" ") -> None:
def _str_pad(self, width, side="left", fillchar=" "):
pass

@abc.abstractmethod
def _str_contains(self, pat, case=True, flags=0, na=None, regex=True) -> None:
def _str_contains(self, pat, case=True, flags=0, na=None, regex=True):
pass

@abc.abstractmethod
def _str_startswith(self, pat, na=None) -> None:
def _str_startswith(self, pat, na=None):
pass

@abc.abstractmethod
def _str_endswith(self, pat, na=None) -> None:
def _str_endswith(self, pat, na=None):
pass

@abc.abstractmethod
Expand All @@ -64,17 +64,17 @@ def _str_replace(
case: bool = True,
flags: int = 0,
regex: bool = True,
) -> None:
):
pass

@abc.abstractmethod
def _str_repeat(self, repeats) -> None:
def _str_repeat(self, repeats):
pass

@abc.abstractmethod
def _str_match(
self, pat: str, case: bool = True, flags: int = 0, na: Scalar = np.nan
) -> None:
):
pass

@abc.abstractmethod
Expand All @@ -84,147 +84,147 @@ def _str_fullmatch(
case: bool = True,
flags: int = 0,
na: Scalar = np.nan,
) -> None:
):
pass

@abc.abstractmethod
def _str_encode(self, encoding, errors="strict") -> None:
def _str_encode(self, encoding, errors="strict"):
pass

@abc.abstractmethod
def _str_find(self, sub, start=0, end=None) -> None:
def _str_find(self, sub, start=0, end=None):
pass

@abc.abstractmethod
def _str_rfind(self, sub, start=0, end=None) -> None:
def _str_rfind(self, sub, start=0, end=None):
pass

@abc.abstractmethod
def _str_findall(self, pat, flags=0) -> None:
def _str_findall(self, pat, flags=0):
pass

@abc.abstractmethod
def _str_get(self, i) -> None:
def _str_get(self, i):
pass

@abc.abstractmethod
def _str_index(self, sub, start=0, end=None) -> None:
def _str_index(self, sub, start=0, end=None):
pass

@abc.abstractmethod
def _str_rindex(self, sub, start=0, end=None) -> None:
def _str_rindex(self, sub, start=0, end=None):
pass

@abc.abstractmethod
def _str_join(self, sep) -> None:
def _str_join(self, sep):
pass

@abc.abstractmethod
def _str_partition(self, sep, expand) -> None:
def _str_partition(self, sep, expand):
pass

@abc.abstractmethod
def _str_rpartition(self, sep, expand) -> None:
def _str_rpartition(self, sep, expand):
pass

@abc.abstractmethod
def _str_len(self) -> None:
def _str_len(self):
pass

@abc.abstractmethod
def _str_slice(self, start=None, stop=None, step=None) -> None:
def _str_slice(self, start=None, stop=None, step=None):
pass

@abc.abstractmethod
def _str_slice_replace(self, start=None, stop=None, repl=None) -> None:
def _str_slice_replace(self, start=None, stop=None, repl=None):
pass

@abc.abstractmethod
def _str_translate(self, table) -> None:
def _str_translate(self, table):
pass

@abc.abstractmethod
def _str_wrap(self, width, **kwargs) -> None:
def _str_wrap(self, width, **kwargs):
pass

@abc.abstractmethod
def _str_get_dummies(self, sep="|") -> None:
def _str_get_dummies(self, sep="|"):
pass

@abc.abstractmethod
def _str_isalnum(self) -> None:
def _str_isalnum(self):
pass

@abc.abstractmethod
def _str_isalpha(self) -> None:
def _str_isalpha(self):
pass

@abc.abstractmethod
def _str_isdecimal(self) -> None:
def _str_isdecimal(self):
pass

@abc.abstractmethod
def _str_isdigit(self) -> None:
def _str_isdigit(self):
pass

@abc.abstractmethod
def _str_islower(self) -> None:
def _str_islower(self):
pass

@abc.abstractmethod
def _str_isnumeric(self) -> None:
def _str_isnumeric(self):
pass

@abc.abstractmethod
def _str_isspace(self) -> None:
def _str_isspace(self):
pass

@abc.abstractmethod
def _str_istitle(self) -> None:
def _str_istitle(self):
pass

@abc.abstractmethod
def _str_isupper(self) -> None:
def _str_isupper(self):
pass

@abc.abstractmethod
def _str_capitalize(self) -> None:
def _str_capitalize(self):
pass

@abc.abstractmethod
def _str_casefold(self) -> None:
def _str_casefold(self):
pass

@abc.abstractmethod
def _str_title(self) -> None:
def _str_title(self):
pass

@abc.abstractmethod
def _str_swapcase(self) -> None:
def _str_swapcase(self):
pass

@abc.abstractmethod
def _str_lower(self) -> None:
def _str_lower(self):
pass

@abc.abstractmethod
def _str_upper(self) -> None:
def _str_upper(self):
pass

@abc.abstractmethod
def _str_normalize(self, form) -> None:
def _str_normalize(self, form):
pass

@abc.abstractmethod
def _str_strip(self, to_strip=None) -> None:
def _str_strip(self, to_strip=None):
pass

@abc.abstractmethod
def _str_lstrip(self, to_strip=None) -> None:
def _str_lstrip(self, to_strip=None):
pass

@abc.abstractmethod
def _str_rstrip(self, to_strip=None) -> None:
def _str_rstrip(self, to_strip=None):
pass

@abc.abstractmethod
Expand All @@ -236,13 +236,13 @@ def _str_removesuffix(self, suffix: str) -> Series:
pass

@abc.abstractmethod
def _str_split(self, pat=None, n=-1, expand=False) -> None:
def _str_split(self, pat=None, n=-1, expand=False):
pass

@abc.abstractmethod
def _str_rsplit(self, pat=None, n=-1) -> None:
def _str_rsplit(self, pat=None, n=-1):
pass

@abc.abstractmethod
def _str_extract(self, pat: str, flags: int = 0, expand: bool = True) -> None:
def _str_extract(self, pat: str, flags: int = 0, expand: bool = True):
pass
14 changes: 6 additions & 8 deletions pandas/io/excel/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -555,11 +555,11 @@ def __init__(

@property
@abc.abstractmethod
def _workbook_class(self) -> None:
def _workbook_class(self):
pass

@abc.abstractmethod
def load_workbook(self, filepath_or_buffer) -> None:
def load_workbook(self, filepath_or_buffer):
pass

def close(self) -> None:
Expand All @@ -581,17 +581,15 @@ def sheet_names(self) -> list[str]:
pass

@abc.abstractmethod
def get_sheet_by_name(self, name: str) -> None:
def get_sheet_by_name(self, name: str):
pass

@abc.abstractmethod
def get_sheet_by_index(self, index: int) -> None:
def get_sheet_by_index(self, index: int):
pass

@abc.abstractmethod
def get_sheet_data(
self, sheet, convert_float: bool, rows: int | None = None
) -> None:
def get_sheet_data(self, sheet, convert_float: bool, rows: int | None = None):
pass

def raise_if_bad_sheet_by_index(self, index: int) -> None:
Expand Down Expand Up @@ -1197,7 +1195,7 @@ def sheets(self) -> dict[str, Any]:

@property
@abc.abstractmethod
def book(self) -> None:
def book(self):
"""
Book instance. Class type will depend on the engine used.

Expand Down
2 changes: 1 addition & 1 deletion pandas/plotting/_matplotlib/boxplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ def _post_plot_logic(self, ax, data) -> None:
ax.set_ylabel(pprint_thing(self.ylabel))

@property
def orientation(self) -> str:
def orientation(self) -> Literal["horizontal", "vertical"]:
if self.kwds.get("vert", True):
return "vertical"
else:
Expand Down
4 changes: 2 additions & 2 deletions pandas/util/_test_decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,15 @@ def safe_import(mod_name: str, min_version: str | None = None):
return False


def _skip_if_no_mpl() -> bool:
def _skip_if_no_mpl():
mod = safe_import("matplotlib")
if mod:
mod.use("Agg")
else:
return True


def _skip_if_not_us_locale() -> bool:
def _skip_if_not_us_locale():
lang, _ = locale.getlocale()
if lang != "en_US":
return True
Expand Down