-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Open
Labels
bugmypy got something wrongmypy got something wrong
Description
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
mypy
to 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 List and dict literals with explicit types not documented #1 SMP Tue Jun 23 12:58:10 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
Metadata
Metadata
Assignees
Labels
bugmypy got something wrongmypy got something wrong