Skip to content

Combine multiple classes #1392

Open
Open
@dkrikun

Description

Is it possible to combine two (or more) class declarations into one?
This should be similar to multiple inheritance I guess, but should work with slots.

For example:

@define
class Point2d:
    x : int
    y : int

@define
class Line:
    start : Point2d
    end : Point2d
    
@define
class StrokeProperties:
     size : float
     color : Color
     
DrawnPoint = some_magic(Point2d, StrokeProperties)
DrawnLine = some_magic(Line, StrokeProperties)

print(DrawnPoint.x, DrawnPoint.size)

One could argue, that composition should be used instead, but I think it could be nicer to be able to access attributes without nesting.

Is there something like this in attrs, or how it could be done using existing api?

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions