Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Expression constructors are not mypy-compatible without the pydantic plugin

Open
#3,101 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
65/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Quiet
Tech stack
python

Research direction

Start in pyiceberg/expressions/init.py at the UnboundPredicate, LiteralPredicate, and UnaryPredicate constructors and their term field declarations. Check the existing validator behavior, then verify that mypy without the Pydantic plugin accepts the listed predicate constructors and that string terms are still coerced correctly at runtime.

Written by the indexing model from the issue text.

Description

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.

Dominant language
Python
Stars
1.1k
Forks
589
Avg merge
2d 4h
Merged PRs (30d)
72

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from apache/iceberg-python

All issues in apache/iceberg-python

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.