Author: Matti Picus <[email protected]>
Branch: 
Changeset: r95036:d2dd59afa85c
Date: 2018-08-29 08:16 +0200
http://bitbucket.org/pypy/pypy/changeset/d2dd59afa85c/

Log:    ensure datetimeAPI is initialized, for subclassing cpyext classes

diff --git a/pypy/module/cpyext/cdatetime.py b/pypy/module/cpyext/cdatetime.py
--- a/pypy/module/cpyext/cdatetime.py
+++ b/pypy/module/cpyext/cdatetime.py
@@ -137,8 +137,9 @@
     If it is a datetime.time or datetime.datetime, it may have tzinfo
     '''
     state = space.fromcache(State)
-    # cannot raise here, so just crash
-    assert len(state.datetimeAPI) > 0
+    if len(state.datetimeAPI) ==0:
+        # can happen in subclassing
+        _PyDateTime_Import(space)
     if state.datetimeAPI[0].c_TimeType == py_obj.c_ob_type:
         py_datetime = rffi.cast(PyDateTime_Time, py_obj)
         w_tzinfo = space.getattr(w_obj, space.newtext('tzinfo'))
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to