[py3k] use inspect module to get a function's arguments
authorRémi Cardona <remi.cardona@logilab.fr>
Tue, 22 Sep 2015 15:25:25 +0200
changeset 10714 8a2ec43fcf44
parent 10713 ec0f96cd7a18
child 10715 edd1ba9bb030
[py3k] use inspect module to get a function's arguments
devtools/fill.py
web/views/forms.py
--- a/devtools/fill.py	Fri Sep 18 17:58:30 2015 +0200
+++ b/devtools/fill.py	Tue Sep 22 15:25:25 2015 +0200
@@ -26,6 +26,7 @@
 from copy import deepcopy
 from datetime import datetime, date, time, timedelta
 from decimal import Decimal
+import inspect
 
 from six import text_type, add_metaclass
 from six.moves import range
@@ -258,7 +259,7 @@
         for attrname, attrvalue in classdict.items():
             if callable(attrvalue):
                 if attrname.startswith('generate_') and \
-                       attrvalue.func_code.co_argcount < 2:
+                       len(inspect.getargspec(attrvalue).args) < 2:
                     raise TypeError('generate_xxx must accept at least 1 argument')
                 setattr(_ValueGenerator, attrname, attrvalue)
         return type.__new__(mcs, name, bases, classdict)
--- a/web/views/forms.py	Fri Sep 18 17:58:30 2015 +0200
+++ b/web/views/forms.py	Tue Sep 22 15:25:25 2015 +0200
@@ -48,6 +48,7 @@
 from warnings import warn
 
 import time
+import inspect
 
 from logilab.common import dictattr, tempattr
 from logilab.common.decorators import iclassmethod, cached
@@ -257,7 +258,7 @@
                 editedfields = self._cw.form['_cw_fields']
             except KeyError:
                 raise RequestError(self._cw._('no edited fields specified'))
-        entityform = entity and self.field_by_name.im_func.func_code.co_argcount == 4 # XXX
+        entityform = entity and len(inspect.getargspec(self.field_by_name)) == 4 # XXX
         for editedfield in splitstrip(editedfields):
             try:
                 name, role = editedfield.split('-')