[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: svn commit: r1818995 - in /subversion/branches/swig-py3: build/ac-macros/swig.m4 subversion/bindings/swig/include/proxy.py subversion/bindings/swig/include/proxy.swg

From: Branko Čibej <brane_at_apache.org>
Date: Tue, 2 Jan 2018 10:12:48 +0100

On 31.12.2017 03:05, Troy Curtis Jr wrote:
>
> This all makes sense and seems nice on the surface, but I'm not
> sure we
> can just change the behaviour of the bindings from old-style to
> new-style classes in a Python 2.x build. There are enough subtle
> differences in behaviour between the two that existing scripts could
> break after an upgrade of the bindings.
>
> Python 3.x has only new-style (or rather, even-newer-style)
> classes and
> there's no backward-compatibility consideration, since our bindings
> currently don't work with Python3.
>
>
> That is a reasonable concern.  I definitely preferred the cleaner
> single implementation, but honestly the code necessary to continue to
> use classic classes in python 2 is not large.  I've attached a working
> patch for reference/discussion.  It is a bit more code and some
> conditional definitions, but perhaps it is the more preferred course
> to take?
>
> [[[
> On branch swig-py3: Go back to using classic classes for Python 2 swig
> bindings.
>
> Add some additional clarifying comments for the reasons behind overriding
> __getattr__ and __getattribute__.
>
> * build/ac-macros/swig.m4
>   (SVN_FIND_SWIG): Add the '-classic' flag to swig when python 2 is
> detected.
>
> * subversion/bindings/swig/include/proxy.py
>    (_retrieve_swig_value): Factor out metadata retrieval from
> __getattribute__ to a new function.  
>    (__getattribute__): Only define __getattribute__ for new style classes.
>    (__getattr__): Add back implementation for classic classes.
> ]]]
>
> Troy

[...]

> +· # SWIG classes generated with -classic do not define this variable,
> +· # so set it to 0 when it doesn't exist
> +· try: _newclass
> +· except NameError: _newclass = 0

I prefer to break the try/except blocks onto separate lines, and to use
None for the tristate idiom value:

    try:
      _newclass
    except NameError:
      _newclass = None

-- Brane
Received on 2018-01-02 10:12:54 CET

This is an archived mail posted to the Subversion Dev mailing list.