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

Re: svn commit: r1819110 - /subversion/branches/swig-py3/subversion/bindings/swig/include/proxy.swg

From: Troy Curtis Jr <troycurtisjr_at_gmail.com>
Date: Wed, 27 Dec 2017 02:48:29 +0000

On Sat, Dec 23, 2017 at 2:57 PM Daniel Shahaf <d.s_at_daniel.shahaf.name>
wrote:

> Troy Curtis Jr wrote on Sat, 23 Dec 2017 15:27 +0000:
> > On Fri, Dec 22, 2017 at 11:11 PM Daniel Shahaf <d.s_at_daniel.shahaf.name>
> > wrote:
> >
> > > troycurtisjr_at_apache.org wrote on Sat, 23 Dec 2017 04:43 +0000:
> > > > Author: troycurtisjr
> > > > Date: Sat Dec 23 04:43:26 2017
> > > > New Revision: 1819110
> > > >
> > > > URL: http://svn.apache.org/viewvc?rev=1819110&view=rev
> > > > Log:
> > > > On branch swig-py3: Replace hasattr check for a method with
> try-except.
> > > >
> > > > * subversion/bindings/swig/include/proxy.swg
> > > > (_assert_valid_deep): Replace hasattr check for the 'assert_valid'
> > > method
> > > > with a try-except block as some class instances can have the
> method
> > > but return
> > > > False to hasattr().
> > >
> > > I'm not too familiar with this code; shouldn't we be fixing the
> original
> > > problem, of hasattr() wrongly returning False? I assume it predates
> the
> > > branch, though?
> > >
> > >
> > I won't lie, I didn't like this change much, since I didn't feel that I
> > understood exactly *why* it didn't work. I only found info stating that
> > hasattr effectively did a getattr, but translated the AttributeError
> into a
> > boolean. However, obviously *something* else is different. The
> attribute
> > is obviously able to be found in some scenarios, but returns false for
> > hasattr. So far my attempts to reproduce in a small test class haven't
> > been successful. Perhaps, I should continue to dig into this one to get
> to
> > the bottom of what the difference actually is.
>
> I assume it could affect users' code as well, so yes, it'll be nice to get
> to
> the bottom of it (and to confirm that it's not a regression). What
> classes can
> you reproduce the mismatch with?
>
> I don't see any difference between the CPython implementations of getattr
> and
> hasattr, but perhaps I'm overlooking something (or looking at the source
> of a
> different CPython version to yours).
>
>
In taking another look at why hasattr() seeming fails in certain cases on
SWIG generated new style classes under python2, I ran across this article,
https://hynek.me/articles/hasattr/, which confirms that python 2's
hasattr() can misbehave in the presence of properties (which the
non-classic SWIG classes use). So this appears to be a known discrepancy.
I did change the code to no hide any AttributeError's encountered in the
assert_valid() method call itself.

Troy
Received on 2017-12-27 03:48:44 CET

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

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.