Skip to content

Commit f8478f7

Browse files
committed
types: updated Tuple by currying
1 parent b5f5ac2 commit f8478f7

185 files changed

Lines changed: 1176 additions & 1181 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

scripts/inp_data.py

Lines changed: 165 additions & 165 deletions
Large diffs are not rendered by default.

scripts/inp_tests.py

Lines changed: 59 additions & 59 deletions
Large diffs are not rendered by default.

src/pymcnp/Inp.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ class Inp(_object.McnpFile):
1818
def __init__(
1919
self,
2020
title: types.String,
21-
cells: types.Tuple[inp.Cell | inp.Like],
22-
surfaces: types.Tuple[inp.Surface],
23-
data: types.Tuple[inp.Data],
21+
cells: types.Tuple(inp.Cell | inp.Like),
22+
surfaces: types.Tuple(inp.Surface),
23+
data: types.Tuple(inp.Data),
2424
message: types.String = None,
2525
other: types.String = None,
2626
):
@@ -43,9 +43,9 @@ def __init__(
4343
"""
4444

4545
self.title: types.String = title
46-
self.cells: types.Tuple[inp.Cell | inp.Like | inp.Comment] = cells
47-
self.surfaces: types.Tuple[inp.Surface | inp.Comment] = surfaces
48-
self.data: types.Tuple[inp.Data | inp.Comment] = data
46+
self.cells: types.Tuple(inp.Cell | inp.Like | inp.Comment) = cells
47+
self.surfaces: types.Tuple(inp.Surface | inp.Comment) = surfaces
48+
self.data: types.Tuple(inp.Data | inp.Comment) = data
4949
self.message: types.String = message
5050
self.other: types.String = other
5151

@@ -242,7 +242,7 @@ def cells(self, cells: list[str] | list[inp.Cell | inp.Like | inp.Comment]) -> N
242242
else:
243243
array.append(inp.Cell.from_mcnp(item))
244244

245-
cells = types.Tuple(array)
245+
cells = types.Tuple(inp.Card)(array)
246246

247247
if cells is None or None in cells:
248248
raise errors.InpError(errors.InpCode.SEMANTICS_FILE, cells)
@@ -289,7 +289,7 @@ def surfaces(self, surfaces: list[str] | list[inp.Surface | inp.Comment]) -> Non
289289
pass
290290
array.append(inp.Surface.from_mcnp(item))
291291

292-
surfaces = types.Tuple(array)
292+
surfaces = types.Tuple(inp.Card)(array)
293293

294294
if surfaces is None or None in surfaces:
295295
raise errors.InpError(errors.InpCode.SEMANTICS_FILE, surfaces)
@@ -337,7 +337,7 @@ def data(self, data: list[str] | list[inp.Data | inp.Comment]) -> None:
337337

338338
array.append(inp.Data.from_mcnp(item))
339339

340-
data = types.Tuple(array)
340+
data = types.Tuple(inp.Card)(array)
341341

342342
if data is None or None in data:
343343
raise errors.InpError(errors.InpCode.SEMANTICS_FILE, data)

src/pymcnp/Outp.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class Outp(_object.McnpFile):
2323
def __init__(
2424
self,
2525
header: outp.Header,
26-
blocks: types.Tuple[outp.Block],
26+
blocks: types.Tuple(outp.Block),
2727
):
2828
"""
2929
Initializes ``Outp``.
@@ -44,7 +44,7 @@ def __init__(
4444
raise errors.OutpError(errors.OutpCode.SEMANTICS_FILE, blocks)
4545

4646
self.header: typing.Final[outp.Header] = header
47-
self.blocks: typing.Final[types.Tuple[outp.Block]] = blocks
47+
self.blocks: typing.Final[types.Tuple(outp.Block)] = blocks
4848

4949
@staticmethod
5050
def from_mcnp(source: str):
@@ -78,7 +78,7 @@ def from_mcnp(source: str):
7878

7979
blocks.append(block)
8080

81-
blocks = types.Tuple(blocks)
81+
blocks = types.Tuple(outp.Block)(blocks)
8282

8383
return Outp(
8484
header,

src/pymcnp/Ptrac.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def from_mcnp(source: str):
6565
raise errors.PtracError(errors.PtracCode.SYNTAX_FILE, source)
6666

6767
header = ptrac.Header.from_mcnp(tokens[1])
68-
histories = types.Tuple(ptrac.History.from_mcnp(match[0]) for match in re.finditer(ptrac.History._REGEX.pattern[2:-2], tokens[2]))
68+
histories = types.Tuple(ptrac.History)([ptrac.History.from_mcnp(match[0]) for match in re.finditer(ptrac.History._REGEX.pattern[2:-2], tokens[2])])
6969

7070
return Ptrac(header, histories)
7171

@@ -77,4 +77,4 @@ def to_mcnp(self):
7777
PTRAC for ``Ptrac``.
7878
"""
7979

80-
return self.header.to_mcnp() + ''.join(map(str, self.histories))
80+
return self.header.to_mcnp() + ''.join(history.to_mcnp() for history in self.histories)

src/pymcnp/inp/Cell.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class Cell(_card.Card):
1717
'material': types.Integer,
1818
'density': types.Real,
1919
'geometry': cell.Geometry,
20-
'options': types.Tuple[cell.CellOption],
20+
'options': types.Tuple(cell.CellOption),
2121
}
2222

2323
_REGEX = re.compile(rf'\A(\S+)( \S+)((?<! 0) \S+|(?<= 0))( [^a-z]+)((?: (?:{cell.CellOption._REGEX.pattern[2:-2]}))+?)?\Z')
@@ -28,7 +28,7 @@ def __init__(
2828
material: types.Integer,
2929
geometry: cell.Geometry,
3030
density: types.Real = None,
31-
options: types.Tuple[cell.CellOption] = None,
31+
options: types.Tuple(cell.CellOption) = None,
3232
):
3333
"""
3434
Initializes ``Cell``.
@@ -48,7 +48,7 @@ def __init__(
4848
self.material: types.Integer = material
4949
self.density: types.Real = density
5050
self.geometry: cell.Geometry = geometry
51-
self.options: types.Tuple[cell.CellOption] = options
51+
self.options: types.Tuple(cell.CellOption) = options
5252

5353
def to_mcnp(self):
5454
"""
@@ -58,6 +58,8 @@ def to_mcnp(self):
5858
INP cell card.
5959
"""
6060

61+
print(type(self.options))
62+
6163
source = f'{self.number} {self.material} {self.density or ""} {self.geometry} {self.options or ""}'
6264
source, comments = _parser.preprocess_inp(source)
6365
source = _parser.postprocess_inp(source)
@@ -235,7 +237,7 @@ def geometry(self, geometry: str | cell.Geometry) -> None:
235237
self._geometry: cell.Geometry = geometry
236238

237239
@property
238-
def options(self) -> types.Tuple[cell.CellOption]:
240+
def options(self) -> types.Tuple(cell.CellOption):
239241
"""
240242
Cell options.
241243
@@ -266,7 +268,6 @@ def options(self, options: list[str] | list[cell.CellOption] = None) -> None:
266268
array.append(item)
267269
elif isinstance(item, str):
268270
array.append(cell.CellOption.from_mcnp(item))
271+
options = types.Tuple(cell.CellOption)(array)
269272

270-
options = types.Tuple(array)
271-
272-
self._options: types.Tuple[cell.CellOption] = options
273+
self._options: types.Tuple(cell.CellOption) = options

src/pymcnp/inp/Like.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class Like(_card.Card):
1515
_ATTRS = {
1616
'number': types.Integer,
1717
'cell': types.Integer,
18-
'options': types.Tuple[like.LikeOption],
18+
'options': types.Tuple(like.LikeOption),
1919
}
2020

2121
_REGEX = re.compile(rf'\A(\S+) like (\S+) but((?: (?:{like.LikeOption._REGEX.pattern[2:-2]}))+?)?\Z')
@@ -24,7 +24,7 @@ def __init__(
2424
self,
2525
number: types.Integer,
2626
cell: types.Integer,
27-
options: types.Tuple[like.LikeOption] = None,
27+
options: types.Tuple(like.LikeOption) = None,
2828
):
2929
"""
3030
Initializes ``Like``.
@@ -40,7 +40,7 @@ def __init__(
4040

4141
self.number: types.Integer = number
4242
self.cell: types.Integer = cell
43-
self.options: types.Tuple[like.LikeOption] = options
43+
self.options: types.Tuple(like.LikeOption) = options
4444

4545
def to_mcnp(self):
4646
"""
@@ -133,7 +133,7 @@ def cell(self, cell: str | int | types.Integer) -> None:
133133
self._cell: types.Integer = cell
134134

135135
@property
136-
def options(self) -> types.Tuple[like.LikeOption]:
136+
def options(self) -> types.Tuple(like.LikeOption):
137137
"""
138138
Cell options.
139139
@@ -165,6 +165,6 @@ def options(self, options: list[str] | list[like.LikeOption] = None) -> None:
165165
elif isinstance(item, str):
166166
array.append(like.LikeOption.from_mcnp(item))
167167

168-
options = types.Tuple(array)
168+
options = types.Tuple(like.LikeOption)(array)
169169

170-
self._options: types.Tuple[like.LikeOption] = options
170+
self._options: types.Tuple(like.LikeOption) = options

src/pymcnp/inp/_option.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import types
2-
31
from .. import errors
42
from ..utils import _object
53
from ..utils import _parser
@@ -42,10 +40,7 @@ def from_mcnp(cls, source: str):
4240

4341
attrs = {}
4442
for i, (name, attr) in enumerate(subclass._ATTRS.items()):
45-
if isinstance(attr, types.GenericAlias):
46-
attrs[name] = attr.from_mcnp(tokens[i + 1].strip(), attr.__args__[0]) if tokens[i + 1] else None
47-
else:
48-
attrs[name] = attr.from_mcnp(tokens[i + 1].strip()) if tokens[i + 1] else None
43+
attrs[name] = attr.from_mcnp(tokens[i + 1].strip()) if tokens[i + 1] else None
4944

5045
return subclass(**attrs)
5146

src/pymcnp/inp/cell/Fill_0.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class Fill_0(_option.CellOption):
1717
'i': types.Index,
1818
'j': types.Index,
1919
'k': types.Index,
20-
'universes': types.Tuple[types.Integer],
20+
'universes': types.Tuple(types.Integer),
2121
'm': types.Integer,
2222
}
2323

@@ -51,7 +51,7 @@ def __init__(
5151
self.i: types.Index = i
5252
self.j: types.Index = j
5353
self.k: types.Index = k
54-
self.universes: types.Tuple[types.Integer] = universes
54+
self.universes: types.Tuple(types.Integer) = universes
5555
self.m: types.Integer = m
5656

5757
@property
@@ -199,7 +199,7 @@ def k(self, k: str | types.Index) -> None:
199199
self._k: types.Index = k
200200

201201
@property
202-
def universes(self) -> types.Tuple[types.Integer]:
202+
def universes(self) -> types.Tuple(types.Integer):
203203
"""
204204
Fill universe numbers
205205
@@ -232,12 +232,12 @@ def universes(self, universes: list[str] | list[int] | list[types.Integer]) -> N
232232
array.append(types.Integer(item))
233233
elif isinstance(item, str):
234234
array.append(types.Integer.from_mcnp(item))
235-
universes = types.Tuple(array)
235+
universes = types.Tuple(types.Integer)(array)
236236

237237
if universes is None:
238238
raise errors.InpError(errors.InpCode.SEMANTICS_OPTION, universes)
239239

240-
self._universes: types.Tuple[types.Integer] = universes
240+
self._universes: types.Tuple(types.Integer) = universes
241241

242242
@property
243243
def m(self) -> types.Integer:

src/pymcnp/inp/cell/Tmp.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class Tmp(_option.CellOption):
1414

1515
_ATTRS = {
1616
'suffix': types.Integer,
17-
'temperature': types.Tuple[types.Real],
17+
'temperature': types.Tuple(types.Real),
1818
}
1919

2020
_REGEX = re.compile(rf'\Atmp(\d+)((?: {types.Real._REGEX.pattern[2:-2]})+?)\Z')
@@ -32,7 +32,7 @@ def __init__(self, temperature: list[str] | list[float] | list[types.Real], suff
3232
"""
3333

3434
self.suffix: types.Integer = suffix
35-
self.temperature: types.Tuple[types.Real] = temperature
35+
self.temperature: types.Tuple(types.Real) = temperature
3636

3737
@property
3838
def suffix(self) -> types.Integer:
@@ -70,7 +70,7 @@ def suffix(self, suffix: str | int | types.Integer) -> None:
7070
self._suffix: types.Integer = suffix
7171

7272
@property
73-
def temperature(self) -> types.Tuple[types.Real]:
73+
def temperature(self) -> types.Tuple(types.Real):
7474
"""
7575
Temperature at time index
7676
@@ -103,9 +103,9 @@ def temperature(self, temperature: list[str] | list[float] | list[types.Real]) -
103103
array.append(types.Real(item))
104104
elif isinstance(item, str):
105105
array.append(types.Real.from_mcnp(item))
106-
temperature = types.Tuple(array)
106+
temperature = types.Tuple(types.Real)(array)
107107

108108
if temperature is None or not (min(map(lambda temp: temp, temperature)) > 0):
109109
raise errors.InpError(errors.InpCode.SEMANTICS_OPTION, temperature)
110110

111-
self._temperature: types.Tuple[types.Real] = temperature
111+
self._temperature: types.Tuple(types.Real) = temperature

0 commit comments

Comments
 (0)