Home / File/ _reflection.py — anthropic-sdk-python Source File

_reflection.py — anthropic-sdk-python Source File

Architecture documentation for _reflection.py, a python file in the anthropic-sdk-python codebase. 2 imports, 1 dependents.

File python AnthropicClient SyncAPI 2 imports 1 dependents 2 functions

Entity Profile

Dependency Diagram

graph LR
  5f498a17_95ee_cd14_01ce_dab1a2bfac8d["_reflection.py"]
  506d0594_2a0d_4f14_1041_ed428dcfcac8["inspect"]
  5f498a17_95ee_cd14_01ce_dab1a2bfac8d --> 506d0594_2a0d_4f14_1041_ed428dcfcac8
  89ddcdd7_3ae1_4c7b_41bb_9f1e25f16875["typing"]
  5f498a17_95ee_cd14_01ce_dab1a2bfac8d --> 89ddcdd7_3ae1_4c7b_41bb_9f1e25f16875
  6dadb144_3070_6111_357f_214554108905["__init__.py"]
  6dadb144_3070_6111_357f_214554108905 --> 5f498a17_95ee_cd14_01ce_dab1a2bfac8d
  style 5f498a17_95ee_cd14_01ce_dab1a2bfac8d fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

from __future__ import annotations

import inspect
from typing import Any, Callable


def function_has_argument(func: Callable[..., Any], arg_name: str) -> bool:
    """Returns whether or not the given function has a specific parameter"""
    sig = inspect.signature(func)
    return arg_name in sig.parameters


def assert_signatures_in_sync(
    source_func: Callable[..., Any],
    check_func: Callable[..., Any],
    *,
    exclude_params: set[str] = set(),
) -> None:
    """Ensure that the signature of the second function matches the first."""

    check_sig = inspect.signature(check_func)
    source_sig = inspect.signature(source_func)

    errors: list[str] = []

    for name, source_param in source_sig.parameters.items():
        if name in exclude_params:
            continue

        custom_param = check_sig.parameters.get(name)
        if not custom_param:
            errors.append(f"the `{name}` param is missing")
            continue

        if custom_param.annotation != source_param.annotation:
            errors.append(
                f"types for the `{name}` param are do not match; source={repr(source_param.annotation)} checking={repr(custom_param.annotation)}"
            )
            continue

    if errors:
        raise AssertionError(f"{len(errors)} errors encountered when comparing signatures:\n\n" + "\n\n".join(errors))

Subdomains

Dependencies

  • inspect
  • typing

Frequently Asked Questions

What does _reflection.py do?
_reflection.py is a source file in the anthropic-sdk-python codebase, written in python. It belongs to the AnthropicClient domain, SyncAPI subdomain.
What functions are defined in _reflection.py?
_reflection.py defines 2 function(s): assert_signatures_in_sync, function_has_argument.
What does _reflection.py depend on?
_reflection.py imports 2 module(s): inspect, typing.
What files import _reflection.py?
_reflection.py is imported by 1 file(s): __init__.py.
Where is _reflection.py in the architecture?
_reflection.py is located at src/anthropic/_utils/_reflection.py (domain: AnthropicClient, subdomain: SyncAPI, directory: src/anthropic/_utils).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free