simon-git: spigot (master): Simon Tatham

Commits to Tartarus hosted VCS tartarus-commits at lists.tartarus.org
Wed Nov 15 19:40:41 GMT 2017


TL;DR:
  baea20a Python: make Spigot.__repr__ introspect the class name.

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-11-15 19:40:41

commit baea20a6cf8bad89e8bd0e62f660724dea26b89b
web diff https://git.tartarus.org/?p=simon/spigot.git;a=commitdiff;h=baea20a6cf8bad89e8bd0e62f660724dea26b89b;hp=74b73896f57633715485847dfc7a52b888d8d88a
Author: Simon Tatham <anakin at pobox.com>
Date:   Wed Nov 15 19:40:15 2017 +0000

    Python: make Spigot.__repr__ introspect the class name.
    
    Now, if a user makes their own subclass of spigot.Spigot, then the
    inherited __repr__ function will automatically use the new class name,
    so that you'll be able to see from an object's repr() string whether
    it's an instance of base Spigot or your subclass:
    
    >>> from spigot import Spigot
    >>> class SubSpigot(Spigot):
    ...  pass
    ...
    >>> (Spigot(2), SubSpigot(2))
    (<Spigot:2>, <SubSpigot:2>)
    
    (This parallels the way that Spigot.fraction and Spigot.eval and so on
    are classmethods rather than staticmethods, so that SubSpigot.fraction
    will construct and return an instance of SubSpigot. I don't actually
    know of any use case for this kind of subclassing, but as long as I'm
    _trying_ to make it do something useful, I might as well try properly.)

 python-module/__init__.py | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)



More information about the tartarus-commits mailing list