How to make this code run successfully and pass the mypy checks?
from datetime import datetime
class TimeStamp(str):
"""ID with a short form and a long form."""
def __new__(cls, datetime) -> TimeStamp:
short = str(datetime.timestamp())
long = datetime.strftime("%Y-%m-%d %H:%M:%S")
obj = str.__new__(cls, short)
obj.short = short
obj.long = long
return obj
now = TimeStamp(datetime.now())
print(now)
print(now.long)
currently mypy untitled1.py
results in the following errors:
untitled1.py:10: error: "TimeStamp" has no attribute "short"
untitled1.py:11: error: "TimeStamp" has no attribute "long"
untitled1.py:16: error: "TimeStamp" has no attribute "long"
Found 3 errors in 1 file (checked 1 source file)