Lessons Learned

contact@vinta.com.br

You don't need a hacky snippet to manipulate dates into the a specific moment, such as EOD. datetime.datetime.combine can do that for you as it receives three parameters: date (can be datetime too), time and tzinfo , the latter being an optional argument. The following snippet will put a given date into EOD:

from datetime import datetime, time

date = datetime.strptime("2019-01-01", "%Y-%m-%d")  # datetime.datetime(2029, 1, 1, 0, 0)
eod_date = datetime.combine(date, time.max)  # datetime.datetime(2029, 1, 1, 23, 59, 59, 999999)
Did you like?
1

PEP 591 specifies a final decorator that intends to restrict subsclassing for those classes with the giving decorator as well as overriding methods with this annotation. It plays nicely with the @overload decorator, although a type checker such as mypy would require the @final decorator to be put last. As any typing implementation, it's not going to be enforced at runtime if no runtime type checker is being used. For more info, see https://www.python.org/dev/peps/pep-0591/

Did you like?
1