diff options
| author | yum <yum.food.vr@gmail.com> | 2023-01-01 21:05:27 -0800 |
|---|---|---|
| committer | yum <yum.food.vr@gmail.com> | 2023-01-01 21:44:45 -0800 |
| commit | e25bdba3a3a53b09be5269d8b065c13b73ab55c3 (patch) | |
| tree | 1d1dc1d94cde92c2f4f8ce86017395054787515d /FOSS/Python/Dependencies/future-0.18.2/docs/int_object.rst | |
| parent | 0d408cc812a094a708edbe4baf536e928731cfc3 (diff) | |
Embed git in package
package.ps1 fetches PortableGit and embeds it in the package. This
eliminates all but one runtime dependency (MSVC++ Redistributable).
* Move Python into a new FOSS folder.
Diffstat (limited to 'FOSS/Python/Dependencies/future-0.18.2/docs/int_object.rst')
| -rw-r--r-- | FOSS/Python/Dependencies/future-0.18.2/docs/int_object.rst | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/FOSS/Python/Dependencies/future-0.18.2/docs/int_object.rst b/FOSS/Python/Dependencies/future-0.18.2/docs/int_object.rst new file mode 100644 index 0000000..f774784 --- /dev/null +++ b/FOSS/Python/Dependencies/future-0.18.2/docs/int_object.rst @@ -0,0 +1,68 @@ +.. _int-object: + +int +--- + +Python 3's ``int`` type is very similar to Python 2's ``long``, except +for the representation (which omits the ``L`` suffix in Python 2). Python +2's usual (short) integers have been removed from Python 3, as has the +``long`` builtin name. + +Python 3:: + + >>> 2**64 + 18446744073709551616 + +Python 2:: + + >>> 2**64 + 18446744073709551616L + +``future`` includes a backport of Python 3's ``int`` that +is a subclass of Python 2's ``long`` with the same representation +behaviour as Python 3's ``int``. To ensure an integer is long compatibly with +both Py3 and Py2, cast it like this:: + + >>> from builtins import int + >>> must_be_a_long_integer = int(1234) + +The backported ``int`` object helps with writing doctests and simplifies code +that deals with ``long`` and ``int`` as special cases on Py2. An example is the +following code from ``xlwt-future`` (called by the ``xlwt.antlr.BitSet`` class) +for writing out Excel ``.xls`` spreadsheets. With ``future``, the code is:: + + from builtins import int + + def longify(data): + """ + Turns data (an int or long, or a list of ints or longs) into a + list of longs. + """ + if not data: + return [int(0)] + if not isinstance(data, list): + return [int(data)] + return list(map(int, data)) + + +Without ``future`` (or with ``future`` < 0.7), this might be:: + + def longify(data): + """ + Turns data (an int or long, or a list of ints or longs) into a + list of longs. + """ + if not data: + if PY3: + return [0] + else: + return [long(0)] + if not isinstance(data,list): + if PY3: + return [int(data)] + else: + return [long(data)] + if PY3: + return list(map(int, data)) # same as returning data, but with up-front typechecking + else: + return list(map(long, data)) |
