Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

parse return value fails mypy check #450

Open
2 tasks done
natflow opened this issue Mar 11, 2020 · 1 comment
Open
2 tasks done

parse return value fails mypy check #450

natflow opened this issue Mar 11, 2020 · 1 comment

Comments

@natflow
Copy link

natflow commented Mar 11, 2020

  • 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.

elemoine pushed a commit to procrastinate-org/procrastinate that referenced this issue Mar 13, 2020
elemoine pushed a commit to procrastinate-org/procrastinate that referenced this issue Mar 13, 2020
@sanjayaggi
Copy link

sanjayaggi commented Feb 24, 2022

python = "^3.9"
pendulum = "^2.1.2"
mypy = "^0.931"

For below code mypy will show the issue
error: Item "Duration" of "Union[Date, Time, DateTime, Duration]" has no attribute "format"
While you can see format is working fine and returning the desired results.

Code to reproduce the error

"""Pendulum mypy issue"""
import pendulum
COB = "20220224"
cob_date_time = pendulum.parse(COB, strict=False)
print(type(cob_date_time))
formatted_cob = cob_date_time.format("DDMMYYYY")
print(formatted_cob)
print(type(formatted_cob))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants