-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
RET504 "false positive" when using variables for typing #10732
Comments
You may want to have from typing import TypedDict, NotRequired, Any
class A_Type(TypedDict):
services: NotRequired[list[dict[str, Any]]]
def fun(a: A_Type) -> list[dict[str, Any]]:
services: list[dict[str, Any]]
if "services" in a:
return a["services"]
# services being assigned other ways
services = []
return services |
In my case it is too versatile to have a TypedDict. https://github.com/home-assistant/core/pull/114528/files
|
I'm curious if you could do: services: list[dict[str, Any]] = a["services"]
return services That might be easier to "detect" / allow. |
This is already working without issue, but then you have to annotate the variable multiple times. |
Oh, hah, I didn't realize that. I think we can support the variant from your first post. |
…essary-assign` (astral-sh#10741) ## Summary Closes astral-sh#10732.
Hello together,
When introducing the RET rules to Home Assistant I currently have this case (simplified):
where RET504 is flagging, but when fixed mypy is complaining because of the Any type. The current options are 1. use
cast
, 2. declare the type again or 3. add a# noqa
.It would be cool that when a type declaration of the variable is found, that this assignment followed by a return would not get flagged.
The text was updated successfully, but these errors were encountered: