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

Should TypedDict be compatible with Dict[str, Any] ? #8923

Closed
dmerejkowsky opened this issue May 30, 2020 · 2 comments
Closed

Should TypedDict be compatible with Dict[str, Any] ? #8923

dmerejkowsky opened this issue May 30, 2020 · 2 comments

Comments

@dmerejkowsky
Copy link
Contributor

This is more a question than a bug report per se.

Here it is.

I have the following code:

from typing import Any, Dict, TypedDict


IndexContext = TypedDict("IndexContext", {"user": str})


def get_context() -> IndexContext:
    return {"user": "john"}


def render(context: Dict[str, Any]) -> None:
    print(context)


def main() -> None:
    context = get_context()
    render(context)

Here's what I get when running mypy:

$ mypy foo.py
foo.py:17: error: Argument 1 to "render" has incompatible type "IndexContext"; 
  expected "Dict[str, Any]"
Found 1 error in 1 file (checked 1 source file)

I was expecting that mypy would not complain, because the IndexContext seems compatible with a plain Dict[str, Any]. Am I missing something ?

@sobolevn
Copy link
Member

Some context: typeddjango/django-stubs#355

@dmerejkowsky
Copy link
Contributor Author

Sorry, this is a duplicate of #4976 (I somehow missed it when I open this issue). Let's close this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants