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.

classification
Title: Failing decimal doctest
Type: behavior Stage:
Components: Library (Lib) Versions: Python 2.6
process
Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: facundobatista Nosy List: benjamin.peterson, facundobatista, mark.dickinson
Priority: normal Keywords: patch

Created on 2008-04-30 21:28 by benjamin.peterson, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
decimal_localcontext.patch mark.dickinson, 2008-05-01 02:27
Messages (4)
msg66026 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2008-04-30 21:28
I was removing from __future__ import with_statment in the stdlib when I
came across this disabled doctest in decimal.py:

    # The string below can't be included in the docstring until Python 2.6
    # as the doctest module doesn't understand __future__ statements
    """
    >>> from __future__ import with_statement
    >>> print getcontext().prec
    28
    >>> with localcontext():
    ...     ctx = getcontext()
    ...     ctx.prec += 2
    ...     print ctx.prec
    ...
    30
    >>> with localcontext(ExtendedContext):
    ...     print getcontext().prec
    ...
    9
    >>> print getcontext().prec
    28
    """

When it was enabled, it failed.
msg66030 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2008-05-01 01:59
There are a couple of problems here.  The direct reason for the failure is 
that there's an earlier doctest (around line 61 of decimal.py) that sets 
the precision of the current context to 18 instead of its default value of 
28.

The obvious fix is to add a line:

>>> setcontext(DefaultContext)

just after the '>>> from __future__ import with_statement' line (around 
line 480 of decimal.py), to restore the original context.

*but*...

that doesn't work, because test_decimal.py clobbers DefaultContext (and it 
shouldn't, in my opinion).

I've attached a patch that might fix these problems, and that also enables 
this doctest.  I'm not sure that this patch is necessarily the best way of 
going about things, though.
msg66031 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2008-05-01 02:27
Removed the old patch.

Here's a better patch, that avoids changing the semantics of the 
threading tests.

As far as I can tell, the setting and resetting of DefaultContext traps 
in DecimalTest's setUp and tearDown method was pointless, since that 
test doesn't use the DefaultContext:  it uses its own freshly created 
context instead.  So the patch removes the setting of traps from setUp, 
and removes tearDown entirely.
msg66100 - (view) Author: Facundo Batista (facundobatista) * (Python committer) Date: 2008-05-02 17:39
Commited, r62638. Thank you both!
History
Date User Action Args
2022-04-11 14:56:33adminsetgithub: 46980
2008-05-02 17:39:20facundobatistasetstatus: open -> closed
resolution: accepted
messages: + msg66100
2008-05-01 02:27:43mark.dickinsonsetfiles: + decimal_localcontext.patch
messages: + msg66031
2008-05-01 02:23:18mark.dickinsonsetfiles: - decimal_localcontext.patch
2008-05-01 01:59:50mark.dickinsonsetfiles: + decimal_localcontext.patch
assignee: facundobatista
messages: + msg66030
keywords: + patch
nosy: + mark.dickinson, facundobatista
2008-04-30 21:28:39benjamin.petersoncreate