mirror of
https://github.com/wassname/segpy.git
synced 2026-06-27 18:25:38 +08:00
Adds a true() function which always returns True.
This commit is contained in:
+29
-1
@@ -446,4 +446,32 @@ def ensure_superset(superset, subset):
|
||||
if not is_superset(superset, subset):
|
||||
raise ValueError("subset_or_slice {!r} is not a subset of all_items {!r}"
|
||||
.format(subset, superset))
|
||||
return subset
|
||||
return subset
|
||||
|
||||
def true(*args, **kwargs):
|
||||
return True
|
||||
|
||||
|
||||
def collect_attributes(derived_class, base_class=object, predicate=None):
|
||||
"""
|
||||
|
||||
Args:
|
||||
derived_class: The class at which to start searching.
|
||||
base_class: The class at which to stop searching
|
||||
predicate: A predicate which accepts
|
||||
|
||||
Returns:
|
||||
A generator of items containing the (class, attribute_name)
|
||||
"""
|
||||
# TODO: Consider using the inspect module to do this
|
||||
if predicate is None:
|
||||
predicate = true
|
||||
|
||||
for cls in derived_class.__mro__:
|
||||
for key, value in vars(cls).items():
|
||||
if predicate(key, value):
|
||||
yield cls, key, value
|
||||
if cls is base_class:
|
||||
break
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user