python / python/mypy

Spurious error with dynamic keyword arguments

Open
#9,676 6 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug topic-calls
Dominant language
Python
Stars
20.6k
Forks
3.3k
PR merge metrics
PR metrics pending

Description

Bug Report

The expression datetime.timedelta(**{"seconds": 1.0}) works correctly in python, but mypy reports it as an error if the python-version parameter is 3.6 or greater. (note that the typeshed definition of timedelta.__init__ is conditioned on the python version, which explains why that parameter has this effect)

To Reproduce

test.py:

import datetime

datetime.timedelta(**{"seconds": 1.0})

Run mypy --python-version 3.5 test.py and mypy --python-version 3.6 test.py

Actual Behavior

With --python-version 3.5, there are no errors. With --python-version 3.6, it reports:

test.py:3: error: Argument 1 to "timedelta" has incompatible type "**Dict[str, float]"; expected "int"
Found 1 error in 1 file (checked 1 source file)

Your Environment

  • Mypy version used: tested both 0.740 and 0.790
  • Mypy command-line flags: --python-version
  • Mypy configuration options from mypy.ini (and other config files): none
  • Python version used: 3.8
  • Operating system and version: linux

Minimal test case: https://repl.it/@bdarnell/mypy-dynamic-keyword-args-bug-report
CI build in which this was initially discovered: https://travis-ci.org/github/tornadoweb/tornado/jobs/740396440

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 minimal test.py example and the linked typeshed datetime.pyi definition, then compare mypy's handling of the call under --python-version 3.5 and 3.6. The issue is done when the dynamic keyword call is accepted for Python 3.6 without regressing the existing 3.5 behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 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.