summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_long.py
Commit message (Collapse)AuthorAgeFilesLines
* gh-101266: Fix __sizeof__ for subclasses of int (#101394)Mark Dickinson2023-02-051-0/+39
| | | | | | | Fix the behaviour of the `__sizeof__` method (and hence the results returned by `sys.getsizeof`) for subclasses of `int`. Previously, `int` subclasses gave identical results to the `int` base class, ignoring the presence of the instance dictionary. <!-- gh-issue-number: gh-101266 --> * Issue: gh-101266 <!-- /gh-issue-number -->
* gh-100268: Add is_integer method to int (#100439)Shantanu2022-12-241-0/+5
| | | This improves the lives of type annotation users of `float` - which type checkers implicitly treat as `int|float` because that is what most code actually wants. Before this change a `.is_integer()` method could not be assumed to exist on things annotated as `: float` due to the method not existing on both types.
* gh-98783: Fix crashes when `str` subclasses are used in `_PyUnicode_Equal` ↵Nikita Sobolev2022-10-301-0/+12
| | | | (#98806)
* gh-94808: Cover `PyObject_PyBytes` case with custom `__bytes__` method (#96610)Nikita Sobolev2022-10-061-0/+16
| | | Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
* gh-90213: Speed up right shifts of negative integers (GH-30277)Mark Dickinson2022-05-021-0/+4
|
* gh-91117: Ensure integer mod and pow operations use cached small ints (GH-31843)Dennis Sweeney2022-04-111-0/+42
|
* bpo-44977: Deprecate delegation of int to __trunc__ (GH-31031)Zackery Spytz2022-02-031-1/+2
| | | | | Calling int(a) when type(a) implements __trunc__ but not __int__ or __index__ now raises a DeprecationWarning.
* bpo-46361: Fix "small" `int` caching (GH-30583)Brandt Bucher2022-01-161-0/+7
|
* bpo-46233: Minor speedup for bigint squaring (GH-30345)Tim Peters2022-01-041-0/+11
| | | | | | | x_mul()'s squaring code can do some redundant and/or useless work at the end of each digit pass. A more careful analysis of worst-case carries at various digit positions allows making that code leaner.
* bpo-46055: Speed up binary shifting operators (GH-30044)Xinhang Xu2021-12-271-2/+61
| | | Co-authored-by: Mark Dickinson <dickinsm@gmail.com>
* Fix typos in the Lib directory (GH-28775)Christian Clauss2021-10-061-1/+1
| | | | | Fix typos in the Lib directory as identified by codespell. Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
* bpo-45155 : Default arguments for int.to_bytes(length=1, ↵Barry Warsaw2021-09-161-2/+22
| | | | | | | byteorder=sys.byteorder) (#28265) Add default arguments for int.to_bytes() and int.from_bytes() Co-authored-by: Brandt Bucher <brandtbucher@gmail.com>
* bpo-16580: [doc] Add examples to int.to_bytes and int.from_bytes (GH-27760)Gautam Chaudhuri2021-08-151-0/+42
| | | | | | | | | | * added code equivs. for to_bytes and from_bytes Based on woparry's patch[1] from the relevant issue thread[2]. [1]: https://bugs.python.org/file30372/issue16580.patch [2]: https://bugs.python.org/issue16580 Co-authored-by: Mark Dickinson <dickinsm@gmail.com>
* Revert "bpo-26680: Incorporate is_integer in all built-in and standard ↵Raymond Hettinger2020-10-071-4/+0
| | | | | library numeric types (GH-6121)" (GH-22584) This reverts commit 58a7da9e125422323f79c4ee95ac5549989d8162.
* bpo-26680: Incorporate is_integer in all built-in and standard library ↵Robert Smallshire2020-10-011-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | numeric types (GH-6121) * bpo-26680: Adds support for int.is_integer() for compatibility with float.is_integer(). The int.is_integer() method always returns True. * bpo-26680: Adds a test to ensure that False.is_integer() and True.is_integer() are always True. * bpo-26680: Adds Real.is_integer() with a trivial implementation using conversion to int. This default implementation is intended to reduce the workload for subclass implementers. It is not robust in the presence of infinities or NaNs and may have suboptimal performance for other types. * bpo-26680: Adds Rational.is_integer which returns True if the denominator is one. This implementation assumes the Rational is represented in it's lowest form, as required by the class docstring. * bpo-26680: Adds Integral.is_integer which always returns True. * bpo-26680: Adds tests for Fraction.is_integer called as an instance method. The tests for the Rational abstract base class use an unbound method to sidestep the inability to directly instantiate Rational. These tests check that everything works correct as an instance method. * bpo-26680: Updates documentation for Real.is_integer and built-ins int and float. The call x.is_integer() is now listed in the table of operations which apply to all numeric types except complex, with a reference to the full documentation for Real.is_integer(). Mention of is_integer() has been removed from the section 'Additional Methods on Float'. The documentation for Real.is_integer() describes its purpose, and mentions that it should be overridden for performance reasons, or to handle special values like NaN. * bpo-26680: Adds Decimal.is_integer to the Python and C implementations. The C implementation of Decimal already implements and uses mpd_isinteger internally, we just expose the existing function to Python. The Python implementation uses internal conversion to integer using to_integral_value(). In both cases, the corresponding context methods are also implemented. Tests and documentation are included. * bpo-26680: Updates the ACKS file. * bpo-26680: NEWS entries for int, the numeric ABCs and Decimal. Co-authored-by: Robert Smallshire <rob@sixty-north.com>
* bpo-29882: Add an efficient popcount method for integers (#771)Niklas Fiekas2020-05-291-0/+11
| | | | | | | | | | | | | | | | | | | | | | | * bpo-29882: Add an efficient popcount method for integers * Update 'sign bit' and versionadded in docs * Add entry to whatsnew document * Doc: use positive example, mention population count * Minor cleanups of the core code * Move popcount_digit closer to where it's used * Use z instead of self after conversion * Add 'absolute value' and 'population count' to docstring * Fix clinic error about missing summary line * Ensure popcount_digit is portable with 64-bit ints Co-authored-by: Mark Dickinson <dickinsm@gmail.com>
* bpo-27145: small_ints[x] could be returned in long_add and long_sub (GH-15716)HongWeipeng2019-11-261-0/+8
|
* bpo-33073: Rework int.as_integer_ratio() implementation (GH-9303)Serhiy Storchaka2018-10-191-28/+6
| | | | | * Simplify the C code. * Simplify tests and make them more strict and robust. * Add references in the documentation.
* closes bpo-34868: Improve error message with '_' is combined with an invalid ↵Benjamin Peterson2018-10-021-0/+3
| | | | type specifier. (GH-9666)
* bpo-33073: Adding as_integer_ratio to ints. (GH-8750)Lisa Roach2018-09-141-0/+32
|
* bpo-34087: Fix buffer overflow in int(s) and similar functions (GH-8274)INADA Naoki2018-07-141-0/+4
| | | | | | `_PyUnicode_TransformDecimalAndSpaceToASCII()` missed trailing NUL char. It caused buffer overflow in `_Py_string_to_number_with_underscores()`. This bug is introduced in 9b6c60cb.
* bpo-29816: Shift operation now has less opportunity to raise OverflowError. ↵Serhiy Storchaka2017-03-301-2/+30
| | | | | | | (#680) ValueError always is raised rather than OverflowError for negative counts. Shifting zero with non-negative count always returns zero.
* Issue 27080: PEP 515: add '_' formatting option.Eric V. Smith2016-09-101-0/+28
|
* MergeRaymond Hettinger2016-09-031-1/+1
|\
| * Issue 27936: Fix inconsistent round() behavior between float and intRaymond Hettinger2016-09-031-1/+1
| |
* | Issue #27870: A left shift of zero by a large integer no longer attempts to ↵Mark Dickinson2016-08-291-0/+15
| | | | | | | | allocate large amounts of memory.
* | Issue #23640: int.from_bytes() no longer bypasses constructors for subclasses.Serhiy Storchaka2016-05-121-0/+17
|\ \ | |/
| * Issue #23640: int.from_bytes() no longer bypasses constructors for subclasses.Serhiy Storchaka2016-05-121-0/+17
| |
* | Issues #26289 and #26315: Optimize floor/modulo div for single-digit longsYury Selivanov2016-02-111-0/+33
|/ | | | | | | | | | | | | | Microbenchmarks show 2-2.5x improvement. Built-in 'divmod' function is now also ~10% faster. -m timeit -s "x=22331" "x//2;x//-3;x//4;x//5;x//-6;x//7;x//8;x//-99;x//100;" with patch: 0.321 without patch: 0.633 -m timeit -s "x=22331" "x%2;x%3;x%-4;x%5;x%6;x%-7;x%8;x%99;x%-100;" with patch: 0.224 without patch: 0.66 Big thanks to Serhiy Storchaka, Mark Dickinson and Victor Stinner for thorow code reviews and algorithms improvements.
* Issue #25211: Merge test_long from 3.4 into 3.5Martin Panter2015-09-261-88/+72
|\
| * Issue #25211: Eliminate lazy error message class by using subTestMartin Panter2015-09-251-88/+72
| | | | | | | | Some of the calls to the Frm class were buggy anyway.
* | Issue #21741: Update 147 test modules to use test discovery.Zachary Ware2015-04-131-4/+1
| | | | | | | | | | | | | | I have compared output between pre- and post-patch runs of these tests to make sure there's nothing missing and nothing broken, on both Windows and Linux. The only differences I found were actually tests that were previously *not* run.
* | Issue #23326: Removed __ne__ implementations. Since fixing default __ne__Serhiy Storchaka2015-01-311-2/+0
|/ | | | implementation in issue #21408 they are redundant.
* Issue #21422: Add a test to check that bool << int and bool >> int return an intVictor Stinner2014-05-121-0/+7
|
* Issue #20546: Use specific asserts in int tests.Serhiy Storchaka2014-02-081-24/+24
|\
| * Issue #20546: Use specific asserts in int tests.Serhiy Storchaka2014-02-081-24/+24
| |
* | Issue #18783: Removed existing mentions of Python long type in docstrings,Serhiy Storchaka2013-08-271-11/+4
|\ \ | |/ | | | | error messages and comments.
| * Issue #18783: Removed existing mentions of Python long type in docstrings,Serhiy Storchaka2013-08-271-11/+4
| | | | | | | | error messages and comments.
* | Issue #17516: do not create useless tuple: remove dummy commas in testsVictor Stinner2013-03-261-1/+1
|/
* Issue #14630: Merge fix from 3.2.Mark Dickinson2012-04-201-0/+14
|\
| * Issue #14630: Fix an incorrect access of ob_digit[0] for a zero instance of ↵Mark Dickinson2012-04-201-0/+14
| | | | | | | | an int subclass.
* | Issue #10925: Add equivalent pure Python code for the builtin int-to-float ↵Mark Dickinson2011-10-231-0/+80
|/ | | | conversion to test_long.
* Issue #10624: Use support.requires_IEEE_754 in all appropriate tests.Eric Smith2010-12-041-8/+3
|
* #1513299: cleanup some map() uses where a comprehension works better.Georg Brandl2010-12-041-1/+1
|
* Issue #2844: Make int('42', n) consistently raise ValueError forMark Dickinson2010-05-261-0/+10
| | | | invalid integers n (including n = -909).
* Merged revisions 81551 via svnmerge fromMark Dickinson2010-05-261-0/+15
| | | | | | | | | | svn+ssh://pythondev@svn.python.org/python/trunk ........ r81551 | mark.dickinson | 2010-05-26 20:06:33 +0100 (Wed, 26 May 2010) | 1 line Issue #8825: additional testcases for int(string, 0) and long(string, 0). ........
* Merged revisions 78093 via svnmerge fromGeorg Brandl2010-03-141-5/+0
| | | | | | | | | | svn+ssh://pythondev@svn.python.org/python/trunk ........ r78093 | georg.brandl | 2010-02-07 18:03:15 +0100 (So, 07 Feb 2010) | 1 line Remove unused imports in test modules. ........
* Merged revisions ↵Georg Brandl2010-03-141-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 78018,78035-78040,78042-78043,78046,78048-78052,78054,78059,78075-78080 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r78018 | georg.brandl | 2010-02-06 11:08:21 +0100 (Sa, 06 Feb 2010) | 1 line #7864: make deprecation notices a bit clearer. ........ r78035 | georg.brandl | 2010-02-06 23:44:17 +0100 (Sa, 06 Feb 2010) | 1 line Fix duplicate import. ........ r78036 | georg.brandl | 2010-02-06 23:49:47 +0100 (Sa, 06 Feb 2010) | 1 line Remove unused import. ........ r78037 | georg.brandl | 2010-02-06 23:59:15 +0100 (Sa, 06 Feb 2010) | 1 line No need to assign the results of expressions used only for side effects. ........ r78038 | georg.brandl | 2010-02-07 00:02:29 +0100 (So, 07 Feb 2010) | 1 line Add a missing import. ........ r78039 | georg.brandl | 2010-02-07 00:06:24 +0100 (So, 07 Feb 2010) | 1 line Add missing imports. ........ r78040 | georg.brandl | 2010-02-07 00:08:00 +0100 (So, 07 Feb 2010) | 1 line Fix a few UnboundLocalErrors in test_long. ........ r78042 | georg.brandl | 2010-02-07 00:12:12 +0100 (So, 07 Feb 2010) | 1 line Add missing import. ........ r78043 | georg.brandl | 2010-02-07 00:12:19 +0100 (So, 07 Feb 2010) | 1 line Remove duplicate test method. ........ r78046 | georg.brandl | 2010-02-07 00:18:00 +0100 (So, 07 Feb 2010) | 1 line Fix various missing import/unbound name errors. ........ r78048 | georg.brandl | 2010-02-07 00:23:45 +0100 (So, 07 Feb 2010) | 1 line We heard you like test failures so we put unbound locals in your test so that you can fail while you fail. ........ r78049 | georg.brandl | 2010-02-07 00:33:33 +0100 (So, 07 Feb 2010) | 1 line Fix import/access for some identifiers. _TestSharedCTypes does not seem to be executed? ........ r78050 | georg.brandl | 2010-02-07 00:34:10 +0100 (So, 07 Feb 2010) | 1 line Fix more unbound locals in code paths that do not seem to be used. ........ r78051 | georg.brandl | 2010-02-07 00:53:52 +0100 (So, 07 Feb 2010) | 1 line Add missing import when running these tests standalone. ........ r78052 | georg.brandl | 2010-02-07 00:54:04 +0100 (So, 07 Feb 2010) | 1 line Add missing import when running these tests standalone. ........ r78054 | georg.brandl | 2010-02-07 00:58:25 +0100 (So, 07 Feb 2010) | 1 line Add missing import. ........ r78059 | georg.brandl | 2010-02-07 12:34:15 +0100 (So, 07 Feb 2010) | 1 line Use "regexp" consistently. ........ r78075 | georg.brandl | 2010-02-07 13:16:12 +0100 (So, 07 Feb 2010) | 1 line Fix another duplicated test method. ........ r78076 | georg.brandl | 2010-02-07 13:19:43 +0100 (So, 07 Feb 2010) | 1 line Fix wrong usage of "except X, Y:". ........ r78077 | georg.brandl | 2010-02-07 13:25:50 +0100 (So, 07 Feb 2010) | 1 line Fix two redefined test methods. ........ r78078 | georg.brandl | 2010-02-07 13:27:06 +0100 (So, 07 Feb 2010) | 1 line Fix a redefined test method. ........ r78079 | georg.brandl | 2010-02-07 13:34:26 +0100 (So, 07 Feb 2010) | 1 line Add a minimal test for fnmatchcase(). ........ r78080 | georg.brandl | 2010-02-07 13:55:12 +0100 (So, 07 Feb 2010) | 1 line Remove duplicate test method. ........
* Issue #1023290: Added API for the conversion of longs to bytes and vice-versa.Alexandre Vassalotti2010-01-091-0/+232
|
* Merged revisions 77071 via svnmerge fromMark Dickinson2009-12-271-3/+2
| | | | | | | | | | svn+ssh://pythondev@svn.python.org/python/trunk ........ r77071 | mark.dickinson | 2009-12-27 21:31:50 +0000 (Sun, 27 Dec 2009) | 1 line Use a more idiomatic check in check_truediv. ........