Skip to content

Commit

Permalink
fixing up/removing todos
Browse files Browse the repository at this point in the history
  • Loading branch information
jbleon95 committed Mar 18, 2024
1 parent e57c1a4 commit 5fd67cc
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
8 changes: 6 additions & 2 deletions api/src/opentrons/protocol_api/_parameters.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Dict, Optional, Any

from opentrons.protocols.parameters.types import AllowedTypes
from opentrons.protocols.parameters.types import AllowedTypes, ParameterNameError


class Parameters:
Expand All @@ -14,14 +14,18 @@ def _getparam(self, variable_name: str) -> Any:
return getattr(self, f"_{variable_name}")

def _initialize_parameter(self, variable_name: str, value: AllowedTypes) -> None:
# TODO raise an error if the variable name already exists to prevent overwriting anything important
if not hasattr(self, variable_name) and not hasattr(self, f"_{variable_name}"):
setattr(self, f"_{variable_name}", value)
prop = property(
fget=lambda s, v=variable_name: Parameters._getparam(s, v) # type: ignore[misc]
)
setattr(Parameters, variable_name, prop)
self._values[variable_name] = value
else:
raise ParameterNameError(
f"Cannot use {variable_name} as a variable name, either duplicates another"
f" parameter name, Opentrons reserved function, or Python built-in"
)

def get_all(self) -> Dict[str, AllowedTypes]:
return self._values
1 change: 0 additions & 1 deletion api/src/opentrons/protocols/parameters/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ class ParameterChoices(TypedDict):
value: AllowedTypes


# TODO these should inherit from shared_data exceptions
class ParameterValueError(ValueError):
"""An error raised when a parameter value is not valid."""

Expand Down
2 changes: 1 addition & 1 deletion api/src/opentrons/protocols/parameters/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def ensure_variable_name(variable_name: str) -> str:
"Variable name must only contain alphanumeric characters, underscores, and cannot start with a digit."
)
if keyword.iskeyword(variable_name):
raise ParameterNameError("Variable name cannot be a reserved Python key word.")
raise ParameterNameError("Variable name cannot be a reserved Python keyword.")
return variable_name


Expand Down

0 comments on commit 5fd67cc

Please sign in to comment.