Skip to content

Commit

Permalink
Merge pull request #44 from gerlero/namedtuple
Browse files Browse the repository at this point in the history
Switch from collections.namedtuple to typing.NamedTuple
  • Loading branch information
gerlero authored Mar 28, 2024
2 parents f7a664f + cec8887 commit 6113bbd
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions foamlib/_dictionaries.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from pathlib import Path
from dataclasses import dataclass
from collections import namedtuple
from contextlib import suppress
from typing import (
Any,
Expand All @@ -10,6 +9,7 @@
Optional,
Mapping,
MutableMapping,
NamedTuple,
cast,
)

Expand Down Expand Up @@ -145,19 +145,17 @@ class FoamFile(_FoamDictionary):

Dictionary = _FoamDictionary

DimensionSet = namedtuple(
"DimensionSet",
[
"mass",
"length",
"time",
"temperature",
"moles",
"current",
"luminous_intensity",
],
defaults=(0, 0, 0, 0, 0, 0, 0),
)
class DimensionSet(NamedTuple):
mass: Union[int, float] = 0
length: Union[int, float] = 0
time: Union[int, float] = 0
temperature: Union[int, float] = 0
moles: Union[int, float] = 0
current: Union[int, float] = 0
luminous_intensity: Union[int, float] = 0

def __repr__(self) -> str:
return f"{type(self).__qualname__}({', '.join(f'{n}={v}' for n, v in zip(self._fields, self) if v != 0)})"

@dataclass
class Dimensioned:
Expand Down

0 comments on commit 6113bbd

Please sign in to comment.