Skip to content

Spurious error with dynamic keyword arguments #9676

Open
@bdarnell

Description

@bdarnell

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrongtopic-callsFunction calls, *args, **kwargs, defaults

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions