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

Internal error on a simple destructuring assignment #8938

Closed
earshinov opened this issue Jun 3, 2020 · 5 comments
Closed

Internal error on a simple destructuring assignment #8938

earshinov opened this issue Jun 3, 2020 · 5 comments

Comments

@earshinov
Copy link

TLDR: *intermediate_keys, prop = key, *keys

Are you reporting a bug, or opening a feature request?

A 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.

test.py:

from typing import Any, Dict

def assignDeep(value: Any, target: Dict[str, Any], key: str, *keys: str) -> None:
    """Assigns the given value to property nested in several dictionaries

    Usage example:

        >>> data = {}
        >>> assignDeep(1, data, 'one', 'two', 'three')
        >>> data
        {'one': {'two': {'three': 1}}}
    """
    *intermediate_keys, prop = key, *keys  # <<<
    for key in intermediate_keys:
        target = target.setdefault(key, {})
    target[prop] = value

What is the actual behavior/output?

$ mypy --show-traceback test.py
test.py:13: error: INTERNAL ERROR -- Please try using mypy master on Github:
https://mypy.rtfd.io/en/latest/common_issues.html#using-a-development-mypy-build
Please report a bug at https://github.com/python/mypy/issues
version: 0.790+dev.d49e245d902dbd5758e78787f4708f03085b941d

What is the behavior/output you expect?

The line

*intermediate_keys, prop = key, *keys

should type-check or at least not cause mypy to fail with an internal error.

What are the versions of mypy and Python you are using? Do you see the same issue after installing mypy from Git master?

Reproducible in

  • mypy 0.761
  • mypy 0.780 (latest version published on PyPI)
  • mypy 0.790+dev.d49e245d902dbd5758e78787f4708f03085b941d (installed from master)
$ python3.8 --version
Python 3.8.3

What are the mypy flags you are using? (For example --strict-optional)

mypy.ini:

[mypy]
ignore_missing_imports = True

If mypy crashed with a traceback, please paste the full traceback below.

Traceback (most recent call last):
  File "/usr/local/bin/mypy", line 8, in <module>
    sys.exit(console_entry())
  File "/usr/local/lib/python3.8/dist-packages/mypy/__main__.py", line 8, in console_entry
    main(None, sys.stdout, sys.stderr)
  File "/usr/local/lib/python3.8/dist-packages/mypy/main.py", line 89, in main
    res = build.build(sources, options, None, flush_errors, fscache, stdout, stderr)
  File "/usr/local/lib/python3.8/dist-packages/mypy/build.py", line 180, in build
    result = _build(
  File "/usr/local/lib/python3.8/dist-packages/mypy/build.py", line 252, in _build
    graph = dispatch(sources, manager, stdout)
  File "/usr/local/lib/python3.8/dist-packages/mypy/build.py", line 2626, in dispatch
    process_graph(graph, manager)
  File "/usr/local/lib/python3.8/dist-packages/mypy/build.py", line 2949, in process_graph
    process_stale_scc(graph, scc, manager)
  File "/usr/local/lib/python3.8/dist-packages/mypy/build.py", line 3047, in process_stale_scc
    graph[id].type_check_first_pass()
  File "/usr/local/lib/python3.8/dist-packages/mypy/build.py", line 2107, in type_check_first_pass
    self.type_checker().check_first_pass()
  File "/usr/local/lib/python3.8/dist-packages/mypy/checker.py", line 294, in check_first_pass
    self.accept(d)
  File "/usr/local/lib/python3.8/dist-packages/mypy/checker.py", line 401, in accept
    stmt.accept(self)
  File "/usr/local/lib/python3.8/dist-packages/mypy/nodes.py", line 677, in accept
    return visitor.visit_func_def(self)
  File "/usr/local/lib/python3.8/dist-packages/mypy/checker.py", line 726, in visit_func_def
    self._visit_func_def(defn)
  File "/usr/local/lib/python3.8/dist-packages/mypy/checker.py", line 730, in _visit_func_def
    self.check_func_item(defn, name=defn.name)
  File "/usr/local/lib/python3.8/dist-packages/mypy/checker.py", line 792, in check_func_item
    self.check_func_def(defn, typ, name)
  File "/usr/local/lib/python3.8/dist-packages/mypy/checker.py", line 975, in check_func_def
    self.accept(item.body)
  File "/usr/local/lib/python3.8/dist-packages/mypy/checker.py", line 401, in accept
    stmt.accept(self)
  File "/usr/local/lib/python3.8/dist-packages/mypy/nodes.py", line 1005, in accept
    return visitor.visit_block(self)
  File "/usr/local/lib/python3.8/dist-packages/mypy/checker.py", line 1973, in visit_block
    self.accept(s)
  File "/usr/local/lib/python3.8/dist-packages/mypy/checker.py", line 401, in accept
    stmt.accept(self)
  File "/usr/local/lib/python3.8/dist-packages/mypy/nodes.py", line 1063, in accept
    return visitor.visit_assignment_stmt(self)
  File "/usr/local/lib/python3.8/dist-packages/mypy/checker.py", line 2011, in visit_assignment_stmt
    self.check_assignment(s.lvalues[-1], s.rvalue, s.type is None, s.new_syntax)
  File "/usr/local/lib/python3.8/dist-packages/mypy/checker.py", line 2049, in check_assignment
    self.check_assignment_to_multiple_lvalues(lvalue.items, rvalue, rvalue,
  File "/usr/local/lib/python3.8/dist-packages/mypy/checker.py", line 2508, in check_assignment_to_multiple_lvalues
    self.check_assignment(lv, rv, infer_lvalue_type)
  File "/usr/local/lib/python3.8/dist-packages/mypy/checker.py", line 2149, in check_assignment
    rvalue_type = remove_instance_last_known_values(rvalue_type)
  File "/usr/local/lib/python3.8/dist-packages/mypy/erasetype.py", line 135, in remove_instance_last_known_values
    return t.accept(LastKnownValueEraser())
  File "/usr/local/lib/python3.8/dist-packages/mypy/types.py", line 1676, in accept
    assert isinstance(visitor, SyntheticTypeVisitor)
AssertionError:
./test.py:13: : note: use --pdb to drop into pdb
@earshinov earshinov changed the title Internal error on a simple destructing assignment Internal error on a simple destructuring assignment Jun 3, 2020
@emmatyping
Copy link
Collaborator

I can duplicate this. Probably not too tricky to fix if I had to guess.

@JelleZijlstra
Copy link
Member

I would hardly call this a "simple" destructuring assignment though :)

@kstauffer
Copy link
Contributor

Reproducer doesn't crash on master (f220ce5).

@hauntsaninja
Copy link
Collaborator

mypy_primer bisects the fix to #8827

@earshinov
Copy link
Author

The fix is released with mypy 0.790

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

No branches or pull requests

5 participants