GHC 2019-04-07

1 comment.

, https://git.io/fjLp8 in crsmithdev/arrow
Here's some proof of concept code to implement the original proposal, namely "the timestamp property returned an int-like object that, when called, returned a float", as is:

```py
class Timestamp(int):
    def __new__(cls, arrow_obj: Arrow, *args, **kwargs):
        instance = int.__new__(cls, calendar.timegm(arrow_obj._datetime.utctimetuple()), *args, **kwargs)
        instance._arrow = arrow_obj
        return instance

    def __call__(self) -> float:
        return self._arrow.float_timestamp


class Arrow(...):
    ...
    
    @property
    def timestamp(self):
        return Timestamp(self)
```

The "accessing it like a property could be accompanied with a DeprecationWarning" part is harder since in Python 3 implicit lookup of magic methods bypass `__getattribute__` completely, so adding something like the following to the `Timestamp` class

```py
    def __getattribute__(self, name):
        if name not in ["_arrow", "__call__"]:
            warnings.warn("Arrow.timestamp as a property (int) is deprecated", DeprecationWarning)
        return object.__getattribute__(self, name)
```

won't work when the `Timestamp` is used like a regular int (with implicit `__str__`, `__add__`, etc.). I can't think of a solution without overriding all magic methods of `int`.

To be clear, I'm not advocating this solution. In fact, I think it (at least this particular implementation) is batshit crazy.