Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ADAPTER_CLASSES may not support appendleft #82

Open
VMRuiz opened this issue May 7, 2024 · 2 comments
Open

ADAPTER_CLASSES may not support appendleft #82

VMRuiz opened this issue May 7, 2024 · 2 comments
Labels
bug Something isn't working documentation Improvements or additions to documentation

Comments

@VMRuiz
Copy link

VMRuiz commented May 7, 2024

ADAPTER_CLASSES is defined as Iterable

ADAPTER_CLASSES: Iterable[Type[AdapterInterface]] = deque(

However, in the docs it's suggested to use appendleft method which is not part of the Iterable API.
This causes errors with tools like mypy:

error: "Iterable[Type[AdapterInterface]]" has no attribute "appendleft" [attr-defined]

Either the class type should be changed to List or other classes that may support appendleft or a different way to extend ADAPTER_CLASSES should be given.

@elacuesta
Copy link
Member

ADAPTER_CLASSES was originally typed as a Deque, this was most recently changed in #71 (#74). The appendleft example works in the context of the default implementation, this is mentioned in the docs:

The default implementation uses a collections.deque to support efficient addition/deletion of adapters classes to both ends, but if you are deriving a subclass (see the section on extending itemadapter for additional information), any other iterable (e.g. list, tuple) will work.

I can think of the following, though there might be a more correct and compact solution:

ADAPTER_CLASSES: Union[Iterable[Type[AdapterInterface]], Deque[Type[AdapterInterface]]] = deque( 

@Gallaecio
Copy link
Member

I was thinking we need to keep the typing as it is, and change the documentation example to something like:

ItemAdapter.ADAPTER_CLASSES = (CustomClass, *ItemAdapter.ADAPTER_CLASSES)

@wRAR wRAR added bug Something isn't working documentation Improvements or additions to documentation labels May 7, 2024
@Gallaecio Gallaecio changed the title ADAPTER_CLASSES may not supported appendleft ADAPTER_CLASSES may not support appendleft Oct 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

4 participants