Skip to content

Commit

Permalink
Fixed an issue where initializing a Result object does not correctly …
Browse files Browse the repository at this point in the history
…act as a dict
  • Loading branch information
YHordijk committed Mar 25, 2024
1 parent ff28bdd commit ea105c9
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/tcutility/results/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@
class Result(dict):
'''Class used for storing results from AMS calculations. The class is functionally a dictionary, but allows dot notation to access variables in the dictionary.
The class works case-insensitively, but will retain the case of the key when it was first set.'''
def __init__(self, val=None):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

# if we are casting an object to a Result object
# we will copy all data to this one and all dictionaries will be turned into Result objects
if val and isinstance(val, dict):
# turn every value into a Result object if possible
for key, value in val.items():
if isinstance(value, dict):
self[key] = Result(value)
else:
self[key] = value
# we will copy all data to this one and all dictionaries will be turned into Result object
# turn every value into a Result object if possible
for key, value in self.items():
if isinstance(value, dict):
self[key] = Result(value)
else:
self[key] = value

def __call__(self):
'''Calling of a dictionary subclass should not be possible, instead we raise an error with information about the key and method that were attempted to be called.'''
Expand Down

0 comments on commit ea105c9

Please sign in to comment.