Skip to content

Detect class attributes set by metaclasses __init__ method #1138

@strangemonad

Description

@strangemonad

Summary

I'm not sure if this is a patito-specific issue or a more general metaclass lookup issue.

https://play.ty.dev/2e6bfe16-f59c-46f0-82c0-aaebcacb942d

Context

  • polars is a popular dataframe library
  • patito allows you to define the schema of individual rows as pydantic models
  • This code checks in pyright/basepyright. I haven't checked mypy, pyre or others.

The implementation relies on a metaclass to define some of this behavior.

In particular in the following code

import patito as pt

class Person(pt.Model):
    name: str

results = Person.DataFrame(...)

The Person.DataFrame class var is added by the patito.pydantic.ModelMetaclass(PydanticModelMetaclass). It's a common and convenient shortcut for the getting a dataframe constructor that's already bound to the correct generic type var and run time model class to allow for runtime schema validation. The alternative would be something like the following.

results = pt.DataFrame[Person]().set_model(Person)

Version

ty 0.0.1-alpha.20 (f41f00a 2025-09-03)

Metadata

Metadata

Assignees

Labels

attribute accessInstance attributes, class attributes, etc.

Type

No type
No fields configured for issues without a type.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions