[pypy-issue] Issue #2489: TypeError: object() takes no parameters when making singleton of extend tzinfo (pypy/pypy)

Jayson Reis issues-reply at bitbucket.org
Fri Mar 3 08:35:02 EST 2017


New issue 2489: TypeError: object() takes no parameters when making singleton of extend tzinfo
https://bitbucket.org/pypy/pypy/issues/2489/typeerror-object-takes-no-parameters-when

Jayson Reis:

psycopg2cffi uses `__new__` of it's extended tzinfo version to make a singleton for specific tzinfos and this used to work on python 3.5.3 but using pypy3 nightly `Python 3.5.2 (6c8f0848fcf2, Mar 03 2017, 02:00:11)` `[PyPy 5.6.0-alpha0 with GCC 4.8.2] on linux` it will break with this message:
```
root at 945f7d0c31f9:/data# pypy3 test.py
Traceback (most recent call last):
  File "test.py", line 17, in __new__
    return cls._cache[key]
KeyError: (None, None)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "test.py", line 24, in <module>
    print(FixedOffsetTimezone())
  File "test.py", line 19, in __new__
    tz = super(FixedOffsetTimezone, cls).__new__(cls, offset, name)
TypeError: object() takes no parameters
```

and this is the piece of code that will make it happen.

```python
import datetime

class FixedOffsetTimezone(datetime.tzinfo):
    _cache = dict()

    def __init__(self, offset=None, name=None):
        if offset is not None:
            self._offset = datetime.timedelta(minutes = offset)

        if name is not None:
            self._name = name

    def __new__(cls, offset=None, name=None):
        """Return a suitable instance created earlier if it exists
        """
        key = (offset, name)
        try:
            return cls._cache[key]
        except KeyError:
            tz = super(FixedOffsetTimezone, cls).__new__(cls, offset, name)
            cls._cache[key] = tz
            return tz


print(FixedOffsetTimezone())
```




More information about the pypy-issue mailing list