python / python/mypy

error in argument when using chained function-call

Open
#5,311 4 comments 5 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug false-positive priority-1-normal topic-overloads topic-type-variables
Dominant language
Python
Stars
20.6k
Forks
3.3k
PR merge metrics
PR metrics pending

Description

Example:

dct = {"": ""}

# ok
trans = str.maketrans(dct)
"".translate(trans)

# err
"".translate(str.maketrans(dct))
  • What is the actual behavior/output?

maketrans.py:8: error: Argument 1 to "maketrans" of "str" has incompatible type "Dict[str, str]"; expected "Union[Dict[int, Union[int, str, None]], Dict[str, Union[int, str, None]], Dict[Union[str, int], Union[int, str, None]]]"

  • What is the behavior/output you expect?

No error.

  • What are the versions of mypy and Python you are using?

I tested both mypy 0.610 and mypy 0.620+dev-0ca6bf9ce63439a1e8bcc4dec80ef12f8414cb87 with Python 3.6.5; behavior is identical.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the chained-call example in maketrans.py and reproduce it using Python 3.6.5 with the reported mypy versions. Compare the separate and nested str.maketrans calls; done means the nested form no longer reports the incompatible Dict[str, str] argument error.

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
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.