-
Notifications
You must be signed in to change notification settings - Fork 18
Open
Labels
bugsA deviation from expected behavior that does not reach the level of being reportable as an "Error".A deviation from expected behavior that does not reach the level of being reportable as an "Error".feature requestAn issue that improves the user interface.An issue that improves the user interface.
Description
Is your feature request related to a problem? Please describe.
I was trying to delete the default library for a material (e.g., remove the nlib=...).
I tried:
mat.default_libraries[montepy.NEUTRON] = None # I forgot what the string version of the particle should be.Instead I got:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
Cell In[9], line 1
----> 1 mat.default_libraries[montepy.Particle.NEUTRON] = None
File ~/miniforge3/envs/openmc/lib/python3.12/site-packages/montepy/data_inputs/material.py:63, in _DefaultLibraries.__setitem__(self, key, value)
62 def __setitem__(self, key, value):
---> 63 key = self._validate_key(key)
64 if not isinstance(value, (Library, str)):
65 raise TypeError("")
File ~/miniforge3/envs/openmc/lib/python3.12/site-packages/montepy/data_inputs/material.py:96, in _DefaultLibraries._validate_key(key)
94 raise TypeError("")
95 if not isinstance(key, LibraryType):
---> 96 key = LibraryType(key.upper())
97 return key
File ~/miniforge3/envs/openmc/lib/python3.12/enum.py:751, in EnumType.__call__(cls, value, names, module, qualname, type, start, boundary, *values)
749 if names is not _not_given:
750 value = (value, names) + values
--> 751 return cls.__new__(cls, value)
752 # otherwise, functional API: we're creating a new Enum type
753 if names is _not_given and type is None:
754 # no body? no data-type? possibly wrong usage
File ~/miniforge3/envs/openmc/lib/python3.12/enum.py:1170, in Enum.__new__(cls, value)
1168 ve_exc = ValueError("%r is not a valid %s" % (value, cls.__qualname__))
1169 if result is None and exc is None:
-> 1170 raise ve_exc
1171 elif exc is None:
1172 exc = TypeError(
1173 'error in %s._missing_: returned %r instead of None or a valid member'
1174 % (cls.__name__, result)
1175 )
ValueError: 'N' is not a valid LibraryTypeWhich is a bug. I remember that I should use "nlib", and instead got.
----> 1 mat.default_libraries["nlib"] = None
File ~/miniforge3/envs/openmc/lib/python3.12/site-packages/montepy/data_inputs/material.py:65, in _DefaultLibraries.__setitem__(self, key, value)
63 key = self._validate_key(key)
64 if not isinstance(value, (Library, str)):
---> 65 raise TypeError("")
66 if isinstance(value, str):
67 value = Library(value)
TypeError:Describe the solution you'd like
The only way that currently works is to do:
del mat.default_libraries["nlib"]Additional context
This is a bug and a feature request. A few tasks I see:
- Fix the bug where you can't pass a
montepy.Particle - Actually fill out the
TypeErrormessage - Allow
Nonevalues.
Metadata
Metadata
Assignees
Labels
bugsA deviation from expected behavior that does not reach the level of being reportable as an "Error".A deviation from expected behavior that does not reach the level of being reportable as an "Error".feature requestAn issue that improves the user interface.An issue that improves the user interface.