Author yselivanov
Recipients doerwalter, larry, lemburg, ncoghlan, serhiy.storchaka, yselivanov
Date 2015-08-08.15:48:16
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1439048898.6.0.0152873821019.issue24824@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2015-08-08 15:48:18yselivanovsetrecipients: + yselivanov, lemburg, doerwalter, ncoghlan, larry, serhiy.storchaka
2015-08-08 15:48:18yselivanovsetmessageid: <1439048898.6.0.0152873821019.issue24824@psf.upfronthosting.co.za>
2015-08-08 15:48:18yselivanovlinkissue24824 messages
2015-08-08 15:48:17yselivanovcreate