simon-git: spigot (master): Simon Tatham
Commits to Tartarus hosted VCS
tartarus-commits at lists.tartarus.org
Sun Oct 8 15:38:53 BST 2017
TL;DR:
a92d976 Python: set __qualname__ on spigot maths functions.
8726366 Python: fix input conversion of negative rationals.
efa9266 Python: use C99 hex float literals as a transport format.
62af17a Python: fix fallback between variable scopes.
6a4434c pythangle.py: a more subtle Python 3 incompatibility.
766dd49 Python demos: remove all uses of old % string formatting.
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 15:38:53
commit a92d976be8da1b3a095047dd6d7b05760ce6f9a5
web diff https://git.tartarus.org/?p=simon/spigot.git;a=commitdiff;h=a92d976be8da1b3a095047dd6d7b05760ce6f9a5;hp=50e3a9ffd1ce7401d1810fad8c4b72b265b73dd3
Author: Simon Tatham <anakin at pobox.com>
Date: Sun Oct 8 14:08:52 2017 +0100
Python: set __qualname__ on spigot maths functions.
In Python 2, setting __name__ arranged that functions like spigot_sin
would repr() as "<function sin at 0x7f74425ad140>" or similar, instead
of as some weird name related to the strange way I defined those
functions. But in Python 3, setting __name__ doesn't have that effect,
and I have to set __qualname__ instead.
Conveniently, it's harmless as far as I can see to do both in both
versions of Python.
python/spig/__init__.py | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
commit 87263664975c8bb2e3094d788b2a2fd6044290c7
web diff https://git.tartarus.org/?p=simon/spigot.git;a=commitdiff;h=87263664975c8bb2e3094d788b2a2fd6044290c7;hp=a92d976be8da1b3a095047dd6d7b05760ce6f9a5
Author: Simon Tatham <anakin at pobox.com>
Date: Sun Oct 8 14:33:17 2017 +0100
Python: fix input conversion of negative rationals.
Unlike C printf's %x formatting directive, Python's accepts a signed
integer, which means that formatting a number as "0x%x" won't always
give an answer you can sensibly parse, because if it's negative you
get something silly like "0x-ff".
While I'm here, I've switched the affected line (and a similar one
right next to it) over to using the new .format() system, since I'm
trying to get used to using it anyway.
python/spig/__init__.py | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
commit efa926621d1ca258df199e059dad68f6aff68317
web diff https://git.tartarus.org/?p=simon/spigot.git;a=commitdiff;h=efa926621d1ca258df199e059dad68f6aff68317;hp=87263664975c8bb2e3094d788b2a2fd6044290c7
Author: Simon Tatham <anakin at pobox.com>
Date: Sun Oct 8 14:33:23 2017 +0100
Python: use C99 hex float literals as a transport format.
I've just found out that Python floats have a hex() method which
generates the C99 hex syntax, and the float class itself has a
fromhex() method which parses it. spigot also speaks C99 hex float, so
this allows me to do away with the previous potentially platform-
specific bit-pattern punning via struct.pack.
Conversion from a spigot back to a float by this method admittedly
requires _two_ trips through spigot's core, so it's less efficient,
but spigot is not the fastest tool in the box anyway and I think I
like the decreased probability of per-platform bugs more than the
speed.
python/spig/__init__.py | 19 ++++++++-----------
1 file changed, 8 insertions(+), 11 deletions(-)
commit 62af17af9d0a086eae61ba5b96a672131e62e1b7
web diff https://git.tartarus.org/?p=simon/spigot.git;a=commitdiff;h=62af17af9d0a086eae61ba5b96a672131e62e1b7;hp=efa926621d1ca258df199e059dad68f6aff68317
Author: Simon Tatham <anakin at pobox.com>
Date: Sun Oct 8 14:52:13 2017 +0100
Python: fix fallback between variable scopes.
The Python wrapper class I was using to convert a user-provided list
of nested scopes into the single mapping-style scope object that the C
side was expecting had failed to spot a return value of None as
meaning 'not defined', so it was abandoning the lookup completely if a
function-shaped scope object returned None.
(I suppose it might actually be useful to deliberately have _some_
means for a higher-priority scope to completely undefine a name in a
lower-priority scope. But I had not intended this to be it.)
python/spig/__init__.py | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
commit 6a4434c38abbe7c2332cbceb7cbb0ee69b1398e2
web diff https://git.tartarus.org/?p=simon/spigot.git;a=commitdiff;h=6a4434c38abbe7c2332cbceb7cbb0ee69b1398e2;hp=62af17af9d0a086eae61ba5b96a672131e62e1b7
Author: Simon Tatham <anakin at pobox.com>
Date: Sun Oct 8 15:07:20 2017 +0100
pythangle.py: a more subtle Python 3 incompatibility.
I had still got some uses of / rather than //. In this case it hadn't
yet caused a problem because the divisions never yielded a fractional
value, because I'd constructed the divisor using gcd. But in Python 3,
/ on integers has the side effect of converting to floats, which would
have led to trouble once it generated a quotient too large to exactly
represent in a float.
python/pythangle.py | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
commit 766dd495b08ec5650365660e6ae30d34caeb449d
web diff https://git.tartarus.org/?p=simon/spigot.git;a=commitdiff;h=766dd495b08ec5650365660e6ae30d34caeb449d;hp=6a4434c38abbe7c2332cbceb7cbb0ee69b1398e2
Author: Simon Tatham <anakin at pobox.com>
Date: Sun Oct 8 15:09:13 2017 +0100
Python demos: remove all uses of old % string formatting.
Now I use string.format everywhere. This is mostly just for
consistency, but it did also provide a bit of extra error-checking -
that's how I spotted the large-integer bug in pythangle.py fixed by
the previous commit.
python/mediant.py | 12 ++++++------
python/powbegin.py | 12 ++++++------
python/pythangle.py | 2 +-
python/test.py | 4 ++--
4 files changed, 15 insertions(+), 15 deletions(-)
More information about the tartarus-commits
mailing list