Skip to content

Typing stubs are too strict about arguments of type Expression #341

@frankier

Description

@frankier

What happens?

It seems that many types are convertible to Expression. It looks like the casting is done in C++. Currently Python typecheckers will complain because the stubs say many methods can only take Expression when it's fine to pass any of the types convertable to Expression.

To Reproduce

db = duckdb.connect(":memory")
db.execute("CREATE TABLE ducks AS SELECT 3 AS age, 'mandarin' AS breed;")
db.table("ducks").sort("age")
db.table("ducks").sort(1)

If you type check with pyright, you'll get something like:

Argument of type "Literal['age']" cannot be assigned to parameter "args" of type "Expression" in function "sort"

OS:

Linux

DuckDB Package Version:

1.4.4

Python Version:

3.13

Full Name:

Frankie Robertson

Affiliation:

University of Helsinki

What is the latest build you tested with? If possible, we recommend testing with the latest nightly build.

I have tested with a stable release

Did you include all relevant data sets for reproducing the issue?

Yes

Did you include all code required to reproduce the issue?

  • Yes, I have

Did you include all relevant configuration to reproduce the issue?

  • Yes, I have

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions