Skip to content

Need type annotation for predefined dict generic (3.9) #11093

@ultrabear

Description

@ultrabear

Bug Report
mypy errors on defining a variable to a python 3.9 dict whose type signature has been previously stored in a variable

To Reproduce
Using mypy bug.py --strict
Error stems from disallow untyped generics, I think

Block = dict[str, str]

def main() -> Block:

    out = Block()  # error: Need type annotation for "out" (hint: "out: Dict[<type>, <type>] = ...")

    return out

if __name__ == "__main__":
    main()

Expected Behavior

Mypy should be able to read the type information stored in Block and read it as that type being init, as it can read the type information for a return signature

Actual Behavior
mypy raises a untyped generic error that out needs a type annotation:
error: Need type annotation for "out" (hint: "out: Dict[<type>, <type>] = ...")

Your Environment

  • Mypy version used: 0.910
  • Mypy command-line flags: --strict
  • Mypy configuration options from mypy.ini (and other config files): none present.
  • Python version used: 3.9.6
  • Operating system and version: Linux 5.10

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrongtopic-type-aliasTypeAlias and other type alias issues

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions