This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author ncoghlan
Recipients Arfrever, ezio.melotti, georg.brandl, mark.dickinson, ncoghlan, rhettinger, skrah, zach.ware
Date 2012-08-28.06:13:10
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1346134391.79.0.896505715927.issue15783@psf.upfronthosting.co.za>
In-reply-to
Content
Note that it's only the 3.2 interactive help that specifies "ctx=None", and it's almost certainly lifting that directly from the Python implementation.

The C implementation is definitely in compliance with the prose docs, which give the signature as localcontext([c]) and say "If no context is specified, a copy of the current context is used" without indicating whether passing in None explicitly is supposed to count as not specifying a context.

However, the specific problem that prompted this report is that you used to be able to write code like:

  def my_decimal_func(arg1, arg2, context=None):
    with decimal.localcontext(context):
        # perform decimal operations on arg1 and arg2

but with the C implementation, such code will break. You have to instead write something less idiomatic like:

  def my_decimal_func(arg1, arg2, *context):
    with decimal.localcontext(*context):
        # perform decimal operations on arg1 and arg2

Any third party Decimal manipulating function that accepts an optional context and passes it down to the standard Decimal API will be confronted with the same problem in 3.3: passing None as the context no longer means the same thing as omitting the context argument entirely.

We can either handle this as a documentation issue (recommending the *args based idiom above as an alternative to passing an explicit None), or else change the C implementation to accept context=None as equivalent to omitting the context argument entirely.

I'm inclined towards the latter, simply due to the backwards compatibility breach: explicitly calling localcontext(None) would indeed be silly, but calling localcontext(context), where context comes from a parameter with a default value of None, is perfectly normal Python code. Idiomatic code that worked correctly in the previous Python version is a reasonably strong argument in favour of retaining the feature.
History
Date User Action Args
2012-08-28 06:13:11ncoghlansetrecipients: + ncoghlan, georg.brandl, rhettinger, mark.dickinson, ezio.melotti, Arfrever, skrah, zach.ware
2012-08-28 06:13:11ncoghlansetmessageid: <1346134391.79.0.896505715927.issue15783@psf.upfronthosting.co.za>
2012-08-28 06:13:11ncoghlanlinkissue15783 messages
2012-08-28 06:13:10ncoghlancreate