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
  b9e53dbc_d3d8_2f07_8b45_3dbe628b7e2e["__instancecheck__()"]
  24ed5c40_ba3e_0664_c9ff_ed70849c0b5d["_SyncStreamMeta"]
  b9e53dbc_d3d8_2f07_8b45_3dbe628b7e2e -->|defined in| 24ed5c40_ba3e_0664_c9ff_ed70849c0b5d
  style b9e53dbc_d3d8_2f07_8b45_3dbe628b7e2e fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

src/anthropic/_streaming.py lines 25–41

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

        from .lib.streaming import MessageStream

        if isinstance(instance, MessageStream):
            warnings.warn(
                "Using `isinstance()` to check if a `MessageStream` object is an instance of `Stream` 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 25.

Analyze Your Own Codebase

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

Try Supermodel Free