o
    Fh                     @   s   d dl Z d dlmZ d dlmZ d dlmZmZmZm	Z	 d dl
mZ G dd de	Zded	eeeef ddf fd
dZded	eeeef ddf fddZG dd deZedi eddG dd dZded	eeeef ddf fddZdS )    N)	dataclass)
itemgetter)Any	Generator
NamedTupleProtocol)dataclass_kwargsc                   @   s0   e Zd Zdedeeeef ddf fddZdS )ClassAttrsResolverclsreturnNc                 C   s   d S N )selfr
   r   r   U/var/www/html/venv/lib/python3.10/site-packages/aiogram/utils/class_attrs_resolver.py__call__
   s    zClassAttrsResolver.__call__)	__name__
__module____qualname__typer   tuplestrr   r   r   r   r   r   r	   	   s    (r	   r
   r   c                 c   s    t | E dH  dS )a7  
    Inspects and resolves attributes of a given class.

    This function uses the `inspect.getmembers` utility to yield all attributes of
    a provided class. The output is a generator that produces tuples containing
    attribute names and their corresponding values. This function is suitable for
    analyzing class attributes dynamically. However, it guarantees alphabetical
    order of attributes.

    :param cls: The class for which the attributes will be resolved.
    :return: A generator yielding tuples containing attribute names and their values.
    N)inspect
getmembers)r
   r   r   r   inspect_members_resolver   s   r   c                 c   sR    t  }tt| D ]}|j D ]\}}||v rq||fV  || qqdS )a  
    Resolve and yield attributes from the reversed method resolution order (MRO) of a given class.

    This function iterates through the reversed MRO of a class and yields attributes
    that have not yet been encountered. It avoids duplicates by keeping track of
    attribute names that have already been processed.

    :param cls: The class for which the attributes will be resolved.
    :return: A generator yielding tuples containing attribute names and their values.
    N)setreversedr   getmro__dict__itemsadd)r
   known_attrsbasenamevaluer   r   r   &get_reversed_mro_unique_attrs_resolver   s   
r$   c                   @   s   e Zd ZU eed< eed< dS )	_Positionin_mroin_classN)r   r   r   int__annotations__r   r   r   r   r%   2   s   
 r%   T)slotsc                   @   s0   e Zd ZU eed< eed< dd defddZdS )_AttributeContainerpositionr#   otherr   c                 C   s   | j |j k S r   )r,   )r   r-   r   r   r   __lt__<   s   z_AttributeContainer.__lt__N)r   r   r   r%   r)   r   boolr.   r   r   r   r   r+   7   s   
 r+   c           	      c   s    i }t t| D ]+\}}t t| D ]\}\}}t||}|| }r,||_qt||d||< qq
t	| t
ddD ]
\}}||jfV  q@dS )a  
    Resolve and yield attributes from the method resolution order (MRO) of a given class.

    Iterates through a class's method resolution order (MRO) and collects its attributes
    along with their respective positions in the MRO and the class hierarchy. This generator
    yields a tuple containing the name of each attribute and its associated value.

    :param cls: The class for which the attributes will be resolved.
    :return: A generator yielding tuples containing attribute names and their values.
    )r#   r,      )keyN)	enumerater   r   varsr   r%   getr,   r+   sortedr   r#   )	r
   
attributesposition_in_mror!   position_in_classr"   r#   r,   	attributer   r   r   get_sorted_mro_attrs_resolver@   s   
r:   r   )r   dataclassesr   operatorr   typingr   r   r   r   aiogram.utils.dataclassr   r	   r   r   r   r   r$   r%   r+   r:   r   r   r   r   <module>   s    $$(