Skip to content
This repository was archived by the owner on Sep 9, 2026. It is now read-only.
This repository was archived by the owner on Sep 9, 2026. It is now read-only.

Error type hints in Python3.12 (#1147) #1839

Closed

Description

@954-Ivory

Initial Checks

  • I have read and followed the docs and still think this is a bug

Description

I encountered the following issue when using langchain in Python 3.12:

langchain-ai/langchain#15016

    return Generic.__class_getitem__.__func__(cls, item)  # type: ignore
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'builtin_function_or_method' object has no attribute '__func__'. Did you mean: '__doc__'?

It caused by this PR (#1147)

I think it can be changed like this:

    def __class_getitem__(cls, item: Union[Type[BaseDocument], TypeVar, str]):
        if not isinstance(item, type):
            try:
                return Generic.__class_getitem__.__func__(cls, item)  # type: ignore
                # this do nothing that checking that item is valid type var or str
                # Keep the approach in #1147 to be compatible with lower versions of Python.
            except AttributeError:
                from types import GenericAlias
                return GenericAlias(cls, item)  # type: ignore

I want to know others' opinions.

Example Code

https://learn.deeplearning.ai/langchain/lesson/5/question-and-answer

Python, DocArray & OS Version

OS==Windows 22H2
Python==3.12.0
docarray==0.39.1

Affected Components

Activity

  1. JoanFM commented on Dec 22, 2023

    @JoanFM
    Member

    hey @954-Ivory , would you be able to do a PR with the fix?

  2. 954-Ivory commented on Dec 22, 2023

    @954-Ivory
    ContributorAuthor

    hey @954-Ivory , would you be able to do a PR with the fix?

    Yes, completed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions