Expression constructors are not mypy-compatible without the pydantic plugin
まだ誰も着手していません。
評価
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 初心者へのやさしさ
- 65/100
- issue の種類
- バグ
- 明瞭さ
- おおむね明確
- 活発さ
- 静か
- 技術スタック
- python
調査の方向性
pyiceberg/expressions/init.py の UnboundPredicate、LiteralPredicate、UnaryPredicate のコンストラクターと、それらの term フィールド宣言から始めます。既存の validator の動作を確認し、その後、Pydantic プラグインなしの mypy が列挙された predicate コンストラクターを受け入れること、また文字列の term が実行時に引き続き正しく強制変換されることを確認します。
索引モデルが issue の本文から書いたものです。
説明
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:
UnboundPredicate.__init__:def __init__(self, term: str | UnboundTerm, **kwargs: Any) -> NoneLiteralPredicate.__init__:def __init__(self, term: str | UnboundTerm, literal: Any | None = None, **kwargs: Any) -> NoneUnaryPredicate.__init__:def __init__(self, term: str | UnboundTerm, **_: Any) -> None
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.
- 主要言語
- Python
- スター
- 1.1k
- フォーク
- 589
- 平均マージ
- 2日 2時間
- マージ済み PR(30日)
- 70
コントリビューションガイド
このリポジトリのコントリビューションガイドは索引されていません
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
apache/iceberg-python のほかの issue
-
kind:bug
難易度 1/5 1時間未満 初心者へのやさしさ 92/100
apache/iceberg-python#4006 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
apache/iceberg-python#3996 ·
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
apache/iceberg-python#3979 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
apache/iceberg-python#3885 ·
-
[Bug] PyArrowFileIO fails to propagate s3.ssl.ca-cert to pyarrow.fs.S3FileSystem tls_ca_file_path オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
apache/iceberg-python#3866 · コメント 1 件 ·
apache/iceberg-python の issue をすべて見る
似ている issue
-
enhancement
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
canonical/paas-charm#368 · コメント 1 件 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
-
tech debt
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
-
難易度 1/5 1時間未満 初心者へのやさしさ 90/100
StevenBlack/hosts#3256 ·
-
難易度 1/5 1時間未満 初心者へのやさしさ 90/100
qualcomm/qai-appbuilder#275 ·