Home / Function/ __instancecheck__() — anthropic-sdk-python Function Reference

__instancecheck__() — anthropic-sdk-python Function Reference

Architecture documentation for the __instancecheck__() function in _streaming.py from the anthropic-sdk-python codebase.

Entity Profile

Dependency Diagram

graph TD
  d0bbd79f_0a9b_d34b_5ed4_5cb42fe7d4b4["__instancecheck__()"]
  06e103f1_c04f_3dc3_84b3_de39ef09adee["_AsyncStreamMeta"]
  d0bbd79f_0a9b_d34b_5ed4_5cb42fe7d4b4 -->|defined in| 06e103f1_c04f_3dc3_84b3_de39ef09adee
  style d0bbd79f_0a9b_d34b_5ed4_5cb42fe7d4b4 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

src/anthropic/_streaming.py lines 142–158

    def __instancecheck__(self, instance: Any) -> bool:
        # we override the `isinstance()` check for `AsyncStream`
        # as a previous version of the `AsyncMessageStream` class
        # inherited from `AsyncStream` & without this workaround,
        # changing it to not inherit would be a breaking change.

        from .lib.streaming import AsyncMessageStream

        if isinstance(instance, AsyncMessageStream):
            warnings.warn(
                "Using `isinstance()` to check if a `AsyncMessageStream` object is an instance of `AsyncStream` is deprecated & will be removed in the next major version",
                DeprecationWarning,
                stacklevel=2,
            )
            return True

        return False

Subdomains

Frequently Asked Questions

What does __instancecheck__() do?
__instancecheck__() is a function in the anthropic-sdk-python codebase, defined in src/anthropic/_streaming.py.
Where is __instancecheck__() defined?
__instancecheck__() is defined in src/anthropic/_streaming.py at line 142.

Analyze Your Own Codebase

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

Try Supermodel Free