question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Incompatible `AwareDateTime` with pytz

See original GitHub issue

Hello!

As I was trying to introduce strict typing to my project I ran into an issue when integrating pytz with marshmallow. It seems that marshmallow might be requesting too strict of types. The request for only datetime timezones prevents me from using pytz with the project (even though they are compatible). The mypy maintainer suggested that marshmallow needs to integrate protocol types to be able to solve this problem, though I’ll admit I’m not too sure what that means in this case. For a rundown of the issue please see:

https://github.com/python/mypy/issues/8632

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
adithyabskcommented, Apr 28, 2020

I would mark this issue as a bug @deckar01 I’ll try to implement @lafrech patch and submit a PR when I get a chance

1reaction
lafrechcommented, Apr 9, 2020

My point was that perhaps we should specify datetime.tzinfo as argument type rather than datetime.timezone.

    def __init__(
        self, format: str = None, *, default_timezone: dt.tzinfo = None, **kwargs
    ):

What we actually expect is a tzinfo, not specifically a dt.timezone.

dt.timezone is a convenience class provided by Python core to implement basic timezones. pytz timezones also inherit from tzinfo, which is the right thing to do, not dt.timezone.

The change above should fix the issue IIUC.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Specifying timezone aware times in python - datetime
I'm trying to specify a set of timezone aware times in python, using datetime.time objects. However, this does not seem to be supported...
Read more >
Incompatibility with datetutil.rrule and pytz.timezone? #102
For some time I've been using pytz's timezone implementation together with dateutil's rrule and have stumbled on an incompatibility several ...
Read more >
Making sense of timezones in Python | by Daniel van Flymen
A naive datetime doesn't have a timezone associated with it. An aware one does. ... pytz.localize() is useful for making a naive timezone...
Read more >
How to work with dates and time with Python - Opensource.com
When working with timestamps, the best strategy is to use non DST-aware time zones (ideally UTC+00:00). Serializing your datetime objects. The ...
Read more >
pytz - Paul Ganssle
This incompatibility is why, as of Python 3.6, the tzinfo documentation ... Whenever you construct an aware datetime from a naive one, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found