Skip to content

Commit

Permalink
Make WorkElement attributes explicitly native str type.
Browse files Browse the repository at this point in the history
Make WorkElement.namespace and WorkElement.operation constant member
properties that are initialized as native str whether the client
initializes through the constructor or the class deserialize().

Refs #228
  • Loading branch information
eirrgang committed Jul 2, 2019
1 parent d0ee013 commit 2e60dc8
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/gmx/workflow.py
Expand Up @@ -397,10 +397,10 @@ def __repr__(self):
class WorkElement(object):
"""Encapsulate an element of a work specification."""
def __init__(self, namespace="gmxapi", operation=None, params=None, depends=()):
self.namespace = to_string(namespace)
self._namespace = str(to_string(namespace))
# We can add an operations submodule to validate these. E.g. self.operation = gmx.workflow.operations.normalize(operation)
if operation is not None:
self.operation = to_string(operation)
self._operation = str(to_string(operation))
else:
raise exceptions.UsageError("Invalid argument type for operation.")

Expand All @@ -423,6 +423,16 @@ def __init__(self, namespace="gmxapi", operation=None, params=None, depends=()):
self._name = None
self._workspec = None

@property
def namespace(self):
assert isinstance(self._namespace, str)
return self._namespace

@property
def operation(self):
assert isinstance(self._operation, str)
return self._operation

@property
def name(self):
assert isinstance(self._name, (str, type(None)))
Expand Down

0 comments on commit 2e60dc8

Please sign in to comment.