Current File : //proc/self/root/usr/lib/python3/dist-packages/pyrsistent/__pycache__/_immutable.cpython-312.pyc |
�
n�9e� � � � d dl Z dd�Zy)� Nc � � � t � t � r � j dd� j � � � fd�}dj d� � D � � }dj ||rd|z nd |� |� � }|rt
|� d
dlm} t |d�
� } t ||� || S # t $ r }t t |� dz |z � |�d}~ww xY w)a�
Produces a class that either can be used standalone or as a base class for persistent classes.
This is a thin wrapper around a named tuple.
Constructing a type and using it to instantiate objects:
>>> Point = immutable('x, y', name='Point')
>>> p = Point(1, 2)
>>> p2 = p.set(x=3)
>>> p
Point(x=1, y=2)
>>> p2
Point(x=3, y=2)
Inheriting from a constructed type. In this case no type name needs to be supplied:
>>> class PositivePoint(immutable('x, y')):
... __slots__ = tuple()
... def __new__(cls, x, y):
... if x > 0 and y > 0:
... return super(PositivePoint, cls).__new__(cls, x, y)
... raise Exception('Coordinates must be positive!')
...
>>> p = PositivePoint(1, 2)
>>> p.set(x=3)
PositivePoint(x=3, y=2)
>>> p.set(y=-3)
Traceback (most recent call last):
Exception: Coordinates must be positive!
The persistent class also supports the notion of frozen members. The value of a frozen member
cannot be updated. For example it could be used to implement an ID that should remain the same
over time. A frozen member is denoted by a trailing underscore.
>>> Point = immutable('x, y, id_', name='Point')
>>> p = Point(1, 2, id_=17)
>>> p.set(x=3)
Point(x=3, y=2, id_=17)
>>> p.set(id_=18)
Traceback (most recent call last):
AttributeError: Cannot set frozen members id_
�,� c � �� �D � cg c] } | j d� s�d| z �� }} |r!dj dj |� �� S yc c} w )N�_�'%s'z�
frozen_fields = fields_to_modify & set([{frozen_members}])
if frozen_fields:
raise AttributeError('Cannot set frozen members %s' % ', '.join(frozen_fields))
�, )�frozen_members� )�endswith�format�join)�fr
�memberss ��7/usr/lib/python3/dist-packages/pyrsistent/_immutable.py�frozen_member_testz%immutable.<locals>.frozen_member_test4 sT �� �.5�I�����C��&�1�*�I��I��� ��d�i�i��&?��@�
A� �� Js
�A
�A
r c 3 �&