Skip to content

Commit

Permalink
refactor: robust dictionary access
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrugman committed Jun 14, 2022
1 parent 17ac6d8 commit f438394
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions popmon/analysis/profiling/profiles.py
Expand Up @@ -22,7 +22,7 @@

class Profiles:
_profile_descriptions = {}
_profile_funcs = {-1: {}, 1: {}, 2: {}}
_profile_funcs = {-1: {}}

@classmethod
def register(
Expand All @@ -46,6 +46,9 @@ def f(func: Callable):
cls._profile_descriptions[k] = d
else:
cls._profile_descriptions[key] = description

if dim not in cls._profile_funcs:
cls._profile_funcs[dim] = {}
cls._profile_funcs[dim][(key, htype)] = func
return func

Expand All @@ -65,7 +68,7 @@ def merge(d1, d2):
if dim is None:
v = cls._profile_funcs[-1]
else:
v = merge(cls._profile_funcs[dim], cls._profile_funcs[-1])
v = merge(cls._profile_funcs.get(dim, {}), cls._profile_funcs[-1])

return v

Expand Down

0 comments on commit f438394

Please sign in to comment.