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

Incompatibility with ABC #4

Open
vlastocom opened this issue Jul 31, 2021 · 0 comments
Open

Incompatibility with ABC #4

vlastocom opened this issue Jul 31, 2021 · 0 comments

Comments

@vlastocom
Copy link

I really like @indexedproperty, it saves a lot of boilerplate code.

When trying to create an indexed property in an abstract class, ABC is stopping me from instantiation, see this simplified example:

from abc import ABC
from typing import Dict

from indexedproperty import indexedproperty


class A(ABC):
    def __init__(self):
        self._books: Dict[str, str] = {'U001': 'John', 'U002': 'Mark', 'U003': 'Paul'}

    @indexedproperty
    def book(self, uid: str) -> str:
        return self._books.get(uid, '[Unknown]')


class TestA:
    def test_something(self):
        assert A().book['U001'] == 'John'

#   >       assert A().book['U001'] == 'John'
#   E       TypeError: Can't instantiate abstract class A with abstract method book

Is there a way around this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant