Skip to content

Commit 0794249

Browse files
committed
annotate-magics
1 parent 221f636 commit 0794249

File tree

17 files changed

+68
-19
lines changed

17 files changed

+68
-19
lines changed

pandas/_testing/contexts.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from pathlib import Path
66
from shutil import rmtree
77
import tempfile
8+
from types import TracebackType
89
from typing import (
910
IO,
1011
Any,
@@ -237,6 +238,11 @@ def __enter__(self) -> None:
237238
self.start_state = np.random.get_state()
238239
np.random.seed(self.seed)
239240

240-
def __exit__(self, exc_type, exc_value, traceback) -> None:
241+
def __exit__(
242+
self,
243+
exc_type: type[BaseException] | None,
244+
exc_value: BaseException | None,
245+
traceback: TracebackType | None,
246+
) -> None:
241247

242248
np.random.set_state(self.start_state)

pandas/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ def __getitem__(self, key):
515515
def __iter__(self):
516516
return self._data.__iter__()
517517

518-
def __len__(self):
518+
def __len__(self) -> int:
519519
return self._data.__len__()
520520

521521
return TestNonDictMapping

pandas/core/arrays/datetimelike.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1937,7 +1937,9 @@ class TimelikeOps(DatetimeLikeArrayMixin):
19371937

19381938
_default_dtype: np.dtype
19391939

1940-
def __init__(self, values, dtype=None, freq=lib.no_default, copy: bool = False):
1940+
def __init__(
1941+
self, values, dtype=None, freq=lib.no_default, copy: bool = False
1942+
) -> None:
19411943
values = extract_array(values, extract_numpy=True)
19421944
if isinstance(values, IntegerArray):
19431945
values = values.to_numpy("int64", na_value=iNaT)

pandas/core/dtypes/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ def __init__(self, storage=None) -> None:
403403
def __repr__(self) -> str:
404404
return f"{self.name}[{self.storage}]"
405405

406-
def __str__(self):
406+
def __str__(self) -> str:
407407
return self.name
408408

409409
def __eq__(self, other: Any) -> bool:

pandas/core/internals/concat.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ def _get_mgr_concatenation_plan(mgr: BlockManager, indexers: dict[int, np.ndarra
359359

360360

361361
class JoinUnit:
362-
def __init__(self, block: Block, shape: Shape, indexers=None):
362+
def __init__(self, block: Block, shape: Shape, indexers=None) -> None:
363363
# Passing shape explicitly is required for cases when block is None.
364364
# Note: block is None implies indexers is None, but not vice-versa
365365
if indexers is None:

pandas/core/strings/object_array.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class ObjectStringArrayMixin(BaseStringArrayMethods):
3232

3333
_str_na_value = np.nan
3434

35-
def __len__(self):
35+
def __len__(self) -> int:
3636
# For typing, _str_map relies on the object being sized.
3737
raise NotImplementedError
3838

pandas/io/excel/_base.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from io import BytesIO
88
import os
99
from textwrap import fill
10+
from types import TracebackType
1011
from typing import (
1112
IO,
1213
Any,
@@ -1449,7 +1450,12 @@ def check_extension(cls, ext: str) -> Literal[True]:
14491450
def __enter__(self) -> ExcelWriter:
14501451
return self
14511452

1452-
def __exit__(self, exc_type, exc_value, traceback) -> None:
1453+
def __exit__(
1454+
self,
1455+
exc_type: type[BaseException] | None,
1456+
exc_value: BaseException | None,
1457+
traceback: TracebackType | None,
1458+
) -> None:
14531459
self.close()
14541460

14551461
def close(self) -> None:
@@ -1746,7 +1752,12 @@ def close(self) -> None:
17461752
def __enter__(self) -> ExcelFile:
17471753
return self
17481754

1749-
def __exit__(self, exc_type, exc_value, traceback) -> None:
1755+
def __exit__(
1756+
self,
1757+
exc_type: type[BaseException] | None,
1758+
exc_value: BaseException | None,
1759+
traceback: TracebackType | None,
1760+
) -> None:
17501761
self.close()
17511762

17521763
def __del__(self) -> None:

pandas/io/json/_json.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import functools
99
from io import StringIO
1010
from itertools import islice
11+
from types import TracebackType
1112
from typing import (
1213
TYPE_CHECKING,
1314
Any,
@@ -991,7 +992,12 @@ def __next__(self) -> DataFrame | Series:
991992
def __enter__(self) -> JsonReader[FrameSeriesStrT]:
992993
return self
993994

994-
def __exit__(self, exc_type, exc_value, traceback) -> None:
995+
def __exit__(
996+
self,
997+
exc_type: type[BaseException] | None,
998+
exc_value: BaseException | None,
999+
traceback: TracebackType | None,
1000+
) -> None:
9951001
self.close()
9961002

9971003

pandas/io/parsers/readers.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import inspect
99
import sys
1010
from textwrap import fill
11+
from types import TracebackType
1112
from typing import (
1213
IO,
1314
Any,
@@ -1806,7 +1807,12 @@ def get_chunk(self, size: int | None = None) -> DataFrame:
18061807
def __enter__(self) -> TextFileReader:
18071808
return self
18081809

1809-
def __exit__(self, exc_type, exc_value, traceback) -> None:
1810+
def __exit__(
1811+
self,
1812+
exc_type: type[BaseException] | None,
1813+
exc_value: BaseException | None,
1814+
traceback: TracebackType | None,
1815+
) -> None:
18101816
self.close()
18111817

18121818

pandas/io/pytables.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import os
1616
import re
1717
from textwrap import dedent
18+
from types import TracebackType
1819
from typing import (
1920
TYPE_CHECKING,
2021
Any,
@@ -632,7 +633,12 @@ def __repr__(self) -> str:
632633
def __enter__(self) -> HDFStore:
633634
return self
634635

635-
def __exit__(self, exc_type, exc_value, traceback) -> None:
636+
def __exit__(
637+
self,
638+
exc_type: type[BaseException] | None,
639+
exc_value: BaseException | None,
640+
traceback: TracebackType | None,
641+
) -> None:
636642
self.close()
637643

638644
def keys(self, include: str = "pandas") -> list[str]:

pandas/io/sas/sasreader.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
ABCMeta,
88
abstractmethod,
99
)
10+
from types import TracebackType
1011
from typing import (
1112
TYPE_CHECKING,
1213
Hashable,
@@ -48,7 +49,12 @@ def close(self) -> None:
4849
def __enter__(self) -> ReaderBase:
4950
return self
5051

51-
def __exit__(self, exc_type, exc_value, traceback) -> None:
52+
def __exit__(
53+
self,
54+
exc_type: type[BaseException] | None,
55+
exc_value: BaseException | None,
56+
traceback: TracebackType | None,
57+
) -> None:
5258
self.close()
5359

5460

pandas/io/stata.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import os
1919
import struct
2020
import sys
21+
from types import TracebackType
2122
from typing import (
2223
IO,
2324
TYPE_CHECKING,
@@ -1178,7 +1179,12 @@ def __enter__(self) -> StataReader:
11781179
"""enter context manager"""
11791180
return self
11801181

1181-
def __exit__(self, exc_type, exc_value, traceback) -> None:
1182+
def __exit__(
1183+
self,
1184+
exc_type: type[BaseException] | None,
1185+
exc_value: BaseException | None,
1186+
traceback: TracebackType | None,
1187+
) -> None:
11821188
"""exit context manager"""
11831189
self.close()
11841190

pandas/tests/dtypes/test_inference.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def it_outer():
103103

104104
return it_outer()
105105

106-
def __len__(self):
106+
def __len__(self) -> int:
107107
return len(self._values)
108108

109109
def __array__(self, t=None):
@@ -1954,7 +1954,7 @@ class Numeric(Number):
19541954
def __init__(self, value) -> None:
19551955
self.value = value
19561956

1957-
def __int__(self):
1957+
def __int__(self) -> int:
19581958
return self.value
19591959

19601960
num = Numeric(1)

pandas/tests/extension/arrow/arrays.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def _from_sequence(cls, values, dtype=None, copy=False):
9191
arr = pa.chunked_array([pa.array(np.asarray(values))])
9292
return cls(arr)
9393

94-
def __repr__(self):
94+
def __repr__(self) -> str:
9595
return f"{type(self).__name__}({repr(self._data)})"
9696

9797
def __contains__(self, obj) -> bool:

pandas/tests/frame/test_arithmetic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2032,7 +2032,7 @@ def _constructor_expanddim(self):
20322032
class SubclassedDataFrame(DataFrame):
20332033
_metadata = ["my_extra_data"]
20342034

2035-
def __init__(self, my_extra_data, *args, **kwargs):
2035+
def __init__(self, my_extra_data, *args, **kwargs) -> None:
20362036
self.my_extra_data = my_extra_data
20372037
super().__init__(*args, **kwargs)
20382038

pandas/tests/frame/test_constructors.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1394,7 +1394,7 @@ def __init__(self, lst) -> None:
13941394
def __getitem__(self, n):
13951395
return self._lst.__getitem__(n)
13961396

1397-
def __len__(self):
1397+
def __len__(self) -> int:
13981398
return self._lst.__len__()
13991399

14001400
lst_containers = [DummyContainer([1, "a"]), DummyContainer([2, "b"])]

pandas/tests/io/formats/test_format.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2816,7 +2816,7 @@ def name(self):
28162816
return "DtypeStub"
28172817

28182818
class ExtTypeStub(pd.api.extensions.ExtensionArray):
2819-
def __len__(self):
2819+
def __len__(self) -> int:
28202820
return 2
28212821

28222822
def __getitem__(self, ix):

0 commit comments

Comments
 (0)