Skip to content

TypedDict RecursionError #5357

Closed
Closed

Description

@dmfigol
  • Are you reporting a bug, or opening a feature request?
    Bug
  • Please insert below the code you are checking with mypy,
    or a mock-up repro if the source is private. We would appreciate
    if you try to simplify your case to a minimal repro.
from typing import Dict, Any, Optional
from mypy_extensions import TypedDict


VarsDict = Dict[str, Any]
HostsDict = Dict[str, Optional[VarsDict]]

GroupDataDict = TypedDict(
    "GroupDataDict", {"children": "GroupsDict",
                      "vars": VarsDict,
                      "hosts": HostsDict}, total=False
)

GroupsDict = Dict[str, GroupDataDict]

trying to describe the following data (YAML):

all:
    children:
        servers:
            children:
                webservers:
                    hosts:
                        foo.example.com:
                        bar.example.com:
                dbservers:
                    hosts:
                        one.example.com:
                        two.example.com:
                            my_var: from_hostfile
                        three.example.com:
                            ansible_port: 5555
                            ansible_host: 192.0.2.50
            vars:
                some_server: foo.southeast.example.com
                halon_system_timeout: 30
                self_destruct_countdown: 60
                escape_pods: 2
        frontend:
            hosts:
                foo.example.com:
  • What is the actual behavior/output?
    Crash
  • What is the behavior/output you expect?
    No crash
  • What are the versions of mypy and Python you are using?
    0.610 + Python 3.7 / 3.6.6
  • Do you see the same issue after installing mypy from Git master?
    Haven't checked
  • What are the mypy flags you are using? (For example --strict-optional)
[mypy]
python_version = 3.6

check_untyped_defs = True
disallow_any_generics = True
disallow_untyped_calls = True
ignore_errors = False
ignore_missing_imports = True
strict_optional = True
warn_unused_ignores = True
warn_redundant_casts = True
warn_unused_configs = True
  • If mypy crashed with a traceback, please paste
    the full traceback below.
...
    for l in it:
  File "/usr/local/lib/python3.7/site-packages/mypy/types.py", line 1933, in <genexpr>
    return self.strategy(t.accept(self) for t in types)
  File "/usr/local/lib/python3.7/site-packages/mypy/types.py", line 1475, in accept
    return visitor.visit_forwardref_type(self)
  File "/usr/local/lib/python3.7/site-packages/mypy/types.py", line 1921, in visit_forwardref_type
    return t.resolved.accept(self)
  File "/usr/local/lib/python3.7/site-packages/mypy/types.py", line 512, in accept
    return visitor.visit_instance(self)
  File "/usr/local/lib/python3.7/site-packages/mypy/types.py", line 1895, in visit_instance
    return self.query_types(t.args)
  File "/usr/local/lib/python3.7/site-packages/mypy/types.py", line 1933, in query_types
    return self.strategy(t.accept(self) for t in types)
  File "/usr/local/lib/python3.7/site-packages/mypy/typeanal.py", line 990, in combine_lists_strategy
    for l in it:
  File "/usr/local/lib/python3.7/site-packages/mypy/types.py", line 1933, in <genexpr>
    return self.strategy(t.accept(self) for t in types)
  File "/usr/local/lib/python3.7/site-packages/mypy/types.py", line 1103, in accept
    return visitor.visit_typeddict_type(self)
  File "/usr/local/lib/python3.7/site-packages/mypy/types.py", line 1905, in visit_typeddict_type
    return self.query_types(t.items.values())
  File "/usr/local/lib/python3.7/site-packages/mypy/types.py", line 1933, in query_types
    return self.strategy(t.accept(self) for t in types)
  File "/usr/local/lib/python3.7/site-packages/mypy/typeanal.py", line 990, in combine_lists_strategy
    for l in it:
  File "/usr/local/lib/python3.7/site-packages/mypy/types.py", line 1933, in <genexpr>
    return self.strategy(t.accept(self) for t in types)
  File "/usr/local/lib/python3.7/site-packages/mypy/types.py", line 1475, in accept
    return visitor.visit_forwardref_type(self)
  File "/usr/local/lib/python3.7/site-packages/mypy/types.py", line 1921, in visit_forwardref_type
    return t.resolved.accept(self)
  File "/usr/local/lib/python3.7/site-packages/mypy/types.py", line 512, in accept
    return visitor.visit_instance(self)
  File "/usr/local/lib/python3.7/site-packages/mypy/types.py", line 1895, in visit_instance
    return self.query_types(t.args)
RecursionError: maximum recursion depth exceeded

Activity

  1. ilevkivskyi commented on Jul 15, 2018

    @ilevkivskyi
    Member

    My guess this may be a duplicate of #4780 (modulo NamedTuple -> TypedDict). Does the error disappear when you set disallow_any_generics = False?

  2. dmfigol commented on Jul 15, 2018

    @dmfigol
    Author

    @ilevkivskyi
    When i do disallow_any_generics = False, it no longer crashes, but still produces an error:

    -> % mypy typeddict-recursion.py
    typeddict-recursion.py:8: error: Recursive types not fully supported yet, nested types replaced with "Any"
    typeddict-recursion.py:14: error: Recursive types not fully supported yet, nested types replaced with "Any"
    
  3. ilevkivskyi commented on Jul 15, 2018

    @ilevkivskyi
    Member

    it no longer crashes, but still produces an error

    This is expected (the error explains why). You can just silence it with # type: ignore for now if you accept the risk explained.

  4. dmfigol commented on Jul 15, 2018

    @dmfigol
    Author

    I understand. I would prefer not to allow any generics.

  5. added a commit that references this issue on Aug 8, 2018
    ca201f4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions