python / python/mypy

AssertionError when using double underscore in keyword-only argument

Offen
#6,727 5 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

bug priority-1-normal
Vorherrschende Sprache
Python
Sterne
20.6k
Forks
3.3k
PR-Merge-Kennzahlen
PR-Kennzahlen ausstehend

Beschreibung

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

Bug report.

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.

Code for reproduction:

from typing import Tuple, Dict, Any


def exec(args: Tuple, kwargs: Dict[str, Any]):
    action_id = 0
    action_name = "exec"
    _command_fallback(*args, __action_id=action_id,
                      __action_name=action_name, **kwargs)


def _command_fallback(self, *args, __action_id: int, __action_name: str, **kwargs) -> str:
    print(args, __action_id, __action_name, kwargs)
    return "Success."
What is the actual behavior/output?
$ python3 -m mypy temp.py --show-traceback
temp.py:7: error: INTERNAL ERROR -- please report a bug at https://github.com/python/mypy/issues version: 0.650
Traceback (most recent call last):
  File "/usr/local/bin/mypy", line 11, in <module>
    sys.exit(console_entry())
  File "/usr/local/lib/python3.7/site-packages/mypy/__main__.py", line 7, in console_entry
    main(None)
  File "/usr/local/lib/python3.7/site-packages/mypy/main.py", line 92, in main
    res = build.build(sources, options, None, flush_errors, fscache)
  File "/usr/local/lib/python3.7/site-packages/mypy/build.py", line 156, in build
    result = _build(sources, options, alt_lib_path, flush_errors, fscache)
  File "/usr/local/lib/python3.7/site-packages/mypy/build.py", line 206, in _build
    graph = dispatch(sources, manager)
  File "/usr/local/lib/python3.7/site-packages/mypy/build.py", line 2232, in dispatch
    process_graph(graph, manager)
  File "/usr/local/lib/python3.7/site-packages/mypy/build.py", line 2532, in process_graph
    process_stale_scc(graph, scc, manager)
  File "/usr/local/lib/python3.7/site-packages/mypy/build.py", line 2655, in process_stale_scc
    graph[id].type_check_first_pass()
  File "/usr/local/lib/python3.7/site-packages/mypy/build.py", line 1791, in type_check_first_pass
    self.type_checker().check_first_pass()
  File "/usr/local/lib/python3.7/site-packages/mypy/checker.py", line 282, in check_first_pass
    self.accept(d)
  File "/usr/local/lib/python3.7/site-packages/mypy/checker.py", line 393, in accept
    stmt.accept(self)
  File "/usr/local/lib/python3.7/site-packages/mypy/nodes.py", line 611, in accept
    return visitor.visit_func_def(self)
  File "/usr/local/lib/python3.7/site-packages/mypy/checker.py", line 704, in visit_func_def
    self._visit_func_def(defn)
  File "/usr/local/lib/python3.7/site-packages/mypy/checker.py", line 708, in _visit_func_def
    self.check_func_item(defn, name=defn.name())
  File "/usr/local/lib/python3.7/site-packages/mypy/checker.py", line 770, in check_func_item
    self.check_func_def(defn, typ, name)
  File "/usr/local/lib/python3.7/site-packages/mypy/checker.py", line 934, in check_func_def
    self.accept(item.body)
  File "/usr/local/lib/python3.7/site-packages/mypy/checker.py", line 393, in accept
    stmt.accept(self)
  File "/usr/local/lib/python3.7/site-packages/mypy/nodes.py", line 913, in accept
    return visitor.visit_block(self)
  File "/usr/local/lib/python3.7/site-packages/mypy/checker.py", line 1688, in visit_block
    self.accept(s)
  File "/usr/local/lib/python3.7/site-packages/mypy/checker.py", line 393, in accept
    stmt.accept(self)
  File "/usr/local/lib/python3.7/site-packages/mypy/nodes.py", line 928, in accept
    return visitor.visit_expression_stmt(self)
  File "/usr/local/lib/python3.7/site-packages/mypy/checker.py", line 2623, in visit_expression_stmt
    self.expr_checker.accept(s.expr, allow_none_return=True, always_allow_any=True)
  File "/usr/local/lib/python3.7/site-packages/mypy/checkexpr.py", line 3063, in accept
    typ = self.visit_call_expr(node, allow_none_return=True)
  File "/usr/local/lib/python3.7/site-packages/mypy/checkexpr.py", line 229, in visit_call_expr
    return self.visit_call_expr_inner(e, allow_none_return=allow_none_return)
  File "/usr/local/lib/python3.7/site-packages/mypy/checkexpr.py", line 296, in visit_call_expr_inner
    ret_type = self.check_call_expr_with_callee_type(callee_type, e, fullname, object_type)
  File "/usr/local/lib/python3.7/site-packages/mypy/checkexpr.py", line 633, in check_call_expr_with_callee_type
    object_type=object_type)[0]
  File "/usr/local/lib/python3.7/site-packages/mypy/checkexpr.py", line 705, in check_call
    arg_names, formal_to_actual, context, self.msg)
  File "/usr/local/lib/python3.7/site-packages/mypy/checkexpr.py", line 1094, in check_argument_count
    assert argname is not None
AssertionError:
temp.py:7: : note: use --pdb to drop into pdb
What is the behavior/output you expect?

No exception raised.

What are the versions of mypy and Python you are using?
$ python3 -m mypy version
mypy 0.701
$ python3 --version 
Python 3.7.3
Do you see the same issue after installing mypy from Git master?

Same bug reproduced with mypy-0.710+dev.dadae5f6f6f99191d6a7a407660eba5e3732c397.

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

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Reproduziere den gemeldeten Fall mit Python 3.7 und mypy unter Verwendung von --show-traceback und beginne dann bei mypy/checkexpr.py in check_argument_count, das durch den Traceback identifiziert wurde. Verfolge die Keyword-only-Argumente mit Namen mit doppeltem Unterstrich und überprüfe, dass dieselbe Eingabe ohne einen internen AssertionError abgeschlossen wird.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
python
Bereich
devtools
Issue-Typ
Bug
Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
42/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.