Skip to content

parse return value fails mypy check #450

Open
@natflow

Description

@natflow
  • I am on the latest Pendulum version.
  • I have searched the issues of this repo and believe that this is not a duplicate.
  • OS version and name: Darwin 19.3.0 Darwin Kernel Version 19.3.0: Thu Jan 9 20:58:23 PST 2020; root:xnu-6153.81.5~1/RELEASE_X86_64 x86_64 i386
  • Pendulum version: 2.1.0
  • Mypy version: v0.770
  • Python version: 3.7.6

Issue

$ python3 -m virtualenv venv
Using base prefix '/usr/local/Cellar/python/3.7.6_1/Frameworks/Python.framework/Versions/3.7'
New python executable in /Users/___/devel/repro-pendulum-typing/venv/bin/python3.7
Also creating executable in /Users/___/devel/repro-pendulum-typing/venv/bin/python
Installing setuptools, pip, wheel...
done.
$ source venv/bin/activate
$ env/bin/pip install pendulum==2.1.0 mypy==v0.770
...
$ cat repro.py
import pendulum
d = pendulum.parse('P35D')
print(d.in_seconds())
$ env/bin/mypy --python-executable venv/bin/python repro.py
repro.py:3: error: "str" has no attribute "in_seconds"

So, mypy thinks pendulum.parse returns a string, when in fact it returns a duration (in this case). The str return type was just added to parse: https://github.com/sdispater/pendulum/pull/320/files#diff-d79c6f58aeecd540ddd61603df9184aaR17.

I think the right type would be a Union of pendulum.duration.Duration and other types.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions