Skip to content

Commit 05a0e98

Browse files
authored
CLN: Optional[Hashable] in dict type hints (#40534)
1 parent a3ebb63 commit 05a0e98

File tree

4 files changed

+11
-11
lines changed

4 files changed

+11
-11
lines changed

pandas/core/generic.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ class NDFrame(PandasObject, SelectionMixin, indexing.IndexingMixin):
231231
_metadata: List[str] = []
232232
_is_copy: Optional[weakref.ReferenceType[NDFrame]] = None
233233
_mgr: Manager
234-
_attrs: Dict[Optional[Hashable], Any]
234+
_attrs: Dict[Hashable, Any]
235235
_typ: str
236236

237237
# ----------------------------------------------------------------------
@@ -241,7 +241,7 @@ def __init__(
241241
self,
242242
data: Manager,
243243
copy: bool = False,
244-
attrs: Optional[Mapping[Optional[Hashable], Any]] = None,
244+
attrs: Optional[Mapping[Hashable, Any]] = None,
245245
):
246246
# copy kwarg is retained for mypy compat, is not used
247247

@@ -320,7 +320,7 @@ def _as_manager(self: FrameOrSeries, typ: str) -> FrameOrSeries:
320320
# attrs and flags
321321

322322
@property
323-
def attrs(self) -> Dict[Optional[Hashable], Any]:
323+
def attrs(self) -> Dict[Hashable, Any]:
324324
"""
325325
Dictionary of global attributes of this dataset.
326326
@@ -337,7 +337,7 @@ def attrs(self) -> Dict[Optional[Hashable], Any]:
337337
return self._attrs
338338

339339
@attrs.setter
340-
def attrs(self, value: Mapping[Optional[Hashable], Any]) -> None:
340+
def attrs(self, value: Mapping[Hashable, Any]) -> None:
341341
self._attrs = dict(value)
342342

343343
@final
@@ -803,7 +803,7 @@ def swapaxes(self: FrameOrSeries, axis1, axis2, copy=True) -> FrameOrSeries:
803803
# error: Argument 2 to "NDFrame" has incompatible type "*Generator[Index,
804804
# None, None]"; expected "bool" [arg-type]
805805
# error: Argument 2 to "NDFrame" has incompatible type "*Generator[Index,
806-
# None, None]"; expected "Optional[Mapping[Optional[Hashable], Any]]"
806+
# None, None]"; expected "Optional[Mapping[Hashable, Any]]"
807807
new_values, # type: ignore[arg-type]
808808
*new_axes, # type: ignore[arg-type]
809809
).__finalize__(self, method="swapaxes")

pandas/io/json/_json.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ def read_json(
572572
if dtype is None and orient != "table":
573573
# error: Incompatible types in assignment (expression has type "bool", variable
574574
# has type "Union[ExtensionDtype, str, dtype[Any], Type[str], Type[float],
575-
# Type[int], Type[complex], Type[bool], Type[object], Dict[Optional[Hashable],
575+
# Type[int], Type[complex], Type[bool], Type[object], Dict[Hashable,
576576
# Union[ExtensionDtype, Union[str, dtype[Any]], Type[str], Type[float],
577577
# Type[int], Type[complex], Type[bool], Type[object]]], None]")
578578
dtype = True # type: ignore[assignment]
@@ -921,7 +921,7 @@ def _try_convert_data(self, name, data, use_dtypes=True, convert_dates=True):
921921

922922
# error: Non-overlapping identity check (left operand type:
923923
# "Union[ExtensionDtype, str, dtype[Any], Type[object],
924-
# Dict[Optional[Hashable], Union[ExtensionDtype, Union[str, dtype[Any]],
924+
# Dict[Hashable, Union[ExtensionDtype, Union[str, dtype[Any]],
925925
# Type[str], Type[float], Type[int], Type[complex], Type[bool],
926926
# Type[object]]]]", right operand type: "Literal[True]")
927927
elif self.dtype is True: # type: ignore[comparison-overlap]

pandas/io/sql.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1563,7 +1563,7 @@ def to_sql(
15631563
if not is_dict_like(dtype):
15641564
# error: Value expression in dictionary comprehension has incompatible
15651565
# type "Union[ExtensionDtype, str, dtype[Any], Type[object],
1566-
# Dict[Optional[Hashable], Union[ExtensionDtype, Union[str, dtype[Any]],
1566+
# Dict[Hashable, Union[ExtensionDtype, Union[str, dtype[Any]],
15671567
# Type[str], Type[float], Type[int], Type[complex], Type[bool],
15681568
# Type[object]]]]"; expected type "Union[ExtensionDtype, str,
15691569
# dtype[Any], Type[object]]"
@@ -2060,7 +2060,7 @@ def to_sql(
20602060
if not is_dict_like(dtype):
20612061
# error: Value expression in dictionary comprehension has incompatible
20622062
# type "Union[ExtensionDtype, str, dtype[Any], Type[object],
2063-
# Dict[Optional[Hashable], Union[ExtensionDtype, Union[str, dtype[Any]],
2063+
# Dict[Hashable, Union[ExtensionDtype, Union[str, dtype[Any]],
20642064
# Type[str], Type[float], Type[int], Type[complex], Type[bool],
20652065
# Type[object]]]]"; expected type "Union[ExtensionDtype, str,
20662066
# dtype[Any], Type[object]]"

pandas/plotting/_matplotlib/core.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -609,8 +609,8 @@ def _make_legend(self):
609609
self.legend_handles
610610
)
611611
# error: Incompatible types in assignment (expression has type
612-
# "Iterator[Optional[Hashable]]", variable has type
613-
# "List[Optional[Hashable]]")
612+
# "Iterator[Hashable]", variable has type
613+
# "List[Hashable]")
614614
self.legend_labels = reversed( # type: ignore[assignment]
615615
self.legend_labels
616616
)

0 commit comments

Comments
 (0)