simon-git: spigot (master): Simon Tatham

Commits to Tartarus hosted VCS tartarus-commits at lists.tartarus.org
Sun Oct 22 16:29:19 BST 2017


TL;DR:
  cf82507 Python: permit the Spigot constructor to take a string.

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-22 16:29:19

commit cf825076ac100fd6ab504170402c87c9129a7655
web diff https://git.tartarus.org/?p=simon/spigot.git;a=commitdiff;h=cf825076ac100fd6ab504170402c87c9129a7655;hp=7d1ccdedbed48eece83cac4f27fb317877b8aded
Author: Simon Tatham <anakin at pobox.com>
Date:   Sun Oct 22 15:12:08 2017 +0100

    Python: permit the Spigot constructor to take a string.
    
    I don't feel right about having it parse the full expression syntax by
    default; that feels more like the sort of thing for which you should
    call a specially named method (in our case, eval()) if you want it.
    But since ordinary Python types like int and float offer _some_ kind
    of basic literals-only conversion from strings, I feel that it's
    derelict of me not to do the same.
    
    So I've added a new much-simplified parsing function in expr.cpp, and
    plumbed it through to _to_spigot.
    
    Also, I've added a flag parameter to the internal function _to_spigot
    to enable the string conversion, because I want Spigot("1e2") to work,
    but I don't want arithmetic operations on a Spigot and a string - such
    as (Spigot(1)+"1e2") - to silently convert the string to a Spigot,
    because that would be quite startling and also have about a 1 in 2
    chance of not being what the user wanted, because they might just as
    plausibly have intended the + to be string concatenation and wanted
    the _other_ operand converted.

 expr.cpp                   | 47 ++++++++++++++++++++++++++++++++++++++++++++++
 expr.h                     |  1 +
 python-module/__init__.py  | 12 ++++++++++--
 python-module/internal.cpp | 24 +++++++++++++++++++++++
 python-module/testsuite    | 37 ++++++++++++++++++++++++++++++++++++
 5 files changed, 119 insertions(+), 2 deletions(-)



More information about the tartarus-commits mailing list