Unpacking int arguments to datetime.datetime gives a complaint about tzinfo
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 20.6k
- フォーク
- 3.3k
- PR マージ指標
- PR 指標を取得中
説明
Bug Report
mypy complains about this line of code. First I don't understand why and second I cannot bring it to accept it, even when including tzinfo=None in the parameter list.
# error: "datetime" gets multiple values for keyword argument "tzinfo"
dt.datetime(*split_int_string(date, 4, 6, 8), *split_int_string(time, 2, 4))
# or
# error: "datetime" gets multiple values for keyword argument "tzinfo"
dt.datetime(*split_int_string(date, 4, 6, 8), *split_int_string(time, 2, 4), tzinfo=None)
Why does mypy think tzinfo would already be used, it cannot be from a List[int]. The behavior when running is as expected.
The helper function is annotated like this:
def split_int_string(digits: str, *at: int) -> List[int]:
"""
Split a string at given indices and parse the parts to int.
"""
# Make a canonical representation.
split: List[int] = sorted(at)
if not split or split[0] != 0:
split.insert(0, 0)
if split[-1] != len(digits):
split.append(len(digits))
return [int(digits[split[i - 1] : split[i]]) for i in range(1, len(split))]
To Reproduce
(Write your steps here:)
- Paste from here into a file.
- Run with
python3, it works. - Pass to
mypyto see the error.
Expected Behavior
I expect not to get a typing error for that line.
Actual Behavior
It prints
error: Argument 1 to "datetime" has incompatible type "*List[int]"; expected "Optional[tzinfo]"
or
error: "datetime" gets multiple values for keyword argument "tzinfo"
depending on whether one also adds the tzinfo=None or not.
Your Environment
- Mypy version used: 0.812
- Mypy command-line flags: none
- Mypy configuration options from
mypy.ini(and other config files): none - Python version used: 3.8.6
- Operating system and version: Linux CL003356 4.19.128-microsoft-standard #1 SMP Tue Jun 23 12:58:10 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
Issue にリンクされた貼り付け済みの再現コードから始め、複数の展開された List[int] 引数を指定した datetime.datetime の呼び出しを mypy がどのように解析するかを調べます。tzinfo に関する診断を確認し、その後、報告に示された実行時の挙動と比較します。有効な呼び出しで誤った型エラーが発生しなくなり、実際の引数の競合については引き続き診断されれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- devtools
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100