| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 71316b0 commit a156e09
35 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -92,3 +92,9 @@ no longer available. | |||
| 92 | 92 | .. cfunction:: PyObject* PyMethod_GET_SELF(PyObject *meth) | |
| 93 | 93 | ||
| 94 | 94 | Macro version of :cfunc:`PyMethod_Self` which avoids error checking. | |
| 95 | + | ||
| 96 | + | ||
| 97 | + .. cfunction:: int PyMethod_ClearFreeList(void) | ||
| 98 | + | ||
| 99 | + Clear the free list. Return the total number of freed items. | ||
| 100 | + | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -54,15 +54,11 @@ the constructor functions work with any iterable Python object. | |||
| 54 | 54 | ||
| 55 | 55 | Return true if *p* is a :class:`set` object or an instance of a subtype. | |
| 56 | 56 | ||
| 57 | - .. versionadded:: 2.6 | ||
| 58 | - | ||
| 59 | 57 | .. cfunction:: int PyFrozenSet_Check(PyObject *p) | |
| 60 | 58 | ||
| 61 | 59 | Return true if *p* is a :class:`frozenset` object or an instance of a | |
| 62 | 60 | subtype. | |
| 63 | 61 | ||
| 64 | - .. versionadded:: 2.6 | ||
| 65 | - | ||
| 66 | 62 | .. cfunction:: int PyAnySet_Check(PyObject *p) | |
| 67 | 63 | ||
| 68 | 64 | Return true if *p* is a :class:`set` object, a :class:`frozenset` object, or an | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -105,3 +105,7 @@ Tuple Objects | |||
| 105 | 105 | this function. If the object referenced by ``*p`` is replaced, the original | |
| 106 | 106 | ``*p`` is destroyed. On failure, returns ``-1`` and sets ``*p`` to *NULL*, and | |
| 107 | 107 | raises :exc:`MemoryError` or :exc:`SystemError`. | |
| 108 | + | ||
| 109 | + .. cfunction:: int PyMethod_ClearFreeList(void) | ||
| 110 | + | ||
| 111 | + Clear the free list. Return the total number of freed items. | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -37,8 +37,6 @@ Type Objects | |||
| 37 | 37 | ||
| 38 | 38 | Clears the internal lookup cache. Return the current version tag. | |
| 39 | 39 | ||
| 40 | - .. versionadded:: 2.6 | ||
| 41 | - | ||
| 42 | 40 | ||
| 43 | 41 | .. cfunction:: int PyType_HasFeature(PyObject *o, int feature) | |
| 44 | 42 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -83,6 +83,11 @@ access internal read-only data of Unicode objects: | |||
| 83 | 83 | Return a pointer to the internal buffer of the object. *o* has to be a | |
| 84 | 84 | :ctype:`PyUnicodeObject` (not checked). | |
| 85 | 85 | ||
| 86 | + | ||
| 87 | + .. cfunction:: int PyUnicode_ClearFreeList(void) | ||
| 88 | + | ||
| 89 | + Clear the free list. Return the total number of freed items. | ||
| 90 | + | ||
| 86 | 91 | Unicode provides many different character properties. The most often needed ones | |
| 87 | 92 | are available through these macros which are mapped to C functions depending on | |
| 88 | 93 | the Python configuration. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2010,7 +2010,6 @@ Fundamental data types | |||
| 2010 | 2010 | their methods and attributes. | |
| 2011 | 2011 | ||
| 2012 | 2012 | .. versionchanged:: 2.6 | |
| 2013 | - | ||
| 2014 | 2013 | ctypes data types that are not and do not contain pointers can | |
| 2015 | 2014 | now be pickled. | |
| 2016 | 2015 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1352,19 +1352,15 @@ to work with the :class:`Decimal` class:: | |||
| 1352 | 1352 | '<.02>' | |
| 1353 | 1353 | ||
| 1354 | 1354 | """ | |
| 1355 | - q = Decimal((0, (1,), -places)) # 2 places --> '0.01' | ||
| 1356 | - sign, digits, exp = value.quantize(q).as_tuple() | ||
| 1357 | - assert exp == -places | ||
| 1355 | + q = Decimal(10) ** -places # 2 places --> '0.01' | ||
| 1356 | + sign, digits, exp = value.quantize(q).as_tuple() | ||
| 1358 | 1357 | result = [] | |
| 1359 | 1358 | digits = map(str, digits) | |
| 1360 | 1359 | build, next = result.append, digits.pop | |
| 1361 | 1360 | if sign: | |
| 1362 | 1361 | build(trailneg) | |
| 1363 | 1362 | for i in range(places): | |
| 1364 | - if digits: | ||
| 1365 | - build(next()) | ||
| 1366 | - else: | ||
| 1367 | - build('0') | ||
| 1363 | + build(next() if digits else '0') | ||
| 1368 | 1364 | build(dp) | |
| 1369 | 1365 | i = 0 | |
| 1370 | 1366 | while digits: | |
@@ -1374,12 +1370,8 @@ to work with the :class:`Decimal` class:: | |||
| 1374 | 1370 | i = 0 | |
| 1375 | 1371 | build(sep) | |
| 1376 | 1372 | build(curr) | |
| 1377 | - if sign: | ||
| 1378 | - build(neg) | ||
| 1379 | - else: | ||
| 1380 | - build(pos) | ||
| 1381 | - result.reverse() | ||
| 1382 | - return ''.join(result) | ||
| 1373 | + build(neg if sign else pos) | ||
| 1374 | + return ''.join(reversed(result)) | ||
| 1383 | 1375 | ||
| 1384 | 1376 | def pi(): | |
| 1385 | 1377 | """Compute Pi to the current precision. | |
@@ -1482,7 +1474,7 @@ Decimal FAQ | |||
| 1482 | 1474 | Q. It is cumbersome to type ``decimal.Decimal('1234.5')``. Is there a way to | |
| 1483 | 1475 | minimize typing when using the interactive interpreter? | |
| 1484 | 1476 | ||
| 1485 | - \A. Some users abbreviate the constructor to just a single letter:: | ||
| 1477 | + A. Some users abbreviate the constructor to just a single letter:: | ||
| 1486 | 1478 | ||
| 1487 | 1479 | >>> D = decimal.Decimal | |
| 1488 | 1480 | >>> D('1.23') + D('3.45') | |
@@ -1513,9 +1505,36 @@ the :const:`Inexact` trap is set, it is also useful for validation:: | |||
| 1513 | 1505 | Q. Once I have valid two place inputs, how do I maintain that invariant | |
| 1514 | 1506 | throughout an application? | |
| 1515 | 1507 | ||
| 1516 | - A. Some operations like addition and subtraction automatically preserve fixed | ||
| 1517 | - point. Others, like multiplication and division, change the number of decimal | ||
| 1518 | - places and need to be followed-up with a :meth:`quantize` step. | ||
| 1508 | + A. Some operations like addition, subtraction, and multiplication by an integer | ||
| 1509 | + will automatically preserve fixed point. Others operations, like division and | ||
| 1510 | + non-integer multiplication, will change the number of decimal places and need to | ||
| 1511 | + be followed-up with a :meth:`quantize` step:: | ||
| 1512 | + | ||
| 1513 | + >>> a = Decimal('102.72') # Initial fixed-point values | ||
| 1514 | + >>> b = Decimal('3.17') | ||
| 1515 | + >>> a + b # Addition preserves fixed-point | ||
| 1516 | + Decimal('105.89') | ||
| 1517 | + >>> a - b | ||
| 1518 | + Decimal('99.55') | ||
| 1519 | + >>> a * 42 # So does integer multiplication | ||
| 1520 | + Decimal('4314.24') | ||
| 1521 | + >>> (a * b).quantize(TWOPLACES) # Must quantize non-integer multiplication | ||
| 1522 | + Decimal('325.62') | ||
| 1523 | + >>> (b / a).quantize(TWOPLACES) # And quantize division | ||
| 1524 | + Decimal('0.03') | ||
| 1525 | + | ||
| 1526 | + In developing fixed-point applications, it is convenient to define functions | ||
| 1527 | + to handle the :meth:`quantize` step:: | ||
| 1528 | + | ||
| 1529 | + >>> def mul(x, y, fp=TWOPLACES): | ||
| 1530 | + ... return (x * y).quantize(fp) | ||
| 1531 | + >>> def div(x, y, fp=TWOPLACES): | ||
| 1532 | + ... return (x / y).quantize(fp) | ||
| 1533 | + | ||
| 1534 | + >>> mul(a, b) # Automatically preserve fixed-point | ||
| 1535 | + Decimal('325.62') | ||
| 1536 | + >>> div(b, a) | ||
| 1537 | + Decimal('0.03') | ||
| 1519 | 1538 | ||
| 1520 | 1539 | Q. There are many ways to express the same value. The numbers :const:`200`, | |
| 1521 | 1540 | :const:`200.000`, :const:`2E2`, and :const:`.02E+4` all have the same value at | |
@@ -1537,6 +1556,16 @@ of significant places in the coefficient. For example, expressing | |||
| 1537 | 1556 | :const:`5.0E+3` as :const:`5000` keeps the value constant but cannot show the | |
| 1538 | 1557 | original's two-place significance. | |
| 1539 | 1558 | ||
| 1559 | + If an application does not care about tracking significance, it is easy to | ||
| 1560 | + remove the exponent and trailing zeroes, losing signficance, but keeping the | ||
| 1561 | + value unchanged:: | ||
| 1562 | + | ||
| 1563 | + >>> def remove_exponent(d): | ||
| 1564 | + ... return d.quantize(Decimal(1)) if d == d.to_integral() else d.normalize() | ||
| 1565 | + | ||
| 1566 | + >>> remove_exponent(Decimal('5E+3')) | ||
| 1567 | + Decimal('5000') | ||
| 1568 | + | ||
| 1540 | 1569 | Q. Is there a way to convert a regular float to a :class:`Decimal`? | |
| 1541 | 1570 | ||
| 1542 | 1571 | A. Yes, all binary floating point numbers can be exactly expressed as a | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -825,7 +825,7 @@ complete list of changes, or look through the CVS logs for all the details. | |||
| 825 | 825 | int int | |
| 826 | 826 | >>> var._asdict() | |
| 827 | 827 | {'size': 4, 'type': 'int', 'id': 1, 'name': 'frequency'} | |
| 828 | - >>> v2 = var._replace('name', 'amplitude') | ||
| 828 | + >>> v2 = var._replace(name='amplitude') | ||
| 829 | 829 | >>> v2 | |
| 830 | 830 | variable(id=1, name='amplitude', type='int', size=4) | |
| 831 | 831 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -31,6 +31,7 @@ PyAPI_FUNC(PyObject *) PyMethod_Self(PyObject *); | |||
| 31 | 31 | #define PyMethod_GET_SELF(meth) \ | |
| 32 | 32 | (((PyMethodObject *)meth) -> im_self) | |
| 33 | 33 | ||
| 34 | + PyAPI_FUNC(int) PyMethod_ClearFreeList(void); | ||
| 34 | 35 | ||
| 35 | 36 | typedef struct { | |
| 36 | 37 | PyObject_HEAD | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -73,6 +73,8 @@ PyAPI_FUNC(PyObject **) PyFrame_ExtendStack(PyFrameObject *, int, int); | |||
| 73 | 73 | PyAPI_FUNC(void) PyFrame_LocalsToFast(PyFrameObject *, int); | |
| 74 | 74 | PyAPI_FUNC(void) PyFrame_FastToLocals(PyFrameObject *); | |
| 75 | 75 | ||
| 76 | + PyAPI_FUNC(int) PyFrame_ClearFreeList(void); | ||
| 77 | + | ||
| 76 | 78 | #ifdef __cplusplus | |
| 77 | 79 | } | |
| 78 | 80 | #endif | |
| Back | FazBrowse Home | New Git URL |
0 commit comments