|
Server : Apache System : Linux server.mata-lashes.com 3.10.0-1160.90.1.el7.x86_64 #1 SMP Thu May 4 15:21:22 UTC 2023 x86_64 User : matalashes ( 1004) PHP Version : 8.1.29 Disable Function : NONE Directory : /usr/local/lib64/python3.6/site-packages/pyrsistent/__pycache__/ |
Upload File : |
3
G�Kd� � @ s\ d dl mZ d dlmZmZ d dlmZmZ d dlm Z m
Z
d
dd�Zddd �Zd
d� Z
dS )� )�wraps)�PMap�pmap)�PSet�pset)�PVector�pvectorTc s� t | �}|tks� r8t| t�r8t� fdd�| j� D ��S |tksN� rht| t�rh� fdd�}tt || ��S |t
kr�� fdd�}t
t || ��S |tkr�t| �S | S )a}
Recursively convert simple Python containers into pyrsistent versions
of those containers.
- list is converted to pvector, recursively
- dict is converted to pmap, recursively on values (but not keys)
- set is converted to pset, but not recursively
- tuple is converted to tuple, recursively.
If strict == True (default):
- freeze is called on elements of pvectors
- freeze is called on values of pmaps
Sets and dict keys are not recursively frozen because they do not contain
mutable data by convention. The main exception to this rule is that
dict keys and set elements are often instances of mutable objects that
support hash-by-id, which this function can't convert anyway.
>>> freeze(set([1, 2]))
pset([1, 2])
>>> freeze([1, {'a': 3}])
pvector([1, pmap({'a': 3})])
>>> freeze((1, []))
(1, pvector([]))
c s i | ]\}}t |� �|�qS � )�freeze)�.0�k�v)�strictr �9/tmp/pip-build-8nxjc3nm/pyrsistent/pyrsistent/_helpers.py�
<dictcomp># s zfreeze.<locals>.<dictcomp>c s
t | � �S )N)r
)�x)r r r �<lambda>% s zfreeze.<locals>.<lambda>c s
t | � �S )N)r
)r )r r r r ( s )
�type�dict�
isinstancer r �items�listr r �map�tuple�setr )�or �typZcurried_freezer )r r r
s r
c s� t | �}t| t�s� r8|tkr8� fdd�}tt|| ��S t| t�sN� rd|tkrd� fdd�| j� D �S |tkr�� fdd�}tt|| ��S t| t �r�t
| �S | S )a?
Recursively convert pyrsistent containers into simple Python containers.
- pvector is converted to list, recursively
- pmap is converted to dict, recursively on values (but not keys)
- pset is converted to set, but not recursively
- tuple is converted to tuple, recursively.
If strict == True (the default):
- thaw is called on elements of lists
- thaw is called on values in dicts
>>> from pyrsistent import s, m, v
>>> thaw(s(1, 2))
{1, 2}
>>> thaw(v(1, m(a=3)))
[1, {'a': 3}]
>>> thaw((1, v()))
(1, [])
c s
t | � �S )N)�thaw)r )r r r r H s zthaw.<locals>.<lambda>c s i | ]\}}t |� �|�qS r )r )r r r
)r r r r K s zthaw.<locals>.<dictcomp>c s
t | � �S )N)r )r )r r r r M s )r r r r r r r r r r r )r r r Zcurried_thawr )r r r 0 s
r c s t � �� fdd��}|S )a
Convenience decorator to isolate mutation to within the decorated function (with respect
to the input arguments).
All arguments to the decorated function will be frozen so that they are guaranteed not to change.
The return value is also frozen.
c s* t � dd� | D �tdd� |j� D ����S )Nc S s g | ]}t |��qS r )r
)r �er r r �
<listcomp>_ s z+mutant.<locals>.inner_f.<locals>.<listcomp>c s s | ]}t |�V qd S )N)r
)r �itemr r r � <genexpr>_ s z*mutant.<locals>.inner_f.<locals>.<genexpr>)r
r r )�args�kwargs)�fnr r �inner_f] s zmutant.<locals>.inner_f)r )r$ r% r )r$ r �mutantU s r&