
    jP	                    N    d Z ddlmZ ddlZddlZddlmZmZ ddZddZ	ddZ
dS )z9A fancy version of Python's builtin :func:`dir` function.    )annotationsN)AnyCallableobjobjectattrstrreturnboolc                8    	 t          | |           dS #  Y dS xY w)zfIn recent versions of Python, hasattr() only catches AttributeError.
    This catches all errors.
    TF)getattr)r   r   s     Y/home/ubuntu/.hermes/hermes-agent/venv/lib/python3.11/site-packages/IPython/utils/dir2.pysafe_hasattrr      s,    Ttuus    	list[str]c                   	 t          t          |                     }n# t          $ r t                      }Y nw xY wt          | d          r$|t          t          | j                            z  }d |D             }t          |          S )av  dir2(obj) -> list of strings

    Extended version of the Python builtin dir(), which does a few extra
    checks.

    This version is guaranteed to return only a list of true strings, whereas
    dir() returns anything that objects inject into themselves, even if they
    are later not really valid for attribute access (many extension libraries
    have such bugs).
    	__class__c                <    g | ]}t          |t                    |S  )
isinstancer	   ).0ws     r   
<listcomp>zdir2.<locals>.<listcomp>4   s'    4441As!3!34Q444    )setdir	Exceptionr   r   sorted)r   wordss     r   dir2r      s    CHH    C%% )S''(((
 54444E%==s    ::nameCallable[..., Any] | Nonec                    	 t          | dd          }n# t          $ r Y dS w xY w|dS 	 t          | |d          }n# t          $ r Y dS w xY wt          j        |           rt	          |t
          j                  sdS t          |          r|S dS )aE  Like getattr, but with a few extra sanity checks:

    - If obj is a class, ignore everything except class methods
    - Check if obj is a proxy that claims to have all attributes
    - Catch attribute access failing with any exception
    - Check that the attribute is a callable object

    Returns the method or None.
    (_ipython_canary_method_should_not_exist_N)r   r   inspectisclassr   types
MethodTypecallable)r   r    canaryms       r   get_real_methodr+   8   s    H$OO   tt tCt$$   tt s Jq%2B$C$C t{{ 4s    
""< 
A
	A
)r   r   r   r	   r
   r   )r   r   r
   r   )r   r   r    r	   r
   r!   )__doc__
__future__r   r$   r&   typingr   r   r   r   r+   r   r   r   <module>r/      s    ? ?
 # " " " " "                        >     r   