simon-git: spigot (master): Simon Tatham
Commits to Tartarus hosted VCS
tartarus-commits at lists.tartarus.org
Sun Oct 8 13:38:42 BST 2017
TL;DR:
8bc99b4 Python demos: use fractions.gcd from the standard library.
a57ef94 Python 3 prep: use PyLong_FromLong consistently.
94efc8b Python 3 prep: use int() instead of long().
7d7b08a Python 3 prep: use PyUnicode_FromString.
38d3ad3 Python 3 prep: fill in spigot_SpigotType on setup.
c5347bf Python 3 prep: don't directly reference ob_type.
0888707 Python 3 prep: use iter(dict.items()).
1550c00 Python 3 prep: simplify the API of the C entry points.
af8e0c5 Python 3 prep: add six new compare methods to Spigot.
ce33bdf Python 3 prep: add (r)truediv methods to Spigot.
89742a3 Python 3 prep: add __bool__() method.
b7e02ed Python 3 port: new P3-style module setup.
0d1d8f2 Python 3 port: make test.py P3-friendly.
b093c28 Python 3 port: make mediant.py P3-friendly.
a6492c3 Python 3 port: make pythangle.py P3-friendly.
50e3a9f Python 3 port: make powbegin.py P3-friendly.
Repository: https://git.tartarus.org/simon/spigot.git
On the web: https://git.tartarus.org/?p=simon/spigot.git
Branch updated: master
Committer: Simon Tatham <anakin at pobox.com>
Date: 2017-10-08 13:38:42
commit 8bc99b4ac9d88d7724511212e2d403962a836c13
web diff https://git.tartarus.org/?p=simon/spigot.git;a=commitdiff;h=8bc99b4ac9d88d7724511212e2d403962a836c13;hp=8e7f4dbccef78ce1cf76a8803e05d93446f2ff29
Author: Simon Tatham <anakin at pobox.com>
Date: Sun Oct 8 12:59:50 2017 +0100
Python demos: use fractions.gcd from the standard library.
I've been writing my own for ages, and only just found out that the
'fractions' module provides one, presumably as a side effect of
needing it to convert rationals to lowest terms. So now I can remove
the two Python implementations in my demo programs.
(It's almost a little disappointing that fractions.gcd only works on
integers - it could perfectly well work on pairs of rationals,
delivering a rational answer! But I only need it for integers here.)
python/powbegin.py | 8 +-------
python/pythangle.py | 6 +-----
2 files changed, 2 insertions(+), 12 deletions(-)
commit a57ef94262d2beac5e969d420b620c3ae45d51b6
web diff https://git.tartarus.org/?p=simon/spigot.git;a=commitdiff;h=a57ef94262d2beac5e969d420b620c3ae45d51b6;hp=8bc99b4ac9d88d7724511212e2d403962a836c13
Author: Simon Tatham <anakin at pobox.com>
Date: Sun Oct 8 09:18:52 2017 +0100
Python 3 prep: use PyLong_FromLong consistently.
In Python 3, PyInt_FromLong has gone away.
python/pyspig.cpp | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
commit 94efc8b84a8a653ae8d079a027e04f1fc488cc74
web diff https://git.tartarus.org/?p=simon/spigot.git;a=commitdiff;h=94efc8b84a8a653ae8d079a027e04f1fc488cc74;hp=a57ef94262d2beac5e969d420b620c3ae45d51b6
Author: Simon Tatham <anakin at pobox.com>
Date: Sun Oct 8 11:40:28 2017 +0100
Python 3 prep: use int() instead of long().
It's fair enough that Python 3 has merged the two integer types, but
it's a little odd that my Python code has to be sure to call it 'int'
consistently, whereas the C API now forces me to call it 'long'
consistently!
python/spig/__init__.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
commit 7d7b08ae530d8bb1c7bbcc2d042ebdddecaf25cd
web diff https://git.tartarus.org/?p=simon/spigot.git;a=commitdiff;h=7d7b08ae530d8bb1c7bbcc2d042ebdddecaf25cd;hp=94efc8b84a8a653ae8d079a027e04f1fc488cc74
Author: Simon Tatham <anakin at pobox.com>
Date: Sun Oct 8 09:19:58 2017 +0100
Python 3 prep: use PyUnicode_FromString.
In Python 3, PyString_FromString has gone away. And with
the kind of simple strings this module deals with, I don't
see any reason not to simply rule that everything coming out
of the spigot C++ code is deemed to be in UTF-8.
python/pyspig.cpp | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
commit 38d3ad39ae26cad6481959850f52cd7e6be9a4f3
web diff https://git.tartarus.org/?p=simon/spigot.git;a=commitdiff;h=38d3ad39ae26cad6481959850f52cd7e6be9a4f3;hp=7d7b08ae530d8bb1c7bbcc2d042ebdddecaf25cd
Author: Simon Tatham <anakin at pobox.com>
Date: Sun Oct 8 09:21:24 2017 +0100
Python 3 prep: fill in spigot_SpigotType on setup.
This avoids me having to write a huge static structure
initialiser whose field order will annoyingly not match
between the versions of Python I want to use.
python/pyspig.cpp | 56 +++++++++++++++----------------------------------------
1 file changed, 15 insertions(+), 41 deletions(-)
commit c5347bf6068ca566af410e2c02cadc2517475e53
web diff https://git.tartarus.org/?p=simon/spigot.git;a=commitdiff;h=c5347bf6068ca566af410e2c02cadc2517475e53;hp=38d3ad39ae26cad6481959850f52cd7e6be9a4f3
Author: Simon Tatham <anakin at pobox.com>
Date: Sun Oct 8 09:21:46 2017 +0100
Python 3 prep: don't directly reference ob_type.
There's a wrapper macro, so using it is a good idea.
python/pyspig.cpp | 12 +++++-------
1 file changed, 5 insertions(+), 7 deletions(-)
commit 0888707b6570e8ed5ca02d5243b04f54467f3773
web diff https://git.tartarus.org/?p=simon/spigot.git;a=commitdiff;h=0888707b6570e8ed5ca02d5243b04f54467f3773;hp=c5347bf6068ca566af410e2c02cadc2517475e53
Author: Simon Tatham <anakin at pobox.com>
Date: Sun Oct 8 09:40:13 2017 +0100
Python 3 prep: use iter(dict.items()).
python/spig/__init__.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
commit 1550c006ea55c9509410d16a13824969d9f83a07
web diff https://git.tartarus.org/?p=simon/spigot.git;a=commitdiff;h=1550c006ea55c9509410d16a13824969d9f83a07;hp=0888707b6570e8ed5ca02d5243b04f54467f3773
Author: Simon Tatham <anakin at pobox.com>
Date: Sun Oct 8 11:30:52 2017 +0100
Python 3 prep: simplify the API of the C entry points.
There's really no need for the C methods 'base', 'ieee' and 'printf'
to have a nice Pythonic API with keyword-identified optional
parameters and sensible defaults. The only things that will call these
functions anyway are the wrapper methods written in Python itself, and
_those_ can present a nice Pythonic interface to the end user without
me having to do fiddly stuff with PyArg_ParseTupleAndKeywords,
METH_KEYWORDS and the like.
The old API didn't quite seem to work in my initial testing with
Python 3, and I think the easiest way to fix it is not to find out how
I can make my keyword-based API properly P2/P3 agnostic but to simply
stop trying to be unnecessarily clever in the first place.
python/pyspig.cpp | 35 +++++++++++------------------------
python/spig/__init__.py | 6 +++---
2 files changed, 14 insertions(+), 27 deletions(-)
commit af8e0c5088a85d4e277abe66179146c879e82717
web diff https://git.tartarus.org/?p=simon/spigot.git;a=commitdiff;h=af8e0c5088a85d4e277abe66179146c879e82717;hp=1550c006ea55c9509410d16a13824969d9f83a07
Author: Simon Tatham <anakin at pobox.com>
Date: Sun Oct 8 11:57:51 2017 +0100
Python 3 prep: add six new compare methods to Spigot.
Looks as if the __cmp__ I implemented for Python 2 is ignored, and for
P3 I need to support __lt__, __le__ etc, instead of just __cmp__. But
I might as well leave __cmp__ in; it's not doing any harm by
continuing to be there, and it's a convenient subroutine that I can
implement the six new methods in terms of.
python/spig/__init__.py | 13 +++++++++++++
1 file changed, 13 insertions(+)
commit ce33bdff99dce76b6674cb326848cbfb27b093b5
web diff https://git.tartarus.org/?p=simon/spigot.git;a=commitdiff;h=ce33bdff99dce76b6674cb326848cbfb27b093b5;hp=af8e0c5088a85d4e277abe66179146c879e82717
Author: Simon Tatham <anakin at pobox.com>
Date: Sun Oct 8 13:01:12 2017 +0100
Python 3 prep: add (r)truediv methods to Spigot.
The existing div and rdiv methods are P2-specific (though
I've left them in unconditionally, because why not).
python/spig/__init__.py | 6 ++++++
1 file changed, 6 insertions(+)
commit 89742a3a2c9fee1b2fb989280eacdbe624e82d3f
web diff https://git.tartarus.org/?p=simon/spigot.git;a=commitdiff;h=89742a3a2c9fee1b2fb989280eacdbe624e82d3f;hp=ce33bdff99dce76b6674cb326848cbfb27b093b5
Author: Simon Tatham <anakin at pobox.com>
Date: Sun Oct 8 13:21:08 2017 +0100
Python 3 prep: add __bool__() method.
This is the new thing that P3 calls to determine the truth value of an
object when you use it in a boolean context like an if statement.
python/spig/__init__.py | 3 +++
1 file changed, 3 insertions(+)
commit b7e02eda7c2b42ac6e6f730d43a17bd5b829ff6d
web diff https://git.tartarus.org/?p=simon/spigot.git;a=commitdiff;h=b7e02eda7c2b42ac6e6f730d43a17bd5b829ff6d;hp=89742a3a2c9fee1b2fb989280eacdbe624e82d3f
Author: Simon Tatham <anakin at pobox.com>
Date: Sun Oct 8 09:33:29 2017 +0100
Python 3 port: new P3-style module setup.
I've tried to avoid littering the _entire_ code base with ifdefs;
instead, I've extracted as much as possible of the different module
initialisation sequences into a shared module_setup() function that
works for both P2 and P3, and then I just have one ifdef that calls
that in the middle of otherwise completely different code.
python/pyspig.cpp | 56 +++++++++++++++++++++++++++++++++++++++++++++++--------
1 file changed, 48 insertions(+), 8 deletions(-)
commit 0d1d8f25e5bcb3e93a333d0d1acd6716f001b9d9
web diff https://git.tartarus.org/?p=simon/spigot.git;a=commitdiff;h=0d1d8f25e5bcb3e93a333d0d1acd6716f001b9d9;hp=b7e02eda7c2b42ac6e6f730d43a17bd5b829ff6d
Author: Simon Tatham <anakin at pobox.com>
Date: Sun Oct 8 11:42:55 2017 +0100
Python 3 port: make test.py P3-friendly.
All I had to do here was to stop using the P2-style print statement.
While I was at it, I reworked the print statements so they actually
say _what_ they're demoing, and shortened a couple of output lines so
they don't wrap over 80 columns.
python/test.py | 38 ++++++++++++++++++++++++--------------
1 file changed, 24 insertions(+), 14 deletions(-)
commit b093c287cb9fe846d01a79d1264ed0936ee38b95
web diff https://git.tartarus.org/?p=simon/spigot.git;a=commitdiff;h=b093c287cb9fe846d01a79d1264ed0936ee38b95;hp=0d1d8f25e5bcb3e93a333d0d1acd6716f001b9d9
Author: Simon Tatham <anakin at pobox.com>
Date: Sun Oct 8 11:58:58 2017 +0100
Python 3 port: make mediant.py P3-friendly.
python/mediant.py | 15 ++++++---------
1 file changed, 6 insertions(+), 9 deletions(-)
commit a6492c3e1bdffea6fe1513c203c9f5179f9f1cf5
web diff https://git.tartarus.org/?p=simon/spigot.git;a=commitdiff;h=a6492c3e1bdffea6fe1513c203c9f5179f9f1cf5;hp=b093c287cb9fe846d01a79d1264ed0936ee38b95
Author: Simon Tatham <anakin at pobox.com>
Date: Sun Oct 8 13:00:32 2017 +0100
Python 3 port: make pythangle.py P3-friendly.
Not much to do here: one 'print' at the end of the run needed
rewriting, and a casual use of the obsolete reduce() function which
wasn't hard to replace.
python/pythangle.py | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
commit 50e3a9ffd1ce7401d1810fad8c4b72b265b73dd3
web diff https://git.tartarus.org/?p=simon/spigot.git;a=commitdiff;h=50e3a9ffd1ce7401d1810fad8c4b72b265b73dd3;hp=a6492c3e1bdffea6fe1513c203c9f5179f9f1cf5
Author: Simon Tatham <anakin at pobox.com>
Date: Sun Oct 8 13:14:01 2017 +0100
Python 3 port: make powbegin.py P3-friendly.
This being the most complicated of the current demo program
collection, it made me aware of a couple of P2/P3 incompatibilities I
hadn't previously known about: you have to use // to get a rounding-
down integer division (which fortunately P2 also supports), and I had
been extracting items from a generator g using g.next() instead of
next(g). Also, I was checking if a number was of integer type by
saying 'if type(s) in [int,long]', which would have been cumbersome to
conditionalise on whether the 'long' type exists, so I replaced that
completely with an isinstance check against numbers.Integral.
Other than that, this was the usual straightforward print-removal and
long->int conversion.
python/powbegin.py | 41 ++++++++++++++++++++++-------------------
1 file changed, 22 insertions(+), 19 deletions(-)
More information about the tartarus-commits
mailing list