Convert Type Parameters to follow PEP 695 syntax introduced in Python 3.12

Đang mở
#11,730 9 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

@FrancescoPezzella đang làm issue này rồi.

Từ ngày 14/10/2026.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
22/100
Loại issue
Tái cấu trúc
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
python
Lĩnh vực
developer-experience

Hướng nghiên cứu

The issue gives one example: a pipe method with overloads that uses module-level TypeVar and ParamSpec declarations, in a file over 1000 lines. Before editing, check the project's minimum supported Python version and read the three comments to see whether maintainers have agreed to adopt PEP 695 syntax. Done would mean one module converted, its type checker passing, and any remaining TypeVar uses (such as covariant ones) explained.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

enhancement topic-typing
What is your issue?
Background

https://peps.python.org/pep-0695/ introduced new syntax for Type Parameters.

Out of interest, I took a quick look through the project due to another project I am working on and noticed that this project uses Python 3.12, but still uses a mix of syntax introduced in 3.5 (for reference: https://peps.python.org/pep-0484/) and 3.12, instead of fully modernizing the syntax (where it can be safely done) to the new one.

Sometimes a change cannot be done, for example, if a TypeVar declares covariance/contravariance in a Generic class, since these cases are handled automatically in Python 3.12, and there is no new way to define with the modern syntax.

Example

Old Syntax

from typing import (
    ...
    ParamSpec,
    TypeVar,
    ...
)
T_Resample = TypeVar("T_Resample", bound="Resample")
C = TypeVar("C")
T = TypeVar("T")
P = ParamSpec("P")
    @overload
    def pipe(
        self,
        func: Callable[Concatenate[Self, P], T],
        *args: P.args,
        **kwargs: P.kwargs,
    ) -> T: ...

    @overload
    def pipe(
        self,
        func: tuple[Callable[..., T], str],
        *args: Any,
        **kwargs: Any,
    ) -> T: ...

    def pipe(
        self,
        func: Callable[Concatenate[Self, P], T] | tuple[Callable[P, T], str],
        *args: P.args,
        **kwargs: P.kwargs,

This is a perfect example, where the code could greatly benefit from the new syntax. The file is over a 1000 lines long, the Type Variables are not used anywhere else nor exported. The new syntax would greatly simplify them. This follows Python conventions.

With the new syntax

    @overload
    def pipe[T, P**](
        self,
        func: Callable[Concatenate[Self, P], T],
        *args: P.args,
        **kwargs: P.kwargs,
    ) -> T: ...

    @overload
    def pipe[T](
        self,
        func: tuple[Callable[..., T], str],
        *args: Any,
        **kwargs: Any,
    ) -> T: ...

    def pipe[T, P**](
        self,
        func: Callable[Concatenate[Self, P], T] | tuple[Callable[P, T], str],
        *args: P.args,
        **kwargs: P.kwargs,

This is just one example. I am still looking into this just as interesting case study regarding my research. If this is something that the developers are interested in, I would be happy to look into it more, investigate each case and propose a change with a tool that I am still developing.

Let me know if you would further information, I am quite to making issues and contributions, so I tried my best to follow some examples I read here.

No AI was used in the writing of this.

Ngôn ngữ chính
Python
Star
4.2k
Fork
1.5k
Merge trung bình
2 ngày 21 giờ
Pull request đã merge (30 ngày)
74

Chuẩn bị môi trường

Mở trong Codespaces

Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của pydata/xarray

Tất cả issue của pydata/xarray

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.