Skip to content

TYP: Update typing for 3.10 #61453

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
May 19, 2025
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 .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ repos:
pass_filenames: false
types: [python]
stages: [manual]
- id: mypy
- id: stubtest
Copy link
Contributor Author

Choose a reason for hiding this comment

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

docs indicated you could just say stubtest, but that didn't work without this change. Now you can run mypy and stubtest separately as part of type checking

# note: assumes python env is setup and activated
# note: requires pandas dev to be installed
name: mypy (stubtest)
Expand Down
2 changes: 1 addition & 1 deletion pandas/_libs/arrays.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Sequence
from collections.abc import Sequence

import numpy as np

Expand Down
2 changes: 1 addition & 1 deletion pandas/_libs/hashtable.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from collections.abc import Hashable
from typing import (
Any,
Hashable,
Literal,
overload,
)
Expand Down
4 changes: 3 additions & 1 deletion pandas/_libs/internals.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from typing import (
from collections.abc import (
Iterator,
Sequence,
)
from typing import (
final,
overload,
)
Expand Down
2 changes: 1 addition & 1 deletion pandas/_libs/json.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from collections.abc import Callable
from typing import (
Any,
Callable,
)

def ujson_dumps(
Expand Down
8 changes: 5 additions & 3 deletions pandas/_libs/lib.pyi
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
# TODO(npdtypes): Many types specified here can be made more specific/accurate;
# the more specific versions are specified in comments
from collections.abc import (
Callable,
Generator,
Hashable,
)
from decimal import Decimal
from typing import (
Any,
Callable,
Final,
Generator,
Hashable,
Literal,
TypeAlias,
overload,
Expand Down
6 changes: 4 additions & 2 deletions pandas/_libs/ops.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from typing import (
Any,
from collections.abc import (
Callable,
Iterable,
)
from typing import (
Any,
Literal,
TypeAlias,
overload,
Expand Down
2 changes: 1 addition & 1 deletion pandas/_libs/parsers.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from collections.abc import Hashable
from typing import (
Hashable,
Literal,
)

Expand Down
2 changes: 1 addition & 1 deletion pandas/_libs/properties.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from collections.abc import Sequence
from typing import (
Sequence,
overload,
)

Expand Down
2 changes: 1 addition & 1 deletion pandas/_libs/sparse.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Sequence
from collections.abc import Sequence

import numpy as np

Expand Down
2 changes: 1 addition & 1 deletion pandas/_libs/testing.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Mapping
from collections.abc import Mapping

def assert_dict_equal(a: Mapping, b: Mapping, compare_keys: bool = ...) -> bool: ...
def assert_almost_equal(
Expand Down
3 changes: 0 additions & 3 deletions pandas/_libs/tslibs/nattype.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from datetime import (
date as date_,
datetime,
time as time_,
timedelta,
tzinfo as _tzinfo,
)
Expand Down Expand Up @@ -99,7 +97,6 @@ class NaTType:
ambiguous: bool | Literal["raise"] | NaTType = ...,
nonexistent: TimestampNonexistent = ...,
) -> NaTType: ...
def combine(cls, date: date_, time: time_) -> NoReturn: ...
@property
def tzinfo(self) -> None: ...
@property
Expand Down
2 changes: 1 addition & 1 deletion pandas/_libs/tslibs/offsets.pyi
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from collections.abc import Collection
from datetime import (
datetime,
time,
timedelta,
)
from typing import (
Any,
Collection,
Literal,
TypeVar,
overload,
Expand Down
2 changes: 1 addition & 1 deletion pandas/_libs/tslibs/timezones.pyi
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from collections.abc import Callable
from datetime import (
datetime,
tzinfo,
)
from typing import Callable

import numpy as np

Expand Down
2 changes: 1 addition & 1 deletion pandas/_libs/tslibs/tzconversion.pyi
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from collections.abc import Iterable
from datetime import (
timedelta,
tzinfo,
)
from typing import Iterable

import numpy as np

Expand Down
2 changes: 1 addition & 1 deletion pandas/_libs/window/aggregations.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from collections.abc import Callable
from typing import (
Any,
Callable,
Literal,
)

Expand Down
4 changes: 2 additions & 2 deletions pandas/_libs/window/aggregations.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1354,8 +1354,8 @@ def roll_quantile(const float64_t[:] values, ndarray[int64_t] start,
if interpolation_type == LINEAR:
vlow = skiplist_get(skiplist, idx, &ret)
vhigh = skiplist_get(skiplist, idx + 1, &ret)
output[i] = ((vlow + (vhigh - vlow) *
(idx_with_fraction - idx)))
output[i] = (vlow + (vhigh - vlow) *
(idx_with_fraction - idx))
elif interpolation_type == LOWER:
output[i] = skiplist_get(skiplist, idx, &ret)
elif interpolation_type == HIGHER:
Expand Down
5 changes: 4 additions & 1 deletion pandas/_testing/contexts.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from contextlib import contextmanager
import os
from pathlib import Path
import sys
import tempfile
from typing import (
IO,
Expand Down Expand Up @@ -81,7 +82,9 @@ def setTZ(tz) -> None:
pass
else:
os.environ["TZ"] = tz
time.tzset()
# Next line allows typing checks to pass on Windows
if sys.platform != "win32":
time.tzset()

orig_tz = os.environ.get("TZ")
setTZ(tz)
Expand Down
Loading
Loading