Skip to content

Commit

Permalink
utils/types: update distribution number & comments
Browse files Browse the repository at this point in the history
  • Loading branch information
BitterB0NG0 committed Nov 21, 2024
1 parent fc19ee9 commit 2fa13a1
Show file tree
Hide file tree
Showing 3 changed files with 227 additions and 69 deletions.
54 changes: 53 additions & 1 deletion src/pymcnp/files/inp/_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,33 @@ def build(self):

o += '\n'

elif attribute.type.startswith('Union'):
inside_types = attribute.type[len('Union[') : -1].split(', ')

a = True
for inside_type in inside_types:
o += (
f' {'if' if a else 'elif'} isinstance(inside_type, {inside_type}):\n'
)

if inside_type.startswith('tuple'):
inside_inside_type = inside_type[len('tuple[') : -1]

if inside_inside_type == 'str':
# Union[tuple[str], ...]
o += f' {attribute.name} = [tokens.popl() for _ in range(0, len(tokens))]\n'
else:
# Union[tuple[?], ...]
o += f' {attribute.name} = [{inside_inside_type}.popl() for _ in range(0, len(tokens))]\n'
elif inside_type == 'str':
# Union[str, ...]
o += f' {attribute.name} = tokens.popl()\n'
else:
# Union[?, ...]
o += f' {attribute.name} = {inside_type}.from_mcnp(tokens.popl())\n'

a = False

elif attribute.type.startswith('tuple'):
inside_type = attribute.type[len('tuple[') : -1]

Expand All @@ -256,7 +283,7 @@ def build(self):
entry_attributes = len(self.entries[index].attributes)
o += f' {attribute.name} = {attribute.type}.from_mcnp(" ".join([tokens.popl() for _ in range(0, {entry_attributes})]))\n'
else:
# object
# ?
o += f' {attribute.name} = {attribute.type}.from_mcnp(tokens.popl())\n'

o += '\n'
Expand Down Expand Up @@ -598,6 +625,31 @@ def build(self, name, mnemonic):
elif self.attribute.type == 'str':
o += ' value = tokens.popl()\n'

elif self.attribute.type.startswith('Union'):
inside_types = self.attribute.type[len('Union[') : -1].split(', ')

a = True
for inside_type in inside_types:
o += f' {'if' if a else 'elif'} isinstance(inside_type, {inside_type}):\n'

if inside_type.startswith('tuple'):
inside_inside_type = inside_type[len('tuple[') : -1]

if inside_inside_type == 'str':
# Union[tuple[str], ...]
o += f' {self.attribute.name} = [tokens.popl() for _ in range(0, len(tokens))]\n'
else:
# Union[tuple[?], ...]
o += f' {self.attribute.name} = [{inside_inside_type}.popl() for _ in range(0, len(tokens))]\n'
elif inside_type == 'str':
# Union[str, ...]
o += f' {self.attribute.name} = tokens.popl()\n'
else:
# Union[?, ...]
o += f' {self.attribute.name} = {inside_type}.from_mcnp(tokens.popl())\n'

a = False

else:
o += f' value = {self.attribute.type}.from_mcnp(tokens.popl())\n'

Expand Down
7 changes: 6 additions & 1 deletion src/pymcnp/files/inp/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -1705,7 +1705,12 @@ def to_mcnp(self) -> str:
),
_factory.DataOptionFactory(
'tme',
_factory.AttributeFactory('time', 'types.McnpReal', 'Time in shakes', 'time >= 0'),
_factory.AttributeFactory(
'time',
'Union[types.McnpReal, types.EmbeddedDistributionNumber]',
'Time in shakes',
'time >= 0',
),
),
_factory.DataOptionFactory(
'dir',
Expand Down
Loading

0 comments on commit 2fa13a1

Please sign in to comment.