Skip to content

How to fix type errors? #102

@Spoonrad

Description

@Spoonrad

How can I fix typing errors when using this library?

Example:

from abc import ABC, abstractmethod

import inject


class ICache(ABC):

    @abstractmethod
    def check(self) -> bool:
        ...

class Cache(ICache):
    ...

    def check(self) -> bool:
        return True

def test_inject() -> None:

    inject.configure(lambda binder: binder.bind(ICache, Cache()))  # type: ignore[arg-type]
    cache = inject.instance(ICache)
    cache.check()
mypy tests/test_inject.py
tests\test_inject.py:22: error: Item "object" of "object | Any" has no attribute "check"  [union-attr]

If I specify the type like this: cache: ICache I get an assignment error instead. How can I resolve this please?

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