Skip to main content

Module class_def

Module class_def 

Source
Expand description

Struct-based class lowering.

A Python class lowers to a Rust struct plus an inherent impl block:

  • Instance attributes become struct fields, inferred from the self.attr assignments in __init__ (from annotated parameters, literals, or construction of another known class).
  • __init__ lowers as an ordinary method taking &mut self, and a synthesized new(...) constructor default-initializes the struct and runs it; ClassName(...) call sites lower to ClassName::new(...)?.
  • Methods lower as inherent methods; the receiver is &self, or &mut self when the method stores through self (directly or by calling another method of the class that does).

Unsupported class constructs — inheritance, class-level statements, attributes whose types can’t be inferred — are conversion-time errors, never silently dropped: lowering that diverges from Python must fail loudly.

Structs§

ClassDef