
    7Gi$                         d Z ddlZ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e	deeeeef      fdZd	eej                      deeeef      fd
Zedde
ee      de
e   defd       ZdededefdZy)a  Utility functions and helpers for deprecation management.

This module provides supporting utilities for the deprecation system, including:
    - Function introspection helpers
    - Testing utilities for deprecated code
    - Warning management tools

Key Functions:
    - get_func_arguments_types_defaults(): Extract function signature details
    - no_warning_call(): Context manager for testing code without warnings
    - void(): Helper to silence IDE warnings about unused parameters

Copyright (C) 2020-2023 Jiri Borovec <...>
    N)	Generator)contextmanager)AnyCallableOptionalUnionfuncreturnc                     t        j                  |       j                  }g }|D ]4  }||   j                  }||   j                  }|j                  |||f       6 |S )a  Parse function arguments, types and default values.

    Args:
        func: a function to be examined

    Returns:
        List of tuples, one per argument, each containing:
            - str: argument name
            - type: argument type annotation (or inspect._empty if no annotation)
            - Any: default value (or inspect._empty if no default)

    Example:
        >>> def example_func(x: int, y: str = "hello", z=42) -> None:
        ...     pass
        >>> result = get_func_arguments_types_defaults(example_func)
        >>> for name, type_hint, default in result:
        ...     print(f"{name}: type={type_hint}, default={default}")
        x: type=<class 'int'>, default=<class 'inspect._empty'>
        y: type=<class 'str'>, default=hello
        z: type=<class 'inspect._empty'>, default=42

        >>> # Example with the function itself
        >>> get_func_arguments_types_defaults(get_func_arguments_types_defaults)
        [('func', typing.Callable, <class 'inspect._empty'>)]

    )inspect	signature
parameters
annotationdefaultappend)r	   func_default_paramsfunc_arg_type_valargarg_typearg_defaults         _/home/nelsen/Projects/HRI/fr-in-the-cloud/.venv/lib/python3.12/site-packages/deprecate/utils.py!get_func_arguments_types_defaultsr      sm    6 "++D1<<" ?&s+66)#.66  #x!=>?     warnsc                 @    | D cg c]  }|j                    c}S c c}w )zConvert list of warning messages to their string representations.

    Args:
        warns: List of warning message objects captured during execution

    Returns:
        List of warning messages as strings or Warning objects

    )message)r   ws     r   _warns_reprr   ;   s      %%!AII%%%s   warning_typematchc              #   N  K   t        j                  d      5 }t        j                  d       d |s
	 ddd       y| st        dt	        |             |D cg c]  }t        |j                  |       s| }}|s
	 ddd       y|s$t        d| j                   dt	        |             |D cg c]!  }||j                  j                         v s |# }}|r't        d| j                   d| d	t	        |             	 ddd       yc c}w c c}w # 1 sw Y   yxY ww)
aY  Context manager to assert that no warnings are raised.

    This is useful for testing that new/replacement functions don't trigger
    deprecation warnings, or that code paths properly avoid deprecated functionality.

    Args:
        warning_type: The type of warning to catch (e.g., FutureWarning, DeprecationWarning).
            If None, catches all warning types.
        match: If specified, only fail if warning message contains this string.
            If None, fails on any warning of the specified type.

    Raises:
        AssertionError: If a warning of the specified type (and optionally matching
            the message pattern) was raised during the context.

    Example:
        >>> # Basic usage
        >>> import warnings
        >>> def new_func(x: int) -> int:
        ...     return x * 2
        >>> # Test passes only if no FutureWarning is raised
        >>> with no_warning_call(FutureWarning):
        ...     result = new_func(42)
        >>> result
        84

        >>> # Only fails if warning contains "deprecated"
        >>> def some_function():
        ...     warnings.warn("deprecated feature", FutureWarning)
        >>> with no_warning_call(FutureWarning, match="other"):  # doesn't match, so passes
        ...     some_function()

        >>> # Fails if ANY warning is raised
        >>> def clean_function():
        ...     pass
        >>> with no_warning_call():
        ...     clean_function()

    .. note:
        This is the inverse of ``pytest.warns()`` - it ensures warnings are NOT raised.
        Useful for testing that refactored code properly uses new APIs.

    T)recordalwaysNz/While catching all warnings, these were found: zWhile catching `z` warnings, these were found: z` warnings with "z", these were found: )
warningscatch_warningssimplefilterAssertionErrorr   
issubclasscategory__name__r   __str__)r   r    calledr   r   founds         r   no_warning_callr.   H   sJ    Z 
	 	 	- h'   #RS^_eSfRg!hii"Kqj\&JKK   "<#8#8"99WXcdiXjWkl  "BqUaii.?.?.A%ABB "<#8#8"99J5' R&&1%&8%9;  )  L C' s\   D%D	D%DD8D<D	D%
*D4!DD+D	D%
DD"D%argskwrgsc                      | |c}}y)a   Empty function that accepts any arguments and returns None.

    This helper function is used to silence IDE warnings about unused parameters
    in deprecated functions where the body is never executed (calls are forwarded
    to a target function).

    Args:
        *args: Any positional arguments (ignored)
        **kwrgs: Any keyword arguments (ignored)

    Returns:
        None

    Example:
        >>> from deprecate import deprecated, void
        >>>
        >>> def new_func(x: int) -> int:
        ...     return x * 2
        >>>
        >>> @deprecated(target=new_func, deprecated_in="1.0", remove_in="2.0")
        ... def old_func(x: int) -> int:
        ...     void(x)  # Silences IDE warning about unused 'x'
        ...     # This line is never reached - call forwarded to new_func
        >>>
        >>> old_func(5)  # Returns 10
        10

    .. note:
        This function has no runtime effect - it's purely for developer convenience
        to avoid IDE warnings. You can also use ``pass`` or just a docstring instead.

    N )r/   r0   _s      r   voidr4      s    B DAqr   )NN)__doc__r   r$   collections.abcr   
contextlibr   typingr   r   r   r   listtuplestrr   WarningMessageWarningr   typer.   r4   r2   r   r   <module>r?      s      % % 1 1!H !eCPSO>T9U !H
&tH334 
&eGSL>Q9R 
& D(4="9 DRU Dbk D DN! !c !c !r   