Skip to content

Incompatibility with ABC #4

@vlastocom

Description

@vlastocom

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions