Skip to content

Commit 8dca2ac

Browse files
author
Martin Ruefenacht
committed
Linked constants with kind
1 parent 096e640 commit 8dca2ac

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

src/pympistandard/__init__.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -191,11 +191,6 @@ def _load_database_v1(path: Path) -> None:
191191

192192
# TODO discover which files of our database are in path, apis.json, constants.json
193193

194-
with path.joinpath("constants.json").open() as constants_file:
195-
for name, desc in dataset.items():
196-
const = Constant(name, desc)
197-
CONSTANTS[const.name] = const
198-
199194
with path.open("r") as datafile:
200195
if path.suffix == ".json":
201196
dataset = json.load(datafile)
@@ -214,7 +209,7 @@ def _load_database_v1(path: Path) -> None:
214209
raise RuntimeError(f"Unrecognized suffix of data file {path}")
215210

216211
# read in datafile
217-
for name, desc in dataset.items():
212+
for name, desc in dataset["procedures"].items():
218213
if desc["attributes"]["predefined_function"]:
219214
predef = PredefinedFunction(name, desc)
220215
PREDEFINED_FUNCTIONS[predef.name] = predef
@@ -226,3 +221,7 @@ def _load_database_v1(path: Path) -> None:
226221
else:
227222
procedure = Procedure(name, desc)
228223
PROCEDURES[procedure.name] = procedure
224+
225+
for name, desc in dataset["constants"].items():
226+
const = Constant(name, desc)
227+
CONSTANTS[name] = const

src/pympistandard/kind.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77

88
from dataclasses import dataclass
99
from collections import defaultdict
10-
from typing import Optional, MutableMapping, TYPE_CHECKING
10+
from typing import Optional, MutableMapping, TYPE_CHECKING, List
1111

1212

13-
from .storage import CALLBACKS
13+
from .storage import CALLBACKS, CONSTANTS
1414

1515

1616
if TYPE_CHECKING:
@@ -106,7 +106,7 @@ def has_embiggenment(self) -> bool:
106106
return False
107107

108108
@property
109-
def callback(self) -> Optional['Callback']:
109+
def callback(self) -> Optional["Callback"]:
110110
"""Access the relevant Callback object for this Kind."""
111111

112112
# NOTE this should eventually be non-optional, all FUNCTION KINDs will have a Callback
@@ -126,6 +126,12 @@ def callback(self) -> Optional['Callback']:
126126

127127
return None
128128

129+
@property
130+
def constants(self) -> List:
131+
"""Access all constants with this KIND."""
132+
133+
return [const for const in CONSTANTS.values() if const.kind == self]
134+
129135
@property
130136
def express(self) -> KindExpressions:
131137
"""Get the KindExpression object to express the Kind in a language."""

0 commit comments

Comments
 (0)