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.

Implement PEP 495

See original GitHub issue

Since arrow provides its own datetime-like, it should really implement PEP 495, e.g. the fold attribute, with functionality backported to Python pre-3.6 Python versions.

Issues that this will or could fix:

There may be more, I’m not sure. Either way, it’s pretty important.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
pgansslecommented, Dec 28, 2018

@systemcatch Why is dateutil pinned at all in this library? I don’t think that’s a good idea at all.

Anyway, I don’t really have time for this, so someone else will have to take it up.

1reaction
pgansslecommented, Nov 9, 2017

I will take a crack at this a bit later. I think it’s not terribly difficult, but from an implementation perspective, the one major question about a backport is whether you want the compatibility code at runtime (makes the code itself cleaner) or at import time (code may run faster).

So, for example, say I implement a fold property in arrow:

@property
def fold(self):
    return getattr(self._datetime, 'fold', self._fold)

@fold.setter
def fold(self, val):
    if getattr(self._datetime, 'fold', None) is None:
        if val not in {0, 1}:
            raise ValueError('fold attribute must be either 0 or 1')
        self._fold = fold
    else:
        self._datetime = self._datetime.replace(fold, val)

Alternatively, it can be done this way:

if getattr(datetime, 'fold', None):
    @property
    def fold(self):
        return self._fold

    @fold.setter
    def fold(self, val):
        if self._fold not in {0, 1}:
            raise ValueError('Fold must be 0 or 1')
        self._fold = val
else:
    @property
    def fold(self):
        return self._datetime.fold

    @fold.setter
    def fold(self, val):
        self._datetime = self._datetime.replace(fold=val)

The third, and I think best option would be to use dateutil.tz.enfold, which already backports almost all the functionality of PEP 495 (with the exception of dateutil/dateutil#344, which is hard for dateutil to fix but easy for arrow). The only problem with this approach is that tz.enfold was introduced in dateutil version 2.6.0, meaning you’d need to pin to >=2.6.0. If that’s a problem, it might be best to backport the enfold function into arrow.

Read more comments on GitHub >

github_iconTop Results From Across the Web

PEP 495 – Local Time Disambiguation
Return a datetime.time object with the specified hour, minute, second, microsecond and fold. Affected Behaviors. What time is it?
Read more >
Deprecation notice regarding PEP 495 in APScheduler
I am having difficulty using APScheduler in Python 3.73. Running any script that uses this library seems to give me the following warning:...
Read more >
PEP 495 and the hardest problem in computer science
This particular PEP will be implemented in Python 3.6 and concerns adding a new attribute called fold to the datetime.time and datetime.time ...
Read more >
Re: [Python-Dev] PEP 495 implementation - The Mail Archive
This time I am adding python-dev to BCC in hopes to reach a larger audience. With the date of the first beta (2016-09-07)...
Read more >
What's New In Python 3.6
PEP 495 – Local Time Disambiguation: PEP written by Alexander Belopolsky and Tim Peters, implementation by Alexander Belopolsky.
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