Skip to content

TYP: annotation of __init__ return type (PEP 484) (pandas/tests) #46278

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
Mar 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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 pandas/tests/base/test_constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def bar(self, *args, **kwargs):
pass

class Delegate(PandasDelegate, PandasObject):
def __init__(self, obj):
def __init__(self, obj) -> None:
self.obj = obj

def test_invalid_delegation(self):
Expand Down
6 changes: 3 additions & 3 deletions pandas/tests/dtypes/test_inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class MockNumpyLikeArray:
a scalar (`is_scalar(np.array(1)) == False`), but it is not list-like either.
"""

def __init__(self, values):
def __init__(self, values) -> None:
self._values = values

def __iter__(self):
Expand Down Expand Up @@ -323,7 +323,7 @@ def test_is_dict_like_fails(ll):
@pytest.mark.parametrize("has_contains", [True, False])
def test_is_dict_like_duck_type(has_keys, has_getitem, has_contains):
class DictLike:
def __init__(self, d):
def __init__(self, d) -> None:
self.d = d

if has_keys:
Expand Down Expand Up @@ -1937,7 +1937,7 @@ def test_is_scalar_number(self):
# subclasses are.

class Numeric(Number):
def __init__(self, value):
def __init__(self, value) -> None:
self.value = value

def __int__(self):
Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/extension/arrow/arrays.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ def all(self, axis=0, out=None):


class ArrowBoolArray(ArrowExtensionArray):
def __init__(self, values):
def __init__(self, values) -> None:
if not isinstance(values, pa.ChunkedArray):
raise ValueError

Expand All @@ -189,7 +189,7 @@ def __init__(self, values):


class ArrowStringArray(ArrowExtensionArray):
def __init__(self, values):
def __init__(self, values) -> None:
if not isinstance(values, pa.ChunkedArray):
raise ValueError

Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/extension/arrow/test_timestamp.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def construct_array_type(cls) -> type_t[ArrowTimestampUSArray]:


class ArrowTimestampUSArray(ArrowExtensionArray):
def __init__(self, values):
def __init__(self, values) -> None:
if not isinstance(values, pa.ChunkedArray):
raise ValueError

Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/extension/decimal/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class DecimalDtype(ExtensionDtype):
na_value = decimal.Decimal("NaN")
_metadata = ("context",)

def __init__(self, context=None):
def __init__(self, context=None) -> None:
self.context = context or decimal.getcontext()

def __repr__(self) -> str:
Expand All @@ -66,7 +66,7 @@ def _is_numeric(self) -> bool:
class DecimalArray(OpsMixin, ExtensionScalarOpsMixin, ExtensionArray):
__array_priority__ = 1000

def __init__(self, values, dtype=None, copy=False, context=None):
def __init__(self, values, dtype=None, copy=False, context=None) -> None:
for i, val in enumerate(values):
if is_float(val):
if np.isnan(val):
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/extension/json/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class JSONArray(ExtensionArray):
dtype = JSONDtype()
__array_priority__ = 1000

def __init__(self, values, dtype=None, copy=False):
def __init__(self, values, dtype=None, copy=False) -> None:
for val in values:
if not isinstance(val, self.dtype.type):
raise TypeError("All values must be of type " + str(self.dtype.type))
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/extension/list/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class ListArray(ExtensionArray):
dtype = ListDtype()
__array_priority__ = 1000

def __init__(self, values, dtype=None, copy=False):
def __init__(self, values, dtype=None, copy=False) -> None:
if not isinstance(values, np.ndarray):
raise TypeError("Need to pass a numpy array as values")
for val in values:
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/extension/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class DummyDtype(dtypes.ExtensionDtype):


class DummyArray(ExtensionArray):
def __init__(self, data):
def __init__(self, data) -> None:
self.data = data

def __array__(self, dtype):
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/extension/test_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@


class MyEA(ExtensionArray):
def __init__(self, values):
def __init__(self, values) -> None:
self._values = values


Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/frame/constructors/test_from_records.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def test_from_records_bad_index_column(self):

def test_from_records_non_tuple(self):
class Record:
def __init__(self, *args):
def __init__(self, *args) -> None:
self.args = args

def __getitem__(self, i):
Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/frame/methods/test_select_dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
class DummyDtype(ExtensionDtype):
type = int

def __init__(self, numeric):
def __init__(self, numeric) -> None:
self._numeric = numeric

@property
Expand All @@ -28,7 +28,7 @@ def _is_numeric(self):


class DummyArray(ExtensionArray):
def __init__(self, data, dtype):
def __init__(self, data, dtype) -> None:
self.data = data
self._dtype = dtype

Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/frame/methods/test_set_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ def test_set_index_custom_label_type(self):
# GH#24969

class Thing:
def __init__(self, name, color):
def __init__(self, name, color) -> None:
self.name = name
self.color = color

Expand Down Expand Up @@ -673,7 +673,7 @@ def test_set_index_custom_label_type_raises(self):

# purposefully inherit from something unhashable
class Thing(set):
def __init__(self, name, color):
def __init__(self, name, color) -> None:
self.name = name
self.color = color

Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/frame/methods/test_to_records.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ def test_to_records_dtype_mi(self, df, kwargs, expected):
def test_to_records_dict_like(self):
# see GH#18146
class DictLike:
def __init__(self, **kwargs):
def __init__(self, **kwargs) -> None:
self.d = kwargs.copy()

def __getitem__(self, key):
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/frame/test_arithmetic.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def switch_numexpr_min_elements(request):


class DummyElement:
def __init__(self, value, dtype):
def __init__(self, value, dtype) -> None:
self.value = value
self.dtype = np.dtype(dtype)

Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/frame/test_constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -1363,7 +1363,7 @@ def test_constructor_sequence_like(self):
# collections.Sequence like

class DummyContainer(abc.Sequence):
def __init__(self, lst):
def __init__(self, lst) -> None:
self._lst = lst

def __getitem__(self, n):
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/frame/test_stack_unstack.py
Original file line number Diff line number Diff line change
Expand Up @@ -1861,7 +1861,7 @@ def test_unstack_number_of_levels_larger_than_int32(self, monkeypatch):
# GH 26314: Change ValueError to PerformanceWarning

class MockUnstacker(reshape_lib._Unstacker):
def __init__(self, *args, **kwargs):
def __init__(self, *args, **kwargs) -> None:
# __init__ will raise the warning
super().__init__(*args, **kwargs)
raise Exception("Don't compute final result.")
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/frame/test_subclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class CustomDataFrame(DataFrame):
custom plotting functions.
"""

def __init__(self, *args, **kw):
def __init__(self, *args, **kw) -> None:
super().__init__(*args, **kw)

@property
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/groupby/test_counting.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ class RaisingObjectException(Exception):
pass

class RaisingObject:
def __init__(self, msg="I will raise inside Cython"):
def __init__(self, msg="I will raise inside Cython") -> None:
super().__init__()
self.msg = msg

Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/indexes/datetimes/test_timezones.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
class FixedOffset(tzinfo):
"""Fixed offset in minutes east from UTC."""

def __init__(self, offset, name):
def __init__(self, offset, name) -> None:
self.__offset = timedelta(minutes=offset)
self.__name = name

Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/indexes/test_index_new.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ def test_constructor_ndarray_like(self, array):
# it should be possible to convert any object that satisfies the numpy
# ndarray interface directly into an Index
class ArrayLike:
def __init__(self, array):
def __init__(self, array) -> None:
self.array = array

def __array__(self, dtype=None) -> np.ndarray:
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/indexing/test_iloc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1072,7 +1072,7 @@ def test_iloc_getitem_float_duplicates(self):
def test_iloc_setitem_custom_object(self):
# iloc with an object
class TO:
def __init__(self, value):
def __init__(self, value) -> None:
self.value = value

def __str__(self) -> str:
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/io/formats/test_console.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class MockEncoding:
side effect should be an exception that will be raised.
"""

def __init__(self, encoding):
def __init__(self, encoding) -> None:
super().__init__()
self.val = encoding

Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/io/json/test_pandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,7 @@ def test_frame_nonprintable_bytes(self):
# GH14256: failing column caused segfaults, if it is not the last one

class BinaryThing:
def __init__(self, hexed):
def __init__(self, hexed) -> None:
self.hexed = hexed
self.binary = bytes.fromhex(hexed)

Expand Down Expand Up @@ -1817,7 +1817,7 @@ def test_to_json_multiindex_escape(self):

def test_to_json_series_of_objects(self):
class _TestObject:
def __init__(self, a, b, _c, d):
def __init__(self, a, b, _c, d) -> None:
self.a = a
self.b = b
self._c = _c
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/io/json/test_readlines.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ def test_chunksize_is_incremental():
)

class MyReader:
def __init__(self, contents):
def __init__(self, contents) -> None:
self.read_count = 0
self.stringio = StringIO(contents)

Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/io/json/test_ujson.py
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@ def toDict(self):

def test_default_handler(self):
class _TestObject:
def __init__(self, val):
def __init__(self, val) -> None:
self.val = val

@property
Expand Down Expand Up @@ -714,7 +714,7 @@ def my_obj_handler(_):

def test_encode_object(self):
class _TestObject:
def __init__(self, a, b, _c, d):
def __init__(self, a, b, _c, d) -> None:
self.a = a
self.b = b
self._c = _c
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/io/parser/common/test_common_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def test_override_set_noconvert_columns():
# Usecols needs to be sorted in _set_noconvert_columns based
# on the test_usecols_with_parse_dates test from test_usecols.py
class MyTextFileReader(TextFileReader):
def __init__(self):
def __init__(self) -> None:
self._currow = 0
self.squeeze = False

Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/io/parser/test_python_parser_only.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ def test_python_engine_file_no_next(python_parser_only):
parser = python_parser_only

class NoNextBuffer:
def __init__(self, csv_data):
def __init__(self, csv_data) -> None:
self.data = csv_data

def __iter__(self):
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/io/parser/test_unsupported.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def test_python_engine(self, python_engine):
def test_python_engine_file_no_iter(self, python_engine):
# see gh-16530
class NoNextBuffer:
def __init__(self, csv_data):
def __init__(self, csv_data) -> None:
self.data = csv_data

def __next__(self):
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/io/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
class CustomFSPath:
"""For testing fspath on unknown objects"""

def __init__(self, path):
def __init__(self, path) -> None:
self.path = path

def __fspath__(self):
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/io/test_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -1243,7 +1243,7 @@ def test_parse_failure_rewinds(self):
# Issue #17975

class MockFile:
def __init__(self, data):
def __init__(self, data) -> None:
self.data = data
self.at_end = False

Expand Down
6 changes: 3 additions & 3 deletions pandas/tests/io/test_pickle.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,12 +436,12 @@ def python_pickler(obj, path):
pickle.dump(obj, fh, protocol=-1)

class MockReadResponse:
def __init__(self, path):
def __init__(self, path) -> None:
self.file = open(path, "rb")
if "gzip" in path:
self.headers = {"Content-Encoding": "gzip"}
else:
self.headers = {"Content-Encoding": None}
self.headers = {"Content-Encoding": ""}

def __enter__(self):
return self
Expand Down Expand Up @@ -478,7 +478,7 @@ def test_pickle_fsspec_roundtrip():


class MyTz(datetime.tzinfo):
def __init__(self):
def __init__(self) -> None:
pass


Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/io/test_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -1538,7 +1538,7 @@ def test_con_unknown_dbapi2_class_does_not_error_without_sql_alchemy_installed(
self,
):
class MockSqliteConnection:
def __init__(self, *args, **kwargs):
def __init__(self, *args, **kwargs) -> None:
self.conn = sqlite3.Connection(*args, **kwargs)

def __getattr__(self, name):
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/reshape/test_pivot.py
Original file line number Diff line number Diff line change
Expand Up @@ -1999,7 +1999,7 @@ def test_pivot_number_of_levels_larger_than_int32(self, monkeypatch):
# GH 20601
# GH 26314: Change ValueError to PerformanceWarning
class MockUnstacker(reshape_lib._Unstacker):
def __init__(self, *args, **kwargs):
def __init__(self, *args, **kwargs) -> None:
# __init__ will raise the warning
super().__init__(*args, **kwargs)
raise Exception("Don't compute final result.")
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/scalar/timedelta/test_arithmetic.py
Original file line number Diff line number Diff line change
Expand Up @@ -988,7 +988,7 @@ def test_compare_custom_object(self):
"""

class CustomClass:
def __init__(self, cmp_result=None):
def __init__(self, cmp_result=None) -> None:
self.cmp_result = cmp_result

def generic_result(self):
Expand Down
Loading