Skip to content

Allow to initialize nested structs using "Transactions(transactions=[], accounts=[])" #2428

Open
@certik

Description

@certik

With the following definitions:

from lpython import dataclass, i64

@dataclass
class TransactionItem:
    account_idx: i64
    commodity: str
    amount: i64

@dataclass
class Transaction:
    date: str
    name: str
    cleared: bool
    comments: str
    items: list[TransactionItem]

@dataclass
class Account:
    name: str

@dataclass
class Transactions:
    transactions: list[Transaction]
    accounts: list[Account]

This does not work:

asr: Transactions = Transactions(transactions=[], accounts=[])

This workaround works:

transactions: list[Transaction] = []
accounts: list[Account] = []
asr: Transactions = Transactions(transactions=transactions, accounts=accounts)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions