python / python/mypy

Spurious error with dynamic keyword arguments

オープン
#9,676 コメント 6 件 リアクション 4 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

bug topic-calls
主要言語
Python
スター
20.6k
フォーク
3.3k
PR マージ指標
PR 指標を取得中

説明

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

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

最小限の test.py の例と、リンクされた typeshed の datetime.pyi 定義から始め、次に --python-version 3.5 と 3.6 における mypy の呼び出し処理を比較します。Python 3.6 では動的なキーワード呼び出しが受け入れられ、既存の 3.5 の動作にリグレッションが発生しなければ、issue は完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
compilers
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。