Skip to content

Conversation

@dbrattli
Copy link
Collaborator

@dbrattli dbrattli commented Dec 3, 2025

What

  • Add support for [<Py.Decorate>] attribute on (static) methods (previously only worked on classes)
  • Add new [<Py.ClassMethod>] attribute to emit @classmethod instead of @staticmethod

[<Py.Decorate>] now works on:

  • Classes (as before)
  • Static methods
  • Instance methods
  • Properties

This enables integration with Python frameworks like Pydantic that require method-level decorators:

  [<AttachMembers>]
  type User(Name: string) =
      inherit BaseModel()
      member val Name = Name with get, set

      [<Py.Decorate("pydantic.field_validator", "'Name'")>]
      [<Py.ClassMethod>]
      static member validate_name(cls: obj, v: string) = v.ToUpper()

Generates:

  class User(BaseModel):
      Name: str

      @field_validator('Name')
      @classmethod
      def validate_name(cls, v: str) -> str:
          return v.upper()

@dbrattli dbrattli merged commit e176121 into main Dec 3, 2025
22 checks passed
@dbrattli dbrattli deleted the python-class-methods branch December 3, 2025 23:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants