Skip to content

The DaprClient resource manager returns wrong type #520

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

Closed
dbrattli opened this issue Jan 7, 2023 · 0 comments · Fixed by #521
Closed

The DaprClient resource manager returns wrong type #520

dbrattli opened this issue Jan 7, 2023 · 0 comments · Fixed by #521
Assignees
Labels
kind/bug Something isn't working size/XS 2 days work
Milestone

Comments

@dbrattli
Copy link
Contributor

dbrattli commented Jan 7, 2023

Expected Behavior

Using with statement with DaprClient should return type of DaprClient on enter. To make this happen the __enter__ method of DaprGrpcClient should return type Self and not DaprGrpcClient so that sub-classes return the correct type. E.g DaprClient would return type of DaprClient

def __enter__(self) -> 'DaprGrpcClient':

The Self type can be used from Python 3.11. For versions less than 3.11 it can be imported from typing_extensions e.g:

from typing_extensions import Self
...

class DaprGrpcClient:
    ....
    def __enter__(self) -> Self:
        return self

Actual Behavior

Using with statement with DaprClient returns type of DaprGrpcClient, not DaprClient. This means that methods like e.g invoke_method_async is not available for static type checkers such as Pyright.

Note that this is a static type checker problem, not a runtime problem. Code runs just fine, but editor shows a problem.

Steps to Reproduce the Problem

Writing code such as with DaprClient() as d: in editors such as vscode using standard Python extension with Pylance (pyright) will show error.

Screenshot 2023-01-07 at 15 04 13

Release Note

RELEASE NOTE:

@dbrattli dbrattli added the kind/bug Something isn't working label Jan 7, 2023
@berndverst berndverst added the size/XS 2 days work label Jan 11, 2023
@berndverst berndverst added this to the v1.9 milestone Jan 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Something isn't working size/XS 2 days work
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants