-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Build: allow partial override of build steps
- Loading branch information
Showing
11 changed files
with
208 additions
and
42 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
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 @@ | ||
_DEFAULT = object() | ||
|
||
|
||
def get_dotted_attribute(obj, attribute, default=_DEFAULT): | ||
""" | ||
Allow to get nested attributes from an object using a dot notation. | ||
This behaves similar to getattr, but allows to get nested attributes. | ||
Similar, if a default value is provided, it will be returned if the | ||
attribute is not found, otherwise it will raise an AttributeError. | ||
""" | ||
for attr in attribute.split("."): | ||
if hasattr(obj, attr): | ||
obj = getattr(obj, attr) | ||
elif default is not _DEFAULT: | ||
return default | ||
else: | ||
raise AttributeError(f"Object {obj} has no attribute {attr}") | ||
return obj | ||
|
||
|
||
def has_dotted_attribute(obj, attribute): | ||
"""Check if an object has a nested attribute using a dot notation.""" | ||
try: | ||
get_dotted_attribute(obj, attribute) | ||
return True | ||
except AttributeError: | ||
return False |
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
Oops, something went wrong.