Page MenuHomePhabricator

Representation for Timestamp object is different between CPython and Pypy
Closed, ResolvedPublicBUG REPORT


Steps to replicate the issue (include links if applicable):

>>> from pywikibot import Timestamp
>>> ts =
>>> ts

What happens?:
Timestamp(2022, 12, 24, 10, 49, 6, 958707) is given for CPython but pywikibot.time.Timestamp(2022, 12, 24, 10, 49, 6, 958707) for Pypy.

Timestamp inherits from datetime.datetime. The repr of datetime is definded as:

def __repr__(self):
    """Convert to formal string, for repr()."""
    L = [self._year, self._month, self._day,  # These are never zero
         self._hour, self._minute, self._second, self._microsecond]
    if L[-1] == 0:
        del L[-1]
    if L[-1] == 0:
        del L[-1]
    s = "%s.%s(%s)" % (self.__class__.__module__,
                       ", ".join(map(str, L)))
    if self._tzinfo is not None:
        assert s[-1:] == ")"
        s = s[:-1] + ", tzinfo=%r" % self._tzinfo + ")"
    if self._fold:
        assert s[-1:] == ")"
        s = s[:-1] + ", fold=1)"
    return s

but obviously only pypy takes this into account. Neither datetime.repr nor Timestamp.repr calls it because the datetime implementation is overridden by _datetime:

    from _datetime import *
except ImportError:

I guess this is a C-implementation.

What should have happened instead?:
The result should be unique.

Software version (skip for WMF-hosted wikis like Wikipedia):
Tested with CPython 3.6-3.12 and Pypy 3.7

Event Timeline

Xqt changed the task status from Open to In Progress.Dec 24 2022, 10:13 AM
Xqt claimed this task.
Xqt triaged this task as High priority.
Xqt updated the task description. (Show Details)

Change 871263 had a related patch set uploaded (by Xqt; author: Xqt):

[pywikibot/core@master] [bugfix] Add Timestamp.__repr__() method to unify the result

Change 871263 merged by jenkins-bot:

[pywikibot/core@master] [bugfix] Add Timestamp.__repr__() method to unify the result