bidsbuilder.util.hooks.descriptors¶
- class CallbackBase¶
Bases:
Generic[VAL]Callback base allows for tags to be passed, moreover it also sets the name of the raw attribute to be the same as the name of the descriptor with an underscore, i.e. ‘_test’ for ‘test’
this is used to support local data storage for slotted classes
- __init__(*, tags=None, default=None, **kwargs)¶
- Parameters:
tags (list | str | None)
default (Any)
- Return type:
None
- class CallbackGetterMixin¶
Bases:
objectMixin for descriptors that have a custom getter method which is given as a parameter
i.e. for Suffix, Entity, or Datatype, where the custom getter can search parent instances if the current instance does not have the value set
- __init__(*, fget, **kwargs)¶
- Parameters:
fget (Callable[[Instance, Descriptor, Owner], VAL])
- Return type:
None
- class CallbackNoGetterMixin¶
Bases:
objectMixin for descriptors that do not have a getter method, i.e. they use the default getter
- class DescriptorProtocol¶
Bases:
Generic[VAL]DescriptorProtocol is a protocol that defines the methods and attributes that a descriptor must implement. It is used to type hint the descriptor classes. This allows for better type checking and code completion in IDEs.
- __init__(*, tags=None, **kwargs)¶
- Parameters:
self (Self)
tags (list | str | None)
- Return type:
None
-
name:
str¶
- HookedDescriptor(type_hint, **kwargs)¶
- Return type:
DescriptorProtocol[TypeVar(VAL)]- Parameters:
type_hint (type[VAL])
kwargs (Unpack[callbackKwargs])
- class PerInstanceCallbackMixin¶
Bases:
objectMixin for per-instance callbacks, i.e. each instance of the descriptor can have its own callback/callbacks
Useful for attributes such as exists, enabling callback checking for other objects which depend on their exists value. I.e. dataset_description is dependent on genetic_info existing.
- __init__(**kwargs)¶
- Return type:
None
- add_callback(instance, callback)¶
Adds a callback (a class method) for this attribute of the given instance The callback will trigger when setting the attribute to a new value, appending or changing keys for lists and dictionaries as well
This method will only work for class methods, if it is a regular function then it is not supported (can be done but need to use weakref.ref() instead)
- Return type:
None- Parameters:
instance (Instance)
callback (Callable[[list | str | None], Any])
- class PlainMixin¶
Bases:
objectmixin for descriptors who’s value is a plain value, i.e. str, or int, or float.
- class PlainValMixin¶
Bases:
objectmixin for descriptors who’s value is a plain value, i.e. str, or int, or float, and includes a validator
- __init__(*, fval, **kwargs)¶
- Parameters:
fval (Callable[[Instance, Descriptor, Any], VAL])
- class SingleCallbackMixin¶
Bases:
objectMixin for single callbacks, i.e. only one callback can be registered for this field and is applied to all instances of the descriptor
at the time of writing, this is used for the callbacks of “parent” attributes. i.e. Entity, Suffix, or datatype, where the single callback is defined to make each “child” and the parent itself check their schema / update their tree name reference
- __init__(*, callback, **kwargs)¶
- Parameters:
callback (Callable[[Instance, list | str | None], Any])
- Return type:
None
- class callbackKwargs¶
Bases:
TypedDict- __init__(*args, **kwargs)¶
- classmethod __new__(*args, **kwargs)¶
-
callback:
Callable[[TypeVar(Instance, bound= object),Union[list,str,None]],Any]¶
- clear()¶
Remove all items from the dict.
- copy()¶
Return a shallow copy of the dict.
-
default:
Any¶
-
factory:
Callable[[TypeVar(Instance, bound= object),TypeVar(Descriptor, bound= DescriptorProtocol)],Union[type,object]]¶
-
fget:
Callable[[TypeVar(Instance, bound= object),TypeVar(VAL),TypeVar(Descriptor, bound= DescriptorProtocol)],TypeVar(VAL)]¶
- classmethod fromkeys(iterable, value=None, /)¶
Create a new dictionary with keys from iterable and values set to value.
-
fval:
Callable[[TypeVar(Instance, bound= object),TypeVar(Descriptor, bound= DescriptorProtocol),Any],TypeVar(VAL)]¶
- get(key, default=None, /)¶
Return the value for key if key is in the dictionary, else default.
- items()¶
Return a set-like object providing a view on the dict’s items.
- keys()¶
Return a set-like object providing a view on the dict’s keys.
- pop(k[, d]) v, remove specified key and return the corresponding value.¶
If the key is not found, return the default if given; otherwise, raise a KeyError.
- popitem()¶
Remove and return a (key, value) pair as a 2-tuple.
Pairs are returned in LIFO (last-in, first-out) order. Raises KeyError if the dict is empty.
- setdefault(key, default=None, /)¶
Insert key with a value of default if key is not in the dictionary.
Return the value for key if key is in the dictionary, else default.
-
tags:
Union[list,str,None]¶
- update([E, ]**F) None. Update D from mapping/iterable E and F.¶
If E is present and has a .keys() method, then does: for k in E.keys(): D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]
- values()¶
Return an object providing a view on the dict’s values.