rohaquinlop / automathon

A Python library for simulating and visualizing finite automata
https://rohaquinlop.github.io/automathon/
MIT License
61 stars 2 forks source link

Make use of dataclasses #13

Closed rohaquinlop closed 8 months ago

rohaquinlop commented 9 months ago

Refactor DFA and NFA definition to make use of dataclasses, replace __init__ with dataclasses.

Refac this...

def __init__(self, name: str, unit_price: float, quantity_on_hand: int = 0):
    self.name = name
    self.unit_price = unit_price
    self.quantity_on_hand = quantity_on_hand

to this...

from dataclasses import dataclass

@dataclass
class InventoryItem:
    """Class for keeping track of an item in inventory."""
    name: str
    unit_price: float
    quantity_on_hand: int = 0

    def total_cost(self) -> float:
        return self.unit_price * self.quantity_on_hand