var/opt/nydus/ops/attr/__pycache__/_funcs.cpython-38.pyc000064400000027475147205560250017215 0ustar00U afC@sddlZddlmZmZddlmZmZmZddlm Z dde ddfdd Z d d Z dde dfd d ZddZddZddZdddZdS)N) PY_3_9_PLUSget_generic_base) _OBJ_SETATTRNOTHINGfields)AttrsAttributeNotFoundErrorTFc sRt|j}}|D]6}t||j} dk r:|| s:qdk rN||| } |dkrBt| jr~t| dd||j<nt| ttt t frdkr| jnt} fdd| D} z| | ||j<Wn.t k rt | ts| | ||j<YnXnBt| t r6fdd| D||j<n | ||j<q| ||j<q|S)a Return the *attrs* attribute values of *inst* as a dict. Optionally recurse into other *attrs*-decorated classes. Args: inst: Instance of an *attrs*-decorated class. recurse (bool): Recurse into classes that are also *attrs*-decorated. filter (~typing.Callable): A callable whose return code determines whether an attribute or element is included (`True`) or dropped (`False`). Is called with the `attrs.Attribute` as the first argument and the value as the second argument. dict_factory (~typing.Callable): A callable to produce dictionaries from. For example, to produce ordered dictionaries instead of normal Python dictionaries, pass in ``collections.OrderedDict``. retain_collection_types (bool): Do not convert to `list` when encountering an attribute whose type is `tuple` or `set`. Only meaningful if *recurse* is `True`. value_serializer (typing.Callable | None): A hook that is called for every attribute or dict key/value. It receives the current instance, field and value and must return the (updated) value. The hook is run *after* the optional *filter* has been applied. Returns: Return type of *dict_factory*. Raises: attrs.exceptions.NotAnAttrsClassError: If *cls* is not an *attrs* class. .. versionadded:: 16.0.0 *dict_factory* .. versionadded:: 16.1.0 *retain_collection_types* .. versionadded:: 20.3.0 *value_serializer* .. versionadded:: 21.3.0 If a dict has a collection for a key, it is serialized as a tuple. NTrecursefilter dict_factoryretain_collection_typesvalue_serializerc s g|]}t|ddqSFis_keyr r r r_asdict_anything.0ir r r rUs zasdict..c 3s:|]2\}}t|ddt|ddfVqdSTrFNrrkkvvdfr r rrr js$zasdict..)r __class__getattrnamehasasdict isinstancetuplelistset frozenset TypeError issubclassdictitems) instr r r r rattrsrvavcfr/rr r r r rrr& sJ4            r&cst|jdddk r(t|dd}nt|ttttfrvdkrJ|j}n|rTt}nt}|fdd|D}nHt|trfdd| D}n|}dk rdd|}|S) zK ``asdict`` only works on attrs instances, this works on anything. __attrs_attrs__NTr c s g|]}t|ddqSrrrrrrrs z$_asdict_anything..c 3s:|]2\}}t|ddt|ddfVqdSrrrrrrr!s$z#_asdict_anything..) r#r"r&r'r(r)r*r+r.r/)valrr r r rr2r5rr6rrs:     rc sZt|j}g}||D]*}t||j}dk r<||s.c3sJ|]B\}}t|jr"t|dn|t|jr.)rr"r#r$r%appendr<r'r(r)r*r+r,r-r.r/) r0r r r:r r1r2r3r4r5r/r rr>rr<sN*           r<cCsNt|dd}|dk rdSt|}|dk rJt|dd}|dk rB||_|dk SdS)z Check whether *cls* is a class with *attrs* attributes. Args: cls (type): Class to introspect. Raises: TypeError: If *cls* is not a class. Returns: bool: r7NTF)r#rr7)clsr1Z generic_baseZ generic_attrsrrrr%Fs  r%cKsdt|}t|j}|D]B\}}t||t}|tkrR|d|jd}t|t|||q|S)a Copy *inst* and apply *changes*. This is different from `evolve` that applies the changes to the arguments that create the new instance. `evolve`'s behavior is preferable, but there are `edge cases`_ where it doesn't work. Therefore `assoc` is deprecated, but will not be removed. .. _`edge cases`: https://github.com/python-attrs/attrs/issues/251 Args: inst: Instance of a class with *attrs* attributes. changes: Keyword changes in the new copy. Returns: A copy of inst with *changes* incorporated. Raises: attrs.exceptions.AttrsAttributeNotFoundError: If *attr_name* couldn't be found on *cls*. attrs.exceptions.NotAnAttrsClassError: If *cls* is not an *attrs* class. .. deprecated:: 17.1.0 Use `attrs.evolve` instead if you can. This function will not be removed du to the slightly different approach compared to `attrs.evolve`, though. z is not an attrs attribute on .)copyrr"r/r#rrr)r0changesnewr1kr4r3msgrrrassocbs   rHc Osz |\}Wn.tk r8dt|d}t|dYnX|j}t|}|D].}|jsXqL|j}|j}||krLt||||<qL|f|S)a Create a new instance, based on the first positional argument with *changes* applied. Args: inst: Instance of a class with *attrs* attributes. *inst* must be passed as a positional argument. changes: Keyword changes in the new copy. Returns: A copy of inst with *changes* incorporated. Raises: TypeError: If *attr_name* couldn't be found in the class ``__init__``. attrs.exceptions.NotAnAttrsClassError: If *cls* is not an *attrs* class. .. versionadded:: 17.1.0 .. deprecated:: 23.1.0 It is now deprecated to pass the instance using the keyword argument *inst*. It will raise a warning until at least April 2024, after which it will become an error. Always pass the instance as a positional argument. .. versionchanged:: 24.1.0 *inst* can't be passed as a keyword argument anymore. z*evolve() takes 1 positional argument, but z were givenN) ValueErrorlenr,r"rinitr$aliasr#) argsrDr0rGrAr1r3 attr_nameZ init_namerrrevolves ! rOc Cs|t|dd|krxddl}||d}tr.||d<|j|f|}|dkrLt|n|D] }|j|krPt|d||jqP||_|S)a Resolve any strings and forward annotations in type annotations. This is only required if you need concrete types in :class:`Attribute`'s *type* field. In other words, you don't need to resolve your types if you only use them for static type checking. With no arguments, names will be looked up in the module in which the class was created. If this is not what you want, for example, if the name only exists inside a method, you may pass *globalns* or *localns* to specify other dictionaries in which to look up these names. See the docs of `typing.get_type_hints` for more details. Args: cls (type): Class to resolve. globalns (dict | None): Dictionary containing global variables. localns (dict | None): Dictionary containing local variables. attribs (list | None): List of attribs for the given class. This is necessary when calling from inside a ``field_transformer`` since *cls* is not an *attrs* class yet. include_extras (bool): Resolve more accurately, if possible. Pass ``include_extras`` to ``typing.get_hints``, if supported by the typing module. On supported Python versions (3.9+), this resolves the types more accurately. Raises: TypeError: If *cls* is not a class. attrs.exceptions.NotAnAttrsClassError: If *cls* is not an *attrs* class and you didn't pass any attribs. NameError: If types cannot be resolved because of missing variables. Returns: *cls* so you can use this function also as a class decorator. Please note that you have to apply it **after** `attrs.define`. That means the decorator has to come in the line **before** `attrs.define`. .. versionadded:: 20.1.0 .. versionadded:: 21.1.0 *attribs* .. versionadded:: 23.1.0 *include_extras* __attrs_types_resolved__Nr)globalnslocalnsinclude_extrastype)r#typingrget_type_hintsrr$rrP) rArQrRZattribsrSrUkwargshintsfieldrrr resolve_typess5  rZ)NNNT)rCZ_compatrr_makerrr exceptionsrr.r&rr(r<r%rHrOrZrrrrs.  {K w+7