Skip to content

# objects

## `xsdata.utils.objects`

### `update(obj, **kwargs)`

Update an object from keyword arguments with dotted keys.

Source code in `xsdata/utils/objects.py`

     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18

    def update(obj: Any, **kwargs: Any) -> None:
        """Update an object from keyword arguments with dotted keys."""

        def attrsetter(obj: Any, attr: str, value: Any) -> None:
            names = attr.split(".")
            last = names.pop()
            for name in names:
                obj = getattr(obj, name)

            setattr(obj, last, value)

        for key, value in kwargs.items():
            attrsetter(obj, key, value)

### `literal_value(value)`

Return the value for code generation.

Source code in `xsdata/utils/objects.py`

    21
    22
    23
    24
    25
    26
    27
    28
    29

    def literal_value(value: Any) -> str:
        """Return the value for code generation."""
        if isinstance(value, float):
            return str(value) if math.isfinite(value) else f'float("{value}")'

        if isinstance(value, QName):
            return f'QName("{value.text}")'

        return repr(value)