diff options
| author | smosker <[email protected]> | 2022-02-10 16:48:21 +0300 | 
|---|---|---|
| committer | Daniil Cherednik <[email protected]> | 2022-02-10 16:48:21 +0300 | 
| commit | dd14d17a747a9c259858faf2fcc3ea6b92df4e15 (patch) | |
| tree | f332cd81782832c17c48d8c3b4511924cd9e47fd /contrib/python/attrs/attr/_funcs.py | |
| parent | b637e2fa3213638fbabe52c15dad14c8237945ac (diff) | |
Restoring authorship annotation for <[email protected]>. Commit 1 of 2.
Diffstat (limited to 'contrib/python/attrs/attr/_funcs.py')
| -rw-r--r-- | contrib/python/attrs/attr/_funcs.py | 208 | 
1 files changed, 104 insertions, 104 deletions
| diff --git a/contrib/python/attrs/attr/_funcs.py b/contrib/python/attrs/attr/_funcs.py index fda508c5c4b..0073198f0f8 100644 --- a/contrib/python/attrs/attr/_funcs.py +++ b/contrib/python/attrs/attr/_funcs.py @@ -7,14 +7,14 @@ from ._make import NOTHING, _obj_setattr, fields  from .exceptions import AttrsAttributeNotFoundError -def asdict( -    inst, -    recurse=True, -    filter=None, -    dict_factory=dict, -    retain_collection_types=False, +def asdict(  +    inst,  +    recurse=True,  +    filter=None,  +    dict_factory=dict,  +    retain_collection_types=False,       value_serializer=None, -): +):       """      Return the ``attrs`` attribute values of *inst* as a dict. @@ -59,49 +59,49 @@ def asdict(          if recurse is True:              if has(v.__class__): -                rv[a.name] = asdict( +                rv[a.name] = asdict(                       v,                      True,                      filter,                      dict_factory,                      retain_collection_types,                      value_serializer, -                ) +                )               elif isinstance(v, (tuple, list, set, frozenset)):                  cf = v.__class__ if retain_collection_types is True else list -                rv[a.name] = cf( -                    [ -                        _asdict_anything( +                rv[a.name] = cf(  +                    [  +                        _asdict_anything(                               i,                              filter,                              dict_factory,                              retain_collection_types,                              value_serializer, -                        ) -                        for i in v -                    ] -                ) +                        )  +                        for i in v  +                    ]  +                )               elif isinstance(v, dict):                  df = dict_factory -                rv[a.name] = df( -                    ( -                        _asdict_anything( +                rv[a.name] = df(  +                    (  +                        _asdict_anything(                               kk,                              filter,                              df,                              retain_collection_types,                              value_serializer, -                        ), -                        _asdict_anything( +                        ),  +                        _asdict_anything(                               vv,                              filter,                              df,                              retain_collection_types,                              value_serializer, -                        ), -                    ) -                    for kk, vv in iteritems(v) -                ) +                        ),  +                    )  +                    for kk, vv in iteritems(v)  +                )               else:                  rv[a.name] = v          else: @@ -117,10 +117,10 @@ def _asdict_anything(      value_serializer,  ):      """ -    ``asdict`` only works on attrs instances, this works on anything. -    """ -    if getattr(val.__class__, "__attrs_attrs__", None) is not None: -        # Attrs class. +    ``asdict`` only works on attrs instances, this works on anything.  +    """  +    if getattr(val.__class__, "__attrs_attrs__", None) is not None:  +        # Attrs class.           rv = asdict(              val,              True, @@ -130,48 +130,48 @@ def _asdict_anything(              value_serializer,          )      elif isinstance(val, (tuple, list, set, frozenset)): -        cf = val.__class__ if retain_collection_types is True else list -        rv = cf( -            [ -                _asdict_anything( +        cf = val.__class__ if retain_collection_types is True else list  +        rv = cf(  +            [  +                _asdict_anything(                       i,                      filter,                      dict_factory,                      retain_collection_types,                      value_serializer, -                ) -                for i in val -            ] -        ) -    elif isinstance(val, dict): -        df = dict_factory -        rv = df( -            ( +                )  +                for i in val  +            ]  +        )  +    elif isinstance(val, dict):  +        df = dict_factory  +        rv = df(  +            (                   _asdict_anything(                      kk, filter, df, retain_collection_types, value_serializer                  ),                  _asdict_anything(                      vv, filter, df, retain_collection_types, value_serializer                  ), -            ) -            for kk, vv in iteritems(val) -        ) -    else: -        rv = val +            )  +            for kk, vv in iteritems(val)  +        )  +    else:  +        rv = val           if value_serializer is not None:              rv = value_serializer(None, None, rv) -    return rv - - -def astuple( -    inst, -    recurse=True, -    filter=None, -    tuple_factory=tuple, -    retain_collection_types=False, -): -    """ +    return rv  +  +  +def astuple(  +    inst,  +    recurse=True,  +    filter=None,  +    tuple_factory=tuple,  +    retain_collection_types=False,  +):  +    """       Return the ``attrs`` attribute values of *inst* as a tuple.      Optionally recurse into other ``attrs``-decorated classes. @@ -206,56 +206,56 @@ def astuple(              continue          if recurse is True:              if has(v.__class__): -                rv.append( -                    astuple( -                        v, -                        recurse=True, -                        filter=filter, -                        tuple_factory=tuple_factory, -                        retain_collection_types=retain, -                    ) -                ) +                rv.append(  +                    astuple(  +                        v,  +                        recurse=True,  +                        filter=filter,  +                        tuple_factory=tuple_factory,  +                        retain_collection_types=retain,  +                    )  +                )               elif isinstance(v, (tuple, list, set, frozenset)):                  cf = v.__class__ if retain is True else list -                rv.append( -                    cf( -                        [ -                            astuple( -                                j, -                                recurse=True, -                                filter=filter, -                                tuple_factory=tuple_factory, -                                retain_collection_types=retain, -                            ) -                            if has(j.__class__) -                            else j -                            for j in v -                        ] -                    ) -                ) +                rv.append(  +                    cf(  +                        [  +                            astuple(  +                                j,  +                                recurse=True,  +                                filter=filter,  +                                tuple_factory=tuple_factory,  +                                retain_collection_types=retain,  +                            )  +                            if has(j.__class__)  +                            else j  +                            for j in v  +                        ]  +                    )  +                )               elif isinstance(v, dict):                  df = v.__class__ if retain is True else dict -                rv.append( -                    df( +                rv.append(  +                    df(                           (                              astuple(                                  kk,                                  tuple_factory=tuple_factory, -                                retain_collection_types=retain, -                            ) -                            if has(kk.__class__) -                            else kk, +                                retain_collection_types=retain,  +                            )  +                            if has(kk.__class__)  +                            else kk,                               astuple(                                  vv,                                  tuple_factory=tuple_factory, -                                retain_collection_types=retain, -                            ) -                            if has(vv.__class__) -                            else vv, +                                retain_collection_types=retain,  +                            )  +                            if has(vv.__class__)  +                            else vv,                           ) -                        for kk, vv in iteritems(v) -                    ) -                ) +                        for kk, vv in iteritems(v)  +                    )  +                )               else:                  rv.append(v)          else: @@ -294,21 +294,21 @@ def assoc(inst, **changes):          Use `evolve` instead.      """      import warnings - -    warnings.warn( -        "assoc is deprecated and will be removed after 2018/01.", -        DeprecationWarning, -        stacklevel=2, -    ) +  +    warnings.warn(  +        "assoc is deprecated and will be removed after 2018/01.",  +        DeprecationWarning,  +        stacklevel=2,  +    )       new = copy.copy(inst)      attrs = fields(inst.__class__)      for k, v in iteritems(changes):          a = getattr(attrs, k, NOTHING)          if a is NOTHING:              raise AttrsAttributeNotFoundError( -                "{k} is not an attrs attribute on {cl}.".format( -                    k=k, cl=new.__class__ -                ) +                "{k} is not an attrs attribute on {cl}.".format(  +                    k=k, cl=new.__class__  +                )               )          _obj_setattr(new, k, v)      return new | 
