On 24/08/2010 08:40, Michael Foord wrote:
On 24/08/2010 01:25, Nick Coghlan wrote:
On Tue, Aug 24, 2010 at 8:15 AM, Nick Coghlanncogh...@gmail.com wrote:
Now, it may be worth considering an addition to the inspect module
that was basically:
def getattr_static(obj, attr):
Retrieve attributes
On 25 August 2010 20:57, P.J. Eby p...@telecommunity.com wrote:
[snip...]
As you can see, the __call__ attribute in each case is whatever the proxied
object's __call__ attribute is, even though the proxy itself has a __call__
method, that is invoked when the proxy is called.
This is
At 12:10 PM 8/25/2010 +1200, Greg Ewing wrote:
Consider an object that is trying to be a transparent
proxy for another object, and behave as much as possible
as though it really were the other object. Should an
attribute statically defined on the proxied object be
considered dynamically defined
On 25/08/2010 19:27, P.J. Eby wrote:
At 12:10 PM 8/25/2010 +1200, Greg Ewing wrote:
Consider an object that is trying to be a transparent
proxy for another object, and behave as much as possible
as though it really were the other object. Should an
attribute statically defined on the proxied
At 08:58 PM 8/25/2010 +0300, Michael Foord wrote:
If your proxy class defines __call__ then callable returns True,
even if the delegation to the proxied object would cause an
AttributeError to be raised.
Nope. You just have to use delegate via __getattribute__ (since 2.2)
instead of
On 24/08/2010 01:25, Nick Coghlan wrote:
On Tue, Aug 24, 2010 at 8:15 AM, Nick Coghlanncogh...@gmail.com wrote:
Now, it may be worth considering an addition to the inspect module
that was basically:
def getattr_static(obj, attr):
Retrieve attributes without triggering dynamic lookup via
On 08/23/2010 04:56 PM, Guido van Rossum wrote:
On Mon, Aug 23, 2010 at 7:46 AM, Benjamin Petersonbenja...@python.org wrote:
2010/8/23 Yury Selivanovyseliva...@gmail.com:
1) I propose to change 'hasattr' behaviour in Python 3, making it to swallow
only AttributeError exceptions (exactly
On Tue, 24 Aug 2010 11:09:10 am Guido van Rossum wrote:
On Mon, Aug 23, 2010 at 4:56 PM, Steven D'Aprano st...@pearwood.info
wrote:
[...]
I have always thought that hasattr() does what it says on the box:
it tests for the *existence* of an attribute, that is, one that
statically exists
2010/8/24 Hrvoje Niksic hrvoje.nik...@avl.com:
The __length_hint__ lookup expects either no exception or AttributeError,
and will propagate others. I'm not sure if this is a bug. On the one hand,
throwing anything except AttributeError from __getattr__ is bad style (which
is why we fixed the
2010/8/24 Hrvoje Niksic hrvoje.nik...@avl.com:
On 08/24/2010 02:31 PM, Benjamin Peterson wrote:
2010/8/24 Hrvoje Niksichrvoje.nik...@avl.com:
The __length_hint__ lookup expects either no exception or
AttributeError,
and will propagate others. I'm not sure if this is a bug. On the one
At 03:37 PM 8/24/2010 +0200, Hrvoje Niksic wrote:
a) a business case of throwing anything other than AttributeError
from __getattr__ and friends is almost certainly a bug waiting to happen, and
FYI, best practice for __getattr__ is generally to bail with an
AttributeError as soon as you see
2010/8/24 P.J. Eby p...@telecommunity.com:
At 03:37 PM 8/24/2010 +0200, Hrvoje Niksic wrote:
a) a business case of throwing anything other than AttributeError from
__getattr__ and friends is almost certainly a bug waiting to happen, and
FYI, best practice for __getattr__ is generally to bail
On 8/24/2010 9:45 AM, Benjamin Peterson wrote:
2010/8/24 Hrvoje Niksic hrvoje.nik...@avl.com:
On 08/24/2010 02:31 PM, Benjamin Peterson wrote:
2010/8/24 Hrvoje Niksichrvoje.nik...@avl.com:
The __length_hint__ lookup expects either no exception or
AttributeError,
and will propagate
On Tue, Aug 24, 2010 at 4:51 AM, Steven D'Aprano st...@pearwood.info wrote:
But that's the thing... as far as I am concerned, a dynamically defined
attribute *doesn't* exist. If it existed, __getattr__ would never be
called. A minor semantic difference, to be sure, but it's real to me.
Eh? If
On Tue, 24 Aug 2010 09:26:09 -0500, Benjamin Peterson benja...@python.org
wrote:
2010/8/24 P.J. Eby p...@telecommunity.com:
At 03:37 PM 8/24/2010 +0200, Hrvoje Niksic wrote:
a) a business case of throwing anything other than AttributeError from
__getattr__ and friends is almost certainly
2010/8/24 R. David Murray rdmur...@bitdance.com:
On Tue, 24 Aug 2010 09:26:09 -0500, Benjamin Peterson benja...@python.org
wrote:
2010/8/24 P.J. Eby p...@telecommunity.com:
At 03:37 PM 8/24/2010 +0200, Hrvoje Niksic wrote:
a) a business case of throwing anything other than AttributeError
On Aug 24, 2010, at 10:26 AM, Benjamin Peterson wrote:
2010/8/24 P.J. Eby p...@telecommunity.com:
At 03:37 PM 8/24/2010 +0200, Hrvoje Niksic wrote:
a) a business case of throwing anything other than
AttributeError from
__getattr__ and friends is almost certainly a bug waiting to
happen,
2010/8/24 James Y Knight f...@fuhm.net:
On Aug 24, 2010, at 10:26 AM, Benjamin Peterson wrote:
2010/8/24 P.J. Eby p...@telecommunity.com:
At 03:37 PM 8/24/2010 +0200, Hrvoje Niksic wrote:
a) a business case of throwing anything other than AttributeError from
__getattr__ and friends is
At 10:13 AM 8/24/2010 -0500, Benjamin Peterson wrote:
2010/8/24 James Y Knight f...@fuhm.net:
On Aug 24, 2010, at 10:26 AM, Benjamin Peterson wrote:
2010/8/24 P.J. Eby p...@telecommunity.com:
At 03:37 PM 8/24/2010 +0200, Hrvoje Niksic wrote:
a) a business case of throwing anything other
On Aug 24, 2010, at 8:31 AM, Benjamin Peterson wrote:
2010/8/24 Hrvoje Niksic hrvoje.nik...@avl.com:
The __length_hint__ lookup expects either no exception or AttributeError,
and will propagate others. I'm not sure if this is a bug. On the one hand,
throwing anything except AttributeError
Steven D'Aprano wrote:
But that's the thing... as far as I am concerned, a dynamically defined
attribute *doesn't* exist.
Maybe for your particular use case, but the concept of
whether an attribute is dynamically defined or not is
not well-defined in general.
Consider an object that is
Hello,
I know the issue has been discussed several times already, however I couldn't
find any reasonable explanation of its strange behaviour. The main problem
with 'hasattr' function is that is swallows all exceptions derived from
Exception class. It's a good thing that it doesn't do that
2010/8/23 Yury Selivanov yseliva...@gmail.com:
1) I propose to change 'hasattr' behaviour in Python 3, making it to swallow
only AttributeError exceptions (exactly like 'getattr'). Probably, Python
3.2 release is our last chance.
I would be in support of that.
2) If you afraid that this
On 2010-08-23, at 10:46 AM, Benjamin Peterson wrote:
2010/8/23 Yury Selivanov yseliva...@gmail.com:
1) I propose to change 'hasattr' behaviour in Python 3, making it to swallow
only AttributeError exceptions (exactly like 'getattr'). Probably, Python
3.2 release is our last chance.
I
On Mon, Aug 23, 2010 at 7:46 AM, Benjamin Peterson benja...@python.org wrote:
2010/8/23 Yury Selivanov yseliva...@gmail.com:
1) I propose to change 'hasattr' behaviour in Python 3, making it to swallow
only AttributeError exceptions (exactly like 'getattr'). Probably, Python
3.2 release is
2010/8/23 Guido van Rossum gu...@python.org:
On Mon, Aug 23, 2010 at 7:46 AM, Benjamin Peterson benja...@python.org
wrote:
2010/8/23 Yury Selivanov yseliva...@gmail.com:
1) I propose to change 'hasattr' behaviour in Python 3, making it to
swallow only AttributeError exceptions (exactly like
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1
Guido van Rossum wrote:
On Mon, Aug 23, 2010 at 7:46 AM, Benjamin Peterson benja...@python.org
wrote:
2010/8/23 Yury Selivanov yseliva...@gmail.com:
1) I propose to change 'hasattr' behaviour in Python 3, making it to
swallow only
On 8/23/2010 10:22 AM, Yury Selivanov wrote:
1) I propose to change 'hasattr' behaviour in Python 3, making it to
swallow only AttributeError exceptions (exactly like 'getattr').
Probably, Python 3.2 release is our last chance.
I gather that this amounts to changing an exception to
On Aug 23, 2010, at 7:22 AM, Yury Selivanov wrote:
I know the issue has been discussed several times already, however I couldn't
find any reasonable explanation of its strange behaviour. The main problem
with 'hasattr' function is that is swallows all exceptions derived from
Exception
On 23/08/2010 22:47, Raymond Hettinger wrote:
On Aug 23, 2010, at 7:22 AM, Yury Selivanov wrote:
I know the issue has been discussed several times already, however I couldn't
find any reasonable explanation of its strange behaviour. The main problem
with 'hasattr' function is that is
2010/8/23 Raymond Hettinger raymond.hettin...@gmail.com:
Thanks for the nice analysis and good example.
I disagree with the solution though. If we want to see the exceptions
associated
with actually getting an attribute, then using getattr() instead is a
perfectly
reasonable solution
On 2010-08-23, at 3:47 PM, Raymond Hettinger wrote:
On Aug 23, 2010, at 7:22 AM, Yury Selivanov wrote:
I know the issue has been discussed several times already, however I
couldn't find any reasonable explanation of its strange behaviour. The main
problem with 'hasattr' function is
On Mon, Aug 23, 2010 at 12:47 PM, Raymond Hettinger
raymond.hettin...@gmail.com wrote:
On Aug 23, 2010, at 7:22 AM, Yury Selivanov wrote:
I know the issue has been discussed several times already, however I
couldn't find any reasonable explanation of its strange behaviour. The main
On 23/08/2010 22:59, Benjamin Peterson wrote:
[snip...]
IMO, this is a much better solution, more in line with known use cases
for hasattr(). If the proposed change when through, it would fail to
address the common use case and cause people to start writing their
own versions of hasattr()
2010/8/23 Michael Foord fuzzy...@voidspace.org.uk:
To me hasattr *looks* like a passive introspection function, and the fact
that it can trigger arbitrary code execution is unfortunate - especially
because a full workaround is pretty arcane.
That's the danger of a dynamic language like Python.
2010/8/23 Guido van Rossum gu...@python.org:
The main problem I can see with letting exceptions other than
AttributeError bubble through (besides perverted dependencies on the
current semantics) is that there are some situations where it is
pretty arbitrary whether TypeError or AttributeError
On Aug 23, 2010, at 1:03 PM, Guido van Rossum wrote:
But hasattr() has a far different set of use cases, so we should explore
an alternate solution to the problem. The usual reason that people use
hasattr() instead of getattr() is that they want to check for the presence of
of a
2010/8/23 Raymond Hettinger raymond.hettin...@gmail.com:
I don't have a specific proposal in mind. My main questions are
* Is there anything that hasattr(obj, key) can or should do that
can't already be done with getattr(obj, key, None)?
If not, do we really need to change anything?
For
On Aug 23, 2010, at 1:13 PM, Benjamin Peterson wrote:
2010/8/23 Michael Foord fuzzy...@voidspace.org.uk:
To me hasattr *looks* like a passive introspection function, and the fact
that it can trigger arbitrary code execution is unfortunate - especially
because a full workaround is pretty
On Aug 23, 2010, at 1:45 PM, Benjamin Peterson wrote:
2010/8/23 Raymond Hettinger raymond.hettin...@gmail.com:
P.S. The current behavior seems to be deeply embedded:
Well, that's what happens when a behavior is added in 1990. :)
More generally: it is an API code smell whenever
On Mon, Aug 23, 2010 at 1:33 PM, Raymond Hettinger
raymond.hettin...@gmail.com wrote:
I don't have a specific proposal in mind.
That's why I called it scope creep. :-) Trust me, your proposal will not
lead to a quick and better replacement for hasattr(). (See several other
people's replies.)
On 2010-08-23, at 4:33 PM, Raymond Hettinger wrote:
On Aug 23, 2010, at 1:03 PM, Guido van Rossum wrote:
But hasattr() has a far different set of use cases, so we should explore
an alternate solution to the problem. The usual reason that people use
hasattr() instead of getattr() is that
On 23/08/2010 23:13, Benjamin Peterson wrote:
2010/8/23 Michael Foordfuzzy...@voidspace.org.uk:
To me hasattr *looks* like a passive introspection function, and the fact
that it can trigger arbitrary code execution is unfortunate - especially
because a full workaround is pretty arcane.
That's
2010/8/23 Raymond Hettinger raymond.hettin...@gmail.com:
On Aug 23, 2010, at 1:13 PM, Benjamin Peterson wrote:
2010/8/23 Michael Foord fuzzy...@voidspace.org.uk:
To me hasattr *looks* like a passive introspection function, and the fact
that it can trigger arbitrary code execution is
On Mon, Aug 23, 2010 at 1:50 PM, Raymond Hettinger
raymond.hettin...@gmail.com wrote:
On Aug 23, 2010, at 1:45 PM, Benjamin Peterson wrote:
2010/8/23 Raymond Hettinger raymond.hettin...@gmail.com:
P.S. The current behavior seems to be deeply embedded:
Well, that's what happens when a
2010/8/23 Guido van Rossum gu...@python.org:
Changing C APIs is even harder than changing Python API because you
can't add exceptions to something that wasn't returning exceptions
before. We did that for comparisons in the past and it was a pain (but
worth it). For these two little APIs I
On 23/08/2010 23:55, Benjamin Peterson wrote:
2010/8/23 Raymond Hettingerraymond.hettin...@gmail.com:
On Aug 23, 2010, at 1:13 PM, Benjamin Peterson wrote:
2010/8/23 Michael Foordfuzzy...@voidspace.org.uk:
To me hasattr *looks* like a passive introspection function, and the fact
that it can
2010/8/23 Michael Foord fuzzy...@voidspace.org.uk:
On 23/08/2010 23:55, Benjamin Peterson wrote:
2010/8/23 Raymond Hettingerraymond.hettin...@gmail.com:
On Aug 23, 2010, at 1:13 PM, Benjamin Peterson wrote:
2010/8/23 Michael Foordfuzzy...@voidspace.org.uk:
To me hasattr *looks* like a
On 24/08/2010 00:05, Benjamin Peterson wrote:
2010/8/23 Michael Foordfuzzy...@voidspace.org.uk:
On 23/08/2010 23:55, Benjamin Peterson wrote:
2010/8/23 Raymond Hettingerraymond.hettin...@gmail.com:
On Aug 23, 2010, at 1:13 PM, Benjamin Peterson wrote:
2010/8/23 Michael
2010/8/23 Michael Foord fuzzy...@voidspace.org.uk:
Properties are allowed to do whatever the heck they want. That doesn't mean
that you have to execute code to determine whether they exist or not.
I thought you were trying to determine whether the attribute exists
not the property.
If
On 2010-08-23, at 5:02 PM, Michael Foord wrote:
On 23/08/2010 23:55, Benjamin Peterson wrote:
2010/8/23 Raymond Hettingerraymond.hettin...@gmail.com:
On Aug 23, 2010, at 1:13 PM, Benjamin Peterson wrote:
2010/8/23 Michael Foordfuzzy...@voidspace.org.uk:
To me hasattr *looks* like a passive
On 2010-08-23, at 5:22 PM, Yury Selivanov wrote:
On 2010-08-23, at 5:02 PM, Michael Foord wrote:
On 23/08/2010 23:55, Benjamin Peterson wrote:
2010/8/23 Raymond Hettingerraymond.hettin...@gmail.com:
On Aug 23, 2010, at 1:13 PM, Benjamin Peterson wrote:
2010/8/23 Michael
Properties are allowed to do whatever the heck they want. That doesn't mean
that you have to execute code to determine whether they exist or not.
If you don't want to execute properties, do the lookup on the type,
not the instance (obviously, you know the dance you need to do, since
you've
On 24/08/2010 00:40, Nick Coghlan wrote:
Properties are allowed to do whatever the heck they want. That doesn't mean
that you have to execute code to determine whether they exist or not.
If you don't want to execute properties, do the lookup on the type,
not the instance (obviously, you know
2010/8/23 Michael Foord fuzzy...@voidspace.org.uk:
On 24/08/2010 00:40, Nick Coghlan wrote:
Properties are allowed to do whatever the heck they want. That doesn't
mean
that you have to execute code to determine whether they exist or not.
If you don't want to execute properties, do the
On Mon, Aug 23, 2010 at 2:22 PM, Yury Selivanov yseliva...@gmail.com wrote:
As I understand the only possible way to make 'hasattr' work as it name
indicates (i.e. just check if attribute exists, not run it), is to add
another magic method(s?) to the existing __getattr__ and __getattribute__
On 2010-08-23, at 6:00 PM, Guido van Rossum wrote:
On Mon, Aug 23, 2010 at 2:22 PM, Yury Selivanov yseliva...@gmail.com wrote:
As I understand the only possible way to make 'hasattr' work as it name
indicates (i.e. just check if attribute exists, not run it), is to add
another magic
On Tue, Aug 24, 2010 at 7:40 AM, Nick Coghlan ncogh...@gmail.com wrote:
Properties are allowed to do whatever the heck they want. That doesn't mean
that you have to execute code to determine whether they exist or not.
If you don't want to execute properties, do the lookup on the type,
not the
2010/8/23 Yury Selivanov yseliva...@gmail.com:
On 2010-08-23, at 6:00 PM, Guido van Rossum wrote:
On Mon, Aug 23, 2010 at 2:22 PM, Yury Selivanov yseliva...@gmail.com wrote:
BTW, is it possible to add new magic method __hasattr__? Maybe not
in Python 3.2, but in general.
-1 The whole point
On Tue, Aug 24, 2010 at 7:49 AM, Michael Foord
fuzzy...@voidspace.org.uk wrote:
Certainly that is true for len. getattr obviously involves invoking code if
you are fetching a property or descriptor. No idea how you conclude that
hasattr executing code adds flexibility to the language though.
On 2010-08-23, at 6:17 PM, Benjamin Peterson wrote:
2010/8/23 Yury Selivanov yseliva...@gmail.com:
On 2010-08-23, at 6:00 PM, Guido van Rossum wrote:
On Mon, Aug 23, 2010 at 2:22 PM, Yury Selivanov yseliva...@gmail.com
wrote:
BTW, is it possible to add new magic method __hasattr__? Maybe
2010/8/23 Yury Selivanov yseliva...@gmail.com:
On 2010-08-23, at 6:17 PM, Benjamin Peterson wrote:
2010/8/23 Yury Selivanov yseliva...@gmail.com:
On 2010-08-23, at 6:00 PM, Guido van Rossum wrote:
On Mon, Aug 23, 2010 at 2:22 PM, Yury Selivanov yseliva...@gmail.com
wrote:
BTW, is it
On Tue, Aug 24, 2010 at 8:15 AM, Nick Coghlan ncogh...@gmail.com wrote:
Now, it may be worth considering an addition to the inspect module
that was basically:
def getattr_static(obj, attr):
Retrieve attributes without triggering dynamic lookup via the
descriptor protocol,
At 12:02 AM 8/24/2010 +0300, Michael Foord wrote:
For properties there is *no reason* why code should be executed
merely in order to discover if the attribute exists or not.
That depends on what you mean by exists. Note that a property
might raise AttributeError to signal that the attribute
On Tue, Aug 24, 2010 at 8:25 AM, Benjamin Peterson benja...@python.org wrote:
2010/8/23 Yury Selivanov yseliva...@gmail.com:
So, the proposed magic method is not intended to change the protocol,
but to complement and enhance it.
But it still raises the potential to break the relationship
At 06:12 PM 8/23/2010 -0400, Yury Selivanov wrote:
BTW, is it possible to add new magic method __hasattr__? Maybe not
in Python 3.2, but in general.
In order to do this properly, you'd need to also add __has__ or
__exists__ (or some such) to the descriptor protocol; otherwise you
break
On Aug 23, 2010, at 03:45 PM, Benjamin Peterson wrote:
It's generally more convenient that getattr(obj, blah, None) is not
None.
Clearly, the solution is a new builtin called 'Missing'.
wink
-Barry
signature.asc
Description: PGP signature
___
On Mon, Aug 23, 2010 at 3:45 PM, P.J. Eby p...@telecommunity.com wrote:
At 06:12 PM 8/23/2010 -0400, Yury Selivanov wrote:
BTW, is it possible to add new magic method __hasattr__? Maybe not
in Python 3.2, but in general.
In order to do this properly, you'd need to also add __has__ or
On Tue, 24 Aug 2010 06:50:19 am Guido van Rossum wrote:
* Is there anything that hasattr(obj, key) can or should do that
can't already be done with getattr(obj, key, None)?
If not, do we really need to change anything?
getattr(obj, 'key', None) returns None when obj.key exists and has
2010/8/23 Steven D'Aprano st...@pearwood.info:
On Tue, 24 Aug 2010 06:50:19 am Guido van Rossum wrote:
* Is there anything that hasattr(obj, key) can or should do that
can't already be done with getattr(obj, key, None)?
If not, do we really need to change anything?
getattr(obj,
On Mon, Aug 23, 2010 at 17:04, Benjamin Peterson benja...@python.org wrote:
2010/8/23 Steven D'Aprano st...@pearwood.info:
On Tue, 24 Aug 2010 06:50:19 am Guido van Rossum wrote:
* Is there anything that hasattr(obj, key) can or should do that
can't already be done with getattr(obj, key,
On Mon, Aug 23, 2010 at 4:56 PM, Steven D'Aprano st...@pearwood.info wrote:
On Tue, 24 Aug 2010 06:50:19 am Guido van Rossum wrote:
* Is there anything that hasattr(obj, key) can or should do that
can't already be done with getattr(obj, key, None)?
If not, do we really need to change
On 2010-08-23, at 10:56 AM, Guido van Rossum wrote:
On Mon, Aug 23, 2010 at 7:46 AM, Benjamin Peterson benja...@python.org
wrote:
2010/8/23 Yury Selivanov yseliva...@gmail.com:
1) I propose to change 'hasattr' behaviour in Python 3, making it to
swallow only AttributeError exceptions
Yuri, I think you are making a good case (though I would like for you
to be a good citizen and use the bug tracker to submit this for
review). Benjamin, what do you think?
--Guido
On Mon, Aug 23, 2010 at 7:14 PM, Yury Selivanov yseliva...@gmail.com wrote:
On 2010-08-23, at 10:56 AM, Guido van
On 2010-08-23, at 10:37 PM, Guido van Rossum wrote:
Yuri, I think you are making a good case (though I would like for you
to be a good citizen and use the bug tracker to submit this for
review). Benjamin, what do you think?
NP, issue #9666 ;-)
-
Yury
2010/8/23 Guido van Rossum gu...@python.org:
Yuri, I think you are making a good case (though I would like for you
to be a good citizen and use the bug tracker to submit this for
review). Benjamin, what do you think?
I will have a look right now.
--
Regards,
Benjamin
76 matches
Mail list logo