Nick Coghlan added the comment:

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.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue15783>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to