Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Expression constructors are not mypy-compatible without the pydantic plugin

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

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
65/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Ít trao đổi
Công nghệ
python
Lĩnh vực
developer-experience

Hướng nghiên cứu

Bắt đầu trong pyiceberg/expressions/init.py tại các constructor của UnboundPredicate, LiteralPredicate và UnaryPredicate cùng các khai báo trường term của chúng. Kiểm tra hành vi validator hiện có, sau đó xác minh rằng mypy không có Pydantic plugin chấp nhận các constructor predicate được liệt kê và rằng các term dạng chuỗi vẫn được cưỡng chế kiểu đúng cách khi chạy.

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

Mô tả

Constructing expression predicates like EqualTo("col", value) produces mypy errors because the Pydantic model field declarations use UnboundTerm as the type for term, and without the pydantic mypy plugin active, mypy generates __init__ signatures from the field types rather than from the explicit __init__ overrides.

Example:

from pyiceberg import expressions as ice

expr = ice.EqualTo("my_column", 42)

mypy output (v1.19.1, pyiceberg 0.11.0, no pydantic mypy plugin):

error: Argument 1 to "EqualTo" has incompatible type "str"; expected "UnboundTerm"  [arg-type]

Root cause:

The base classes define explicit __init__ methods that accept str | UnboundTerm:

But since these classes extend IcebergBaseModel (Pydantic BaseModel), mypy ignores the explicit __init__ and instead generates the constructor signature from the field declaration term: UnboundTerm, which does not include str.

This affects all predicate constructors: EqualTo, NotEqualTo, GreaterThan, GreaterThanOrEqual, LessThan, LessThanOrEqual, IsNull, NotNull, IsNaN, NotNaN, In, NotIn, StartsWith, NotStartsWith.

Workaround:

Downstream projects can either enable the pydantic mypy plugin or suppress type checking for the affected call sites.

Possible fix:

Widen the field type annotation on UnboundPredicate from term: UnboundTerm to term: str | UnboundTerm with a validator that coerces str to UnboundTerm. This way the type seen by mypy (from the field declaration) matches what the constructor actually accepts at runtime, regardless of whether the pydantic mypy plugin is enabled.

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

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

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 apache/iceberg-python

Tất cả issue của apache/iceberg-python

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.