Skip to content

error[invalid-type-form]: Function calls are not allowed in type expressions with Pydantic conlist #388

@alex-goswag

Description

@alex-goswag

Summary

I can use Field(min_length=1) as a work around or maybe that is the better way to do it but I guess conlist should still be supported by ty ?

Example

# !pip install pydantic==2.11.4
# !pip install ty==0.0.1a1

from pydantic import BaseModel, Field, conlist


class OrderLine(BaseModel):
    product_id: int
    quantity: int


class Order(BaseModel):
    order_lines: conlist(item_type=OrderLine, min_length=1)
    field_order_lines: list[OrderLine] = Field(
        min_length=1,
    )


if __name__ == "__main__":
    order = Order(
        order_lines=[OrderLine(product_id=1, quantity=10)],
        field_order_lines=[OrderLine(product_id=1, quantity=10)],
    )
    print(order)

Ty

WARN ty is pre-release software and not ready for production use. Expect to encounter bugs, missing features, and fatal errors.
error[invalid-type-form]: Function calls are not allowed in type expressions
  --> py.py:13:18
   |
12 | class Order(BaseModel):
13 |     order_lines: conlist(item_type=OrderLine, min_length=1)
   |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14 |     field_order_lines: list[OrderLine] = Field(
15 |         min_length=1,
   |
info: rule `invalid-type-form` is enabled by default

Found 1 diagnostic

Mypy

pip install mypy==1.15.0

py.py:13: error: Invalid type comment or annotation  [valid-type]
py.py:13: note: Suggestion: use conlist[...] instead of conlist(...)
Found 1 error in 1 file (checked 1 source file)

Version

ty 0.0.1-alpha.1 (12f466e 2025-05-13)

Metadata

Metadata

Assignees

No one assigned

    Labels

    diagnosticsRelated to reporting of diagnostics.questionAsking for support or clarification

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions