Skip to content

Type checker errors with Field() #13

@corv89

Description

@corv89

Hi, I'm running ty on a project that uses Oxyde ORM and hitting two categories of false positives that trace back to Oxyde's type signatures. Verified the same errors appear with pyright, so this isn't checker-specific.

Field() return type causes invalid-assignment

Model definitions like this:

class Session(Model):
    id: str = Field(db_pk=True)
    name: str = Field(default="")

get flagged because Field() returns OxydeFieldInfo at runtime, but the annotation says str. The checker sees str = OxydeFieldInfo(...) and reports an assignment type mismatch.

It affects every model field that uses Field(), so it's pretty noisy (48 errors in my project).

Stub generator skips module-level functions

A minor issue but I happen to have a few module-level async helper functions defined in models.py (not methods on a Model class). The stub generator doesn't pick these up, so any file importing them gets unresolved-import. Patching the generated .pyi manually isn't ideal.

Workaround

For now I'm suppressing the check in pyproject.toml:

[tool.ty.rules]
invalid-assignment = "ignore"

This works but it's global, which is less than ideal since it also hides real assignment errors in my own code...

Environment

  • Oxyde: 0.5.2
  • Oxyde-core: 0.4.3
  • Python: 3.12
  • Ty: 0.0.21

Thank you, really enjoying Oxyde so far!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions