AssertionError when using double underscore in keyword-only argument
Open
Nobody has claimed this yet.
bug
priority-1-normal
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the reported case with Python 3.7 and mypy using --show-traceback, then start at mypy/checkexpr.py in check_argument_count, identified by the traceback. Trace the keyword-only arguments with double-underscore names and verify that the same input completes without an internal AssertionError.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100