Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
payno
workflow_concepts
Commits
c1593785
Commit
c1593785
authored
Jun 11, 2021
by
Wout De Nolf
Browse files
VariableContainerNamespace: allow getitem for parameters which cannot be python attributes
parent
d895af36
Changes
1
Hide whitespace changes
Inline
Side-by-side
esrftaskgraph/esrftaskgraph/variable.py
View file @
c1593785
...
...
@@ -334,8 +334,8 @@ class ReadOnlyVariableError(RuntimeError):
pass
class
VariableContainerNamespace
:
"""Expose getting
/setting
variable values through attributes"""
class
ReadOnly
VariableContainerNamespace
:
"""Expose getting variable values through attributes"""
def
__init__
(
self
,
container
):
self
.
_container
=
container
...
...
@@ -349,12 +349,16 @@ class VariableContainerNamespace:
return
cls
.
_RESERVED_VARIABLE_NAMES
def
__setattr__
(
self
,
name
,
value
):
if
name
in
self
.
_reserved_variable_names
()
:
if
name
==
"_container"
:
super
().
__setattr__
(
name
,
value
)
else
:
self
.
_get_variable
(
name
).
value
=
value
self
.
_get_variable
(
name
)
raise
ReadOnlyVariableError
(
name
)
def
__getattr__
(
self
,
name
):
return
self
[
name
]
def
__getitem__
(
self
,
name
):
return
self
.
_get_variable
(
name
).
value
def
_get_variable
(
self
,
name
):
...
...
@@ -364,9 +368,11 @@ class VariableContainerNamespace:
raise
MissingVariableError
(
name
)
class
ReadOnlyVariableContainerNamespace
(
VariableContainerNamespace
):
class
VariableContainerNamespace
(
ReadOnlyVariableContainerNamespace
):
"""Expose getting/setting variable values through attributes"""
def
__setattr__
(
self
,
name
,
value
):
if
name
in
self
.
_reserved_variable_names
()
:
super
(
VariableContainerNamespace
,
self
).
__setattr__
(
name
,
value
)
if
name
==
"_container"
:
super
().
__setattr__
(
name
,
value
)
else
:
raise
ReadOnlyV
ariable
Error
(
name
)
self
.
_get_v
ariable
(
name
)
.
value
=
value
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment