-
-
Notifications
You must be signed in to change notification settings - Fork 321
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
[mypy] "Only concrete class can be given" fails with Dependency provider and abc #497
Comments
Hi @zerlok. Yeah, this seems to be a mypy issue. There is no error on class Dependency(Provider[T]):
def __init__(self, instance_of: Type[T] = object, default: Optional[Union[Provider, Any]] = None) -> None: ...
class Factory(Provider[T]):
def __init__(self, provides: Optional[_Callable[..., T]] = None, *args: Injection, **kwargs: Injection) -> None: ... |
Checked a bunch of different ideas but neither works. I'm sorry, I can not fix it in the Dependency Injector. I probably need to update the documentation removing abc usage. Thanks for reporting the issue. |
Hi, @ rmk135, thanks for response. I hope then mypy will fix it somehow. I leave the issue open by now. Also I think that you may add a simple note about mypy behavior in the docs, not removing abc usage (Dependency provider works as expected). |
Hey, @rmk135 . The related mypy issue was closed. I tried to update mypy and dependency-injector and retry my code - the issue remains the same:
Any ideas how to fix it? |
Just an update, because this issue is top on google, there was some heated debates on mypy side about this because mypy allows for some behaviour where they need to ensure any instance of Type[X] is instanceable, so they can't allow an ABCs to fulfil Type[X] I didn't quite follow the details, but TL;DR but there was some push back about this and the best people could agree on was moving the check behind its dedicated own error code (instead of the current misc) (this PR) that will be available on mypy 0.990 Current workaround I've been using is: class Container(containers.DeclarativeContainer):
progress_monitoring = providers.Dependency(
# https://github.com/python/mypy/issues/5374
instance_of=ProgressMonitor, # type: ignore[type-abstract]
default=providers.Factory(
PubsubProgressMonitor,
tasks_lifecycle_topic=config.tasks_lifecycle_topic,
pubsub=pubsub,
),
) |
Maybe add a mention to this to the MyPy section of the docs? |
I'm trying to use Dependency provider according to the documentation, and the code works well, but mypy returns an error
Only concrete class can be given where "Type[Animal]" is expected
. I found this mypy issue, but I'm not sure is that problem related to me. Should I comment to the mypy issue and wait for it to be solved in mypy?project dependencies
mypy settings in
project.toml
The text was updated successfully, but these errors were encountered: