Skip to content

Commit

Permalink
Redesign config such that defaults are visible in API
Browse files Browse the repository at this point in the history
  • Loading branch information
Splines committed Mar 14, 2024
1 parent b83316f commit e1af3b6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 21 deletions.
6 changes: 3 additions & 3 deletions src/api/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@


def config_init(
sigfigs: int = Config.sigfigs_default,
decimal_places: int = Config.decimal_places_default,
print_always: bool = Config.print_always_default,
sigfigs: int = 2,
decimal_places: int = 2,
print_always: bool = False,
):
c = Config(sigfigs, decimal_places, print_always)
print(c.to_json_str())
Expand Down
24 changes: 11 additions & 13 deletions src/application/config.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
from dataclasses import dataclass
import json


@dataclass
class Config:
"""Configuration settings for the application."""
"""Configuration settings for the application.
sigfigs_default = 2
decimal_places_default = 2
print_always_default = False
Args:
sigfigs (int): The number of significant figures to round to.
decimal_places (int): The number of decimal places to round to.
print_always (bool): Whether to print each result directly to the console.
"""

def __init__(
self,
sigfigs=sigfigs_default,
decimal_places=decimal_places_default,
print_always=print_always_default,
):
self.sigfigs = sigfigs
self.decimal_places = decimal_places
self.print_always = print_always
sigfigs: int
decimal_places: int
print_always: bool

def to_json_str(self):
return json.dumps(self.__dict__)
6 changes: 1 addition & 5 deletions tests/playground.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@
print()


wiz.config_init(
sigfigs=3,
decimal_places=3,
print_always=True,
)
wiz.config_init(decimal_places=3, print_always=True)


#############################
Expand Down

0 comments on commit e1af3b6

Please sign in to comment.