[FIXED] Timedelta compare bug (in Skulpt, apparently)

In client code, min(datetime.timedelta(1), datetime.timedelta(0)) throws this exception:

AttributeError: 'timedelta' object has no attribute '_getstate'
at src/lib/datetime.py, line 651 column 8
  called from src/lib/datetime.py, line 633 column 12

Demo here: https://anvil.works/build#clone:5QLXOGONFTC2TV4Q=3DK6NAVF4MHCENPA2EPA6JTP

Potential fix: this Oct 2020 Skulpt pull request by @stucork: support generic alias by s-cork · Pull Request #1216 · skulpt/skulpt · GitHub

Workaround: instead compare the total_seconds() methods:

td1 if td1.total_seconds() < td2.total_seconds() else td2

Seemingly related to my perf_counter() problem I had last week. Somehow, parts of datetime aren’t working with skulpt.

1 Like

I’ve moved to bug reports.

I’m not sure that PR you’ve linked is the fix for this particular issue.

The skulpt implementation for datetime needs an update.

Since skulpt is an open source project - if you’re interested in making a pr to skulpt for this specific issue let me know and I can point you to the right places. (It’s a relatively simple fix to get the comparisons of timedeltas to work). Either way I’ll add it to our list.

For some background skulpt uses an implementation of datetime that was originally a proof of concept for the module written in pure python and was used in pypy. This was originally a partial implementation and might lack some python 3 features since it was written for python 2.7. At the time Cpython’s datetime module was written in C code. But now Cpython’s implementation is also written in pure python and on my todo list is to see how much of the updated cpython implementation is compatible with skulpt.

1 Like

The timedelta issues should now be fixed

2 Likes