-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
129 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import functools | ||
|
||
|
||
def snake_to_pascal(name): | ||
""" | ||
Converts a snake_case name to pascalCase. | ||
""" | ||
first, *rest = name.split("_") | ||
return "".join([first] + [part.capitalize() for part in rest]) | ||
|
||
|
||
def merge(defaults, *overrides): | ||
""" | ||
Returns a new dictionary obtained by deep-merging multiple sets of overrides | ||
into defaults, with precedence from right to left. | ||
""" | ||
def merge2(defaults, overrides): | ||
if isinstance(defaults, dict) and isinstance(overrides, dict): | ||
merged = defaults.copy() | ||
for key, value in overrides.items(): | ||
if key in defaults: | ||
merged[key] = merge2(defaults[key], value) | ||
else: | ||
merged[key] = value | ||
return merged | ||
else: | ||
return overrides if overrides is not None else defaults | ||
return functools.reduce(merge2, overrides, defaults) |