soleil.resolvers.modifiers#

Module Attributes

hidden

The member should not be passed as an argument to type

visible

The member should be passed as a type arg

name(value)

Change the name of the member when passed as a type arg

cast(value)

Used to format the value after pre-processing but before resolution

noid

Indicates that the specified member should not be used by soleil.utils.id_str()

Functions

cast(value)

Used to format the value after pre-processing but before resolution

from_annotation(annotation)

Converts the annotation to a Modifiers object or returns None if the annotation does not specify a Modifiers.

merge_modifiers(*modifiers)

Fails if there are clashing values.

name(value)

Change the name of the member when passed as a type arg

Classes

Modifiers([dict])

To be used as a type hint or class decorator that modifies the behaviour of annotated members of a resolvable object.

class soleil.resolvers.modifiers.Modifiers(dict=None, /, **kwargs)#

Bases: UserDict

To be used as a type hint or class decorator that modifies the behaviour of annotated members of a resolvable object. Supported entries of this modifier depend on the resolver.

Pre-instantiated modifier objects or object factories that make code more readable are provided as part of various soleil modules:

  • name(value:str): Specifies that the annotated member should be passed to its type with this name instead of its declared variable name.

  • hidden : The annotated member should not be passed to its type.

  • cast(value:Callable): The value assigned to the member will be mapped with this callable before resolution.

  • promoted: Valid only to annotate root-level members of solconf modules. The promoted member will be returned when the module is loaded instead of the module itself, and

    CLI override variable paths that point to the containing module will instead be re-directed to the annotated member. Modules resolved with a promoted member (assuming the default module type)

Note that modifiers can be changed in derived classes without changing the class value.

class A:
   a = 1

class B(A):
   a:hidden

Modifiers can be applied to classes by using value-less annotation declarations:

A:(hidden, noid)

class A:
    ...

Alternatively, all modifier objects can be used as class decorators:

@hidden
@noid
class A:
    ...
merge(modifs: Modifiers)#

Fails if there are clashing values

__call__(cls)#

Used to allow the modifiers object to decorate classes.

Appends the specified modifier to the class

soleil.resolvers.modifiers.hidden = {'hidden': True}#

The member should not be passed as an argument to type

soleil.resolvers.modifiers.visible = {'hidden': False}#

The member should be passed as a type arg

soleil.resolvers.modifiers.name(value)#

Change the name of the member when passed as a type arg

soleil.resolvers.modifiers.cast(value)#

Used to format the value after pre-processing but before resolution

soleil.resolvers.modifiers.noid = {'noid': True}#

Indicates that the specified member should not be used by soleil.utils.id_str()

soleil.resolvers.modifiers.merge_modifiers(*modifiers: Modifiers)#

Fails if there are clashing values. The type of the output will be that of the most-specialized modifier in the inputs.

soleil.resolvers.modifiers.from_annotation(annotation: Modifiers | Tuple[Modifiers]) None | Modifiers#

Converts the annotation to a Modifiers object or returns None if the annotation does not specify a Modifiers. If the input is a tuple, the returned object is the merge of all the modifiers. An exception is raised if only some but not all tuple members are Modifiers.