-
-
Notifications
You must be signed in to change notification settings - Fork 49
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: DictComponentsType["_help"]
is not expressed in type declaration
#626
Comments
Thank you for reporting! Would you be interested in contributing the fix? |
Sure, I'll do so tomorrow |
Well, I took a look: I think adding support for strictly We can allow arbitrary string keys at all but the top level, and just asserting at runtime that only literally from typing import Union, Callable, Type, Dict
ComponentType = Union[Callable, Type]
WithStr = Union[ComponentType, str]
NestedComponentsType = Dict[str, Union[WithStr, "NestedComponentsType"]]
DictComponentsType = Dict[str, Union[ComponentType, NestedComponentsType]]
def tryme(components: DictComponentsType) -> None:
print(components)
tryme({
"A": {
"B": "C", # mypy will allow any `str: str`
"D": lambda: "E"
}
#, "F": "G" # mypy throws at top level as expected
}) That will stop mypy from complaining, at the cost of more complex typing, and possible errors that will only be discovered at runtime (non WDYT? I lean towards "won't fix". |
Yes, tricky. I think better to not change anything until there is a more clean way to do it. A bit unfortunate. I did not think about this when I added the |
🐛 Bug report
The type for DictComponentsType doesn't allow the
"_help": str
entry:To reproduce
The text was updated successfully, but these errors were encountered: