Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
BIP
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
FSL
BIP
Commits
74b21b0e
Commit
74b21b0e
authored
2 years ago
by
Paul McCarthy
Browse files
Options
Downloads
Patches
Plain Diff
RF: Disallow overwriting config settings via python attribute assignment
parent
7f8a7a93
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!4
ENH: Config file templating
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
bip/utils/config.py
+20
-1
20 additions, 1 deletion
bip/utils/config.py
with
20 additions
and
1 deletion
bip/utils/config.py
+
20
−
1
View file @
74b21b0e
...
...
@@ -56,6 +56,12 @@ specifying a directory.
"""
class
ConfigError
(
Exception
):
"""
Custom Exception class used by the Config class. Raised by
Config.__setattr__ on attempts to overwrite a configuration setting.
"""
def
nested_lookup
(
d
,
key
):
"""
Look up a value in a nested dictionary based on the given key.
For example, imagine we have a dictionary d:
...
...
@@ -443,7 +449,20 @@ class Config:
def
__getattr__
(
self
,
key
):
"""
Return the configuration item with the specified key.
"""
return
self
[
key
]
try
:
return
self
[
key
]
except
KeyError
:
raise
AttributeError
(
key
)
def
__setattr__
(
self
,
key
,
value
):
"""
Raise an error on attempts to modify a setting value.
"""
# Ignore the initial self.__settings assignment,
# otherwise we infinitely recurse.
if
key
!=
'
_Config__settings
'
and
key
in
self
:
raise
ConfigError
(
f
'
Attempt to overwrite config value
'
f
'
{
key
}
(value:
{
value
}
)
'
)
super
().
__setattr__
(
key
,
value
)
def
get
(
self
,
key
,
default
=
None
):
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment