[issue24824] Pydoc fails with codecs

Yury Selivanov report at bugs.python.org
Sat Aug 8 17:48:18 CEST 2015


Yury Selivanov added the comment:

Larry, Serhiy,

After giving this some thought I think that my initial patch is a wrong approach here -- inspect module should not be touched to fix this issue.  

With this patch applied, signature object for codecs.encode would have a Parameter with a bogus default value, breaking functions like 'BoundArguments.apply_defaults()' etc.  In other words, whatever AC puts in 'signature.parameters['encoding'].default' must be an object that will be accepted by the function.

codecs.encode, if implemented in Python, would look like:

   def encode(obj, encoding=None, errors='strict'):
       if encoding is None:
           encoding = sys.getdefaultencoding()
       ...

And that's how the signature should be defined for the C version (because that's what is actually happening in C code as well!)

The new patch changes the AC specs from

  _codecs.encode
      obj: object
      encoding: str(c_default="NULL") = sys.getdefaultencoding()
      errors: str(c_default="NULL") = "strict"

to

  _codecs.encode
      obj: object
      encoding: str(accept={str, NoneType}) = NULL
      errors: str(c_default="NULL") = "strict"

(docstring is updated too).

This change, by the way, is in accordance with PEP 436:

   The values supplied for these [default] parameters must be compatible with ast.literal_eval.

----------
nosy: +ncoghlan
Added file: http://bugs.python.org/file40152/codecs_ac.diff

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue24824>
_______________________________________


More information about the Python-bugs-list mailing list