L iq *ddlZddlmZdZ ddZy)N) iskeywordcp|g|z|zD]T}t|ts td|jst d|t |sHt d|t }||zD]D}|jdrt d|||vrt d||j|Fy)z Ensure that all the given names are valid Python identifiers that do not start with '_'. Also check that there are no duplicates among field_names + extra_field_names. z,typename and all field names must be stringsz8typename and all field names must be valid identifiers: z2typename and all field names cannot be a keyword: _z-Field names cannot start with an underscore: zDuplicate field name: N) isinstancestr TypeError isidentifier ValueError _iskeywordset startswithadd)typename field_namesextra_field_namesnameseens W/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/scipy/_lib/_bunch.py_validate_namesrs  [(+<<3$$JK K  "--1H67 7 d ))-23 33 5D// ??3 L $x)* * 4<5dX>? ?  c t|dk(r td|g}t|||tjt |}t ttj|}t ttj|}||z}dj|}dj|}djddjd|Ddft j}tt tcd |d |d |d t|d }~|tttd|d} t|| | d} d|d|d| _| d} d|d|d| _| d} fd} fd}fd}| | ||fD]}|d|j"|_|d|d|| | | | |||idd }t'|D]\}}|fd}t)|||<|D]}|fd}t)|||<t+|t f|}|0 tj,dj.j1dd}|||_|| _|S#ttf$rY#wxYw) a Create a namedtuple-like class with additional attributes. This function creates a subclass of tuple that acts like a namedtuple and that has additional attributes. The additional attributes are listed in `extra_field_names`. The values assigned to these attributes are not part of the tuple. The reason this function exists is to allow functions in SciPy that currently return a tuple or a namedtuple to returned objects that have additional attributes, while maintaining backwards compatibility. This should only be used to enhance *existing* functions in SciPy. New functions are free to create objects as return values without having to maintain backwards compatibility with an old tuple or namedtuple return value. Parameters ---------- typename : str The name of the type. field_names : list of str List of names of the values to be stored in the tuple. These names will also be attributes of instances, so the values in the tuple can be accessed by indexing or as attributes. At least one name is required. See the Notes for additional restrictions. extra_field_names : list of str, optional List of names of values that will be stored as attributes of the object. See the notes for additional restrictions. Returns ------- cls : type The new class. Notes ----- There are restrictions on the names that may be used in `field_names` and `extra_field_names`: * The names must be unique--no duplicates allowed. * The names must be valid Python identifiers, and must not begin with an underscore. * The names must not be Python keywords (e.g. 'def', 'and', etc., are not allowed). Examples -------- >>> from scipy._lib._bunch import _make_tuple_bunch Create a class that acts like a namedtuple with length 2 (with field names `x` and `y`) that will also have the attributes `w` and `beta`: >>> Result = _make_tuple_bunch('Result', ['x', 'y'], ['w', 'beta']) `Result` is the new class. We call it with keyword arguments to create a new instance with given values. >>> result1 = Result(x=1, y=2, w=99, beta=0.5) >>> result1 Result(x=1, y=2, w=99, beta=0.5) `result1` acts like a tuple of length 2: >>> len(result1) 2 >>> result1[:] (1, 2) The values assigned when the instance was created are available as attributes: >>> result1.y 2 >>> result1.beta 0.5 rz*field_names must contain at least one nameNz, (c3,K|] }|d|dyw)z=%(z)rN).0rs r z$_make_tuple_bunch..s!M4TF#dV2"6!Ms)zdef __new__(_cls, z0, **extra_fields): return _tuple_new(_cls, (z,)) def __init__(self, a, **extra_fields): for key in self._extra_fields: if key not in extra_fields: raise TypeError("missing keyword argument '%s'" % (key,)) for key, val in extra_fields.items(): if key not in self._extra_fields: raise TypeError("unexpected keyword argument '%s'" % (key,)) self.__dict__[key] = val def __setattr__(self, key, val): if key in z: raise AttributeError("can't set attribute %r of class %r" % (key, self.__class__.__name__)) else: self.__dict__[key] = val )rAttributeError namedtuple_) _tuple_new __builtins____name____new__zCreate new instance of __init__zInstantiate instance of __setattr__cX|jj|jzzS)z/Return a nicely formatted representation string) __class__r#_asdict)selfrepr_fmts r__repr__z#_make_tuple_bunch..__repr__s#~~&&DLLN)BBBrcp|j|}|j|j|S)z9Return a new dict which maps field names to their values.)_fieldsupdate__dict__)r*out_dict_zips rr)z"_make_tuple_bunch.._asdicts-Dt,- 4==! rc,||jfS)z7Return self as a plain tuple. Used by copy and pickle.r0)r*_tuples r__getnewargs_ex__z,_make_tuple_bunch..__getnewargs_ex__sd|T]]**r.) __doc__r.r$r%r,r&r) _extra_fieldsr7_field_defaults_replacec ||SNr)r*indexs r_getz_make_tuple_bunch.._gets ; rc |j|Sr>r5)r*rs rr@z_make_tuple_bunch.._gets==& &rr#__main__)lenr r_sysinternrtuplemapjoinr$dictzipreprrrexecr9r# __qualname__ enumeratepropertytype _getframe f_globalsget __module__)rrrmodule all_namesarg_list full_list tuple_news namespacer$r%r&r,r)r7methodclass_namespacer?rr@resultr2r6r3r+s @@@@r_make_tuple_bunchr` sb ;1EFF Hk+<={{3x=)HDKK56Kc$++/@AB//Iyy%H )$Iww !M9!MMH IsE64 *&Z(: K !" A( (!% 5C"E*8*57I I "G/z9+QGGO$H1(1YKqIHM*KC + Hg/@A>!) !FOO+<=> Zq 1-"*.O!-/ t"  ( / "/  ' ( / (UHo 6F~ ^^A&0044ZLF"# M  +   s /II I )NN)sysrEkeywordrr rr`rrrrcs +6@D!Er