Commit Graph

45 Commits

Author SHA1 Message Date
Georg Brandl 1fb9f528bd Typo fix. 2006-05-11 19:57:09 +00:00
Nick Coghlan afd5e63e24 Finish bringing SVN into line with latest version of PEP 343 by getting rid of all remaining references to context objects that I could find. Without a __context__() method context objects no longer exist. Also get test_with working again, and adopt a suggestion from Neal for decimal.Context.get_manager() 2006-05-03 13:02:47 +00:00
Guido van Rossum da5b701aee Get rid of __context__, per the latest changes to PEP 343 and python-dev
discussion.
There are two places of documentation that still mention __context__:
Doc/lib/libstdtypes.tex -- I wasn't quite sure how to rewrite that without
spending a whole lot of time thinking about it; and whatsnew, which Andrew
usually likes to change himself.
2006-05-02 19:47:52 +00:00
Nick Coghlan a7e820a408 Move the PEP 343 documentation and implementation closer to the
terminology in the alpha 1 documentation.

 - "context manager" reverts to its alpha 1 definition
 - the term "context specifier" goes away entirely
 - contextlib.GeneratorContextManager is renamed GeneratorContext

There are still a number of changes relative to alpha 1:

  - the expression in the with statement is explicitly called the
    "context expression" in the language reference
  - the terms 'with statement context', 'context object' or 'with
    statement context' are used in several places instead of a bare
    'context'. The aim of this is to avoid ambiguity in relation to the
    runtime context set up when the block is executed, and the context
    objects that already exist in various application domains (such as
    decimal.Context)
  - contextlib.contextmanager is renamed to contextfactory
    This best reflects the nature of the function resulting from the
    use of that decorator
  - decimal.ContextManager is renamed to WithStatementContext
    Simple dropping the 'Manager' part wasn't possible due to the
    fact that decimal.Context already exists and means something
    different. WithStatementContext is ugly but workable.

A technically unrelated change snuck into this commit:
contextlib.closing now avoids the overhead of creating a
generator, since it's trivial to implement that particular
context manager directly.
2006-04-25 10:56:51 +00:00
Guido van Rossum f669436189 Um, I thought I'd already checked this in.
Anyway, this is the changes to the with-statement
so that __exit__ must return a true value in order
for a pending exception to be ignored.
The PEP (343) is already updated.
2006-03-10 02:28:35 +00:00
Guido van Rossum 1a5e21e033 Updates to the with-statement:
- New semantics for __exit__() -- it must re-raise the exception
  if type is not None; the with-statement itself doesn't do this.
  (See the updated PEP for motivation.)

- Added context managers to:
  - file
  - thread.LockType
  - threading.{Lock,RLock,Condition,Semaphore,BoundedSemaphore}
  - decimal.Context

- Added contextlib.py, which defines @contextmanager, nested(), closing().

- Unit tests all around; bot no docs yet.
2006-02-28 21:57:43 +00:00
Georg Brandl f33d01d304 bug [ 1266296 ] Mistakes in decimal.Context.subtract documentation 2005-08-22 19:35:18 +00:00
Raymond Hettinger e5a0a9609f Apply the _is_special guard. 2005-06-20 09:49:42 +00:00
Raymond Hettinger eb2608415e Minor namespace clean-up. 2005-06-07 18:52:34 +00:00
Raymond Hettinger 267b868f23 * Fix decimal's handling of foreign types. Now returns NotImplemented
instead of raising a TypeError.  Allows other types to successfully
  implement __radd__() style methods.
* Remove future division import from test suite.
* Remove test suite's shadowing of __builtin__.dir().
2005-03-27 10:47:39 +00:00
Raymond Hettinger bea3f6f5c7 Bug #1163325: "special" decimals aren't hashable 2005-03-15 04:59:17 +00:00
Brett Cannon 46b0802ccd Fix small grammatical error in a docstring. 2005-03-01 03:12:26 +00:00
Raymond Hettinger dbecd93b72 Replace list of constants with tuples of constants. 2005-02-06 06:57:08 +00:00
Raymond Hettinger 7e71fa5cfa Bug #1083645
* The decimal module wouldn't load on builds without threads.
2004-12-18 19:07:19 +00:00
Raymond Hettinger 605ed02483 SF bug #1071588 coercing decimal to int doesn't work between -1 and 1 2004-11-24 07:28:48 +00:00
Raymond Hettinger 17931de110 SF patch #1053375.
(Contributed by Facundo Batista.)

Code simplification by eliminating the unnecessary and error-prone
convolutions for the previously weird sign convention in _WorkRep().
Makes the code more understandable, more reliable, and a bit faster.
2004-10-27 06:21:46 +00:00
Facundo Batista 99b5548298 Very few little improvements. 2004-10-26 23:38:46 +00:00
Raymond Hettinger 76e60d687d SF bug #1048728: Bug fixes and cleanup for decimal.py
(Contributed by Neal Norwitz.  Reviewed by Facundo Bastista.)
2004-10-20 06:58:28 +00:00
Raymond Hettinger abf8a56e68 Don't use mutable values for method defaults. 2004-10-12 09:12:16 +00:00
Raymond Hettinger dab988dd23 SF patch #1043218
Simplify internal calls and logic for _fix() and _fixexponents().
(Contributed by Facundo Batista.)
2004-10-09 07:10:44 +00:00
Raymond Hettinger 4837a223ee Use floor division operator. 2004-09-27 14:23:40 +00:00
Raymond Hettinger 636a6b100f SF patch #1020845: Decimal performance enhancements
(Contributed by Nick Coghlan.)

Various code cleanups and optimizations (saves about 40% on testsuite
execution time and on the telco benchmark).

* caches results of various operations on self (esp. checks for being
  a special value).

* _WorkRep now uses ints and longs for intermediate computations.
2004-09-19 01:54:09 +00:00
Raymond Hettinger 27dbcf2162 Establish policies with respect to 2.3 compatibilty and treated spec
updates as bugfixes.
2004-08-19 22:39:55 +00:00
Raymond Hettinger d6c700a320 Revise max() and min() to comply with the 8/2/2004 update to the specification
(version 1.45):

The max and min operations follow the rules in the current IEEE 754 revision draft:
if one operand is a quiet NaN and the other is number, then the number is always returned
if both operands are finite and equal in numerical value then an ordering is applied:
    if the signs differ then max returns the operand with the positive sign and
    min returns the operand with the negative sign; if the signs are the same then
    the exponent is used to select the result.
2004-08-17 06:39:37 +00:00
Raymond Hettinger 9fce44bc8c * Context.copy() now makes a deepcopy.
* Facilitate reloads of local thread.
2004-08-08 04:03:24 +00:00
Raymond Hettinger 61992efc4b SF bug #1002530: test_decimal fails if repeated
* Protect the pre-defined contexts by using a deepcopy() instead of copy().
* Micro-optimization:  prefer x&1 over x%2
2004-08-06 23:42:16 +00:00
Raymond Hettinger ef66debd7e Use threading.local() instead of threading.currentThread(). 2004-07-14 21:04:27 +00:00
Raymond Hettinger 99148e7eaa Factor out two unnecessary global variables. 2004-07-14 19:56:56 +00:00
Raymond Hettinger b91af521fd * Hide a loop induction variable that was inadvertantly being picked up
by the locals() call in the context constructor.

* Remove unnecessary properties for int, exp, and sign which duplicated
  information returned by as_tuple().
2004-07-14 16:35:30 +00:00
Raymond Hettinger fed52963fc * Rename "Signals" to "_signals" making it non-public.
* Context.create_decimal can take a zero default just like Decimal().
* Fix typo in comment.
2004-07-14 15:41:57 +00:00
Raymond Hettinger bf4406971c Improve Context construction and representation:
* Rename "trap_enablers" to just "traps".
* Simplify names of "settraps" and "setflags" to just "traps" and "flags".
* Show "capitals" in the context representation
* Simplify the Context constructor to match its repr form so that only
  the set flags and traps need to be listed.
* Representation can now be run through eval().

Improve the error message when the Decimal constructor is given a float.

The test suite no longer needs a duplicate reset_flags method.
2004-07-10 14:14:37 +00:00
Raymond Hettinger d87ac8f24d * Update the test suite to reflect that ConversionSyntax was no longer
public.
* Removed the non-signal conditions from __all__.
* Removed the XXX comment which was resolved.
* Use ^ instead of operator.xor
* Remove the threading lock which is no longer necessary.
2004-07-09 10:52:54 +00:00
Raymond Hettinger 5aa478badf Module and tests:
* Map conditions to related signals.
* Make contexts unhashable.
* Eliminate used "default" attribute in exception definitions.
* Eliminate the _filterfunc in favor of a straight list.

Docs:
* Eliminate documented references to conditions that are not signals.
* Eliminate parenthetical notes such as "1/0 --> Inf" which are no
  longer true with the new defaults.
2004-07-09 10:02:53 +00:00
Raymond Hettinger bd7f76dd04 Tim gets his default traps. 2004-07-08 00:49:18 +00:00
Tim Peters 4e0e1b6a54 Whitespace normalization. 2004-07-07 20:54:48 +00:00
Raymond Hettinger 0aeac107ca * Add __eq__ and __ne__ so that things like list.index() work properly
for lists of mixed types.
* Test that sort works.
2004-07-05 22:53:03 +00:00
Raymond Hettinger ca3cc2fe21 * Update the todo list.
* Make ConversionSyntax signals get trapped by default.
2004-07-05 18:48:22 +00:00
Raymond Hettinger e0f1581bab * Fixup docstrings
* Make capitals default part of DefaultContext
2004-07-05 05:36:39 +00:00
Raymond Hettinger 0ea241e9e2 Changed the rounding constant values to match their variable names.
This serves to made the context representation more useful (the names in
match the names out).

Removed the link to ReXX.  That document did not shed add anything to
information already in the spec.

Further tighten the public API to improve usability:

* Emax and Emin are set through Context().  Their defaults are set in the
  DefaultContext, so there is no need to expose DEFAULT_MAX_EXPONENT
  and DEFAULT_MIN_EXPONENT.

* The string functions isnan() and isinfinity() were only used internal to
  the module and were not among the test cases.  External use cases are
  served by the Decimal constructor.  So, made these private.
2004-07-04 13:53:24 +00:00
Raymond Hettinger b1b605ef54 Fix clear_flags(). Make a readable (not evalable) Context repr. 2004-07-04 01:55:39 +00:00
Raymond Hettinger 9ec3e3b6eb Namespace cleanups:
* delete temporary globals immediately after use
* move a global into a class variable
* Rename BasicDefaultContext and ExtendedDefaultContext
  to BasicContext and ExtendedContext.
2004-07-03 13:48:56 +00:00
Raymond Hettinger 6ea4845822 * Make the tests independent of the default precision.
* Change the default precision to 28 (to match VB's decimal type).
2004-07-03 12:26:21 +00:00
Raymond Hettinger d9c0a7ae94 Work through several open todos:
* Added test for pickling contexts
* Renamed ExceptionList to Signals (to match wording in the spec)
* Simplified Context constructor by allowing flags=None to automatically
  generate a zeroed-out flags dictionary.
* inlined _convertString() which was used only once
* _rounding_decision is private, so excluded its contants from __all__.
* added an XXX comment with concerns about subclassing signals results in
  a deviation from the spec (maybe important, maybe not).
* Taught the test_suite to determine its own directory (modeled after code
  in regrtest.py).  Enables it to be run when the current directory is not
  the test directory.
* Added a clear_flags() method to the Context API to make it easier to do
  a common operation with flags.
* Fixed the trap_enablers defaults in BasicDefaultContext to match the spec.
2004-07-03 10:02:28 +00:00
Fred Drake 1f34eb17b5 fix small consistency nit 2004-07-01 14:28:36 +00:00
Raymond Hettinger 7c85fa4a52 Move Decimal from the sandbox into production. 2004-07-01 11:01:35 +00:00