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

Update ResponseT type alias #3227

Merged
merged 4 commits into from May 20, 2024
Merged

Update ResponseT type alias #3227

merged 4 commits into from May 20, 2024

Conversation

willfrey
Copy link
Contributor

@willfrey willfrey commented May 10, 2024

Pyright treats explicit and implicit Any differently, with implicit Any being treated as Unknown. Pyright raised a warning indicating an unknown member type for 'Awaitable' when used in 'ResponseT'. Using the incr method as an example, the warning is:

"warning: Type of 'incr' is partially unknown
 Type of 'incr' is '(name: bytes | str | memoryview, amount: int = 1) -> (Awaitable[Unknown] | Any)' (reportUnknownMemberType)"

By explicitly specifying 'Awaitable[Any]' in the union for 'ResponseT', this resolves the ambiguity about the member type.

Pull Request check-list

Please make sure to review and check all of these items:

  • Do tests and lints pass with this change?
  • Do the CI tests pass with this change (enable it first in your forked repo and wait for the github action build to finish)?
  • Is the new or changed code fully tested?
  • Is a documentation update included (if this change modifies existing APIs, or introduces new ones)?
  • Is there an example added to the examples folder (if applicable)?
  • Was the change added to CHANGES file?

NOTE: these things are not required to open a PR and can be done
afterwards / while the PR is open.

Description of change

Please provide a description of the change here.

Pyright treats explicit and implicit `Any` differently, with implicit `Any` being treated as `Unknown`. Pyright raised a warning indicating an unknown member type for 'Awaitable' when used in 'ResponseT'. Using the `incr` method as an example, the warning is:

```
"warning: Type of 'incr' is partially unknown
 Type of 'incr' is '(name: bytes | str | memoryview, amount: int = 1) -> (Awaitable[Unknown] | Any)' (reportUnknownMemberType)"
```

By explicitly specifying 'Awaitable[Any]' in the union for 'ResponseT', this resolves the ambiguity about the member type.
@gerzse
Copy link
Contributor

gerzse commented May 15, 2024

@willfrey Thanks for this!

Would you mind sharing how you ran pyright? I gave it a quick try, and was surprised to actually see many errors. I'm trying to spot the one you mention in this PR. Thanks!

@willfrey
Copy link
Contributor Author

willfrey commented May 16, 2024

Hi @gerzse! I'd be happy to. I'm using a [tool.pyright] section in my pyproject.toml file to configure Pyright but you can also use a pyrightconfig.json file.

[tool.pyright]
typeCheckingMode = "standard"
reportUnknownVariableType = "warning"

This should trigger the warning above (and probably more!)

For some extra context, Mypy treats Awaitable as Awaitable[Any] but Pyright treats explicit and implicit Any differently, where implicit Any becomes Unknown. A similar type of warning/error can be triggered with Mypy by setting enabling disallow_any_generics setting. This will have Mypy complain when generics are left without an explicit annotation, such as Awaitable vs Awaitable[Any].

@gerzse gerzse added the maintenance Maintenance (CI, Releases, etc) label May 20, 2024
@gerzse
Copy link
Contributor

gerzse commented May 20, 2024

Thanks @willfrey , it worked as you suggested. Plenty of things to fix overall... Thanks for pointing in the right direction.

@gerzse gerzse merged commit cefc36e into redis:master May 20, 2024
46 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
maintenance Maintenance (CI, Releases, etc)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants