Skip to content

NameRequired

faststream.broker.schemas.NameRequired #

NameRequired(name: str, **kwargs: Any)

Bases: BaseModel

A class to represent a required name.

METHOD DESCRIPTION
__eq__

object) -> bool: Check if the given value is equal to the current instance.

validate

Type[NameRequiredCls], value: Union[str, NameRequiredCls]) -> NameRequiredCls: Validate the given value and return a NameRequiredCls instance.

validate

Type[NameRequiredCls], value: None) -> None: Validate the given value and return None.

validate

Type[NameRequiredCls], value: Union[str, NameRequiredCls, None]) -> Optional[NameRequiredCls]: Validate the given value and return an optional NameRequiredCls instance.

This is a Python function.

PARAMETER DESCRIPTION
name

The name of the object.

TYPE: str

**kwargs

Additional keyword arguments.

TYPE: Any DEFAULT: {}

RETURNS DESCRIPTION
None

None.

Source code in faststream/broker/schemas.py
def __init__(self, name: str, **kwargs: Any) -> None:
    """This is a Python function.

    Args:
        name (str): The name of the object.
        **kwargs (Any): Additional keyword arguments.

    Returns:
        None.

    """
    super().__init__(name=name, **kwargs)

name class-attribute instance-attribute #

name: str = Field(...)

validate classmethod #

validate(value: Union[str, NameRequiredCls, None], **kwargs: Any) -> Optional[NameRequiredCls]

Validates a value.

PARAMETER DESCRIPTION
value

The value to be validated.

TYPE: Union[str, NameRequiredCls, None]

**kwargs

Additional keyword arguments.

TYPE: Any DEFAULT: {}

RETURNS DESCRIPTION
Optional[NameRequiredCls]

The validated value.

Source code in faststream/broker/schemas.py
@classmethod
def validate(
    cls: Type[NameRequiredCls],
    value: Union[str, NameRequiredCls, None],
    **kwargs: Any,
) -> Optional[NameRequiredCls]:
    """Validates a value.

    Args:
        value: The value to be validated.
        **kwargs: Additional keyword arguments.

    Returns:
        The validated value.

    """
    if value is not None and isinstance(value, str):
        value = cls(value, **kwargs)
    return value