Re: [Python-ideas] the error that raises an AttributeError should be passed to __getattr__

2017-06-19 Thread Jason Maldonis
First, I apologize for the poor post. Your corrections were exactly correct: This is only relevant in the context of properties/descriptors, and the property swallows the error message and it isn't printed to screen. I should not be typing without testing. > So... what precisely should be passed

Re: [Python-ideas] the error that raises an AttributeError should be passed to __getattr__

2017-06-19 Thread Chris Angelico
On Tue, Jun 20, 2017 at 12:26 PM, Steven D'Aprano wrote: > On Tue, Jun 20, 2017 at 11:31:34AM +1000, Chris Angelico wrote: > >> Why not just write cross-version-compatible code as >> >> def __getattr__(self, name, error=None): >> >> ? Is there something special about getattr?

Re: [Python-ideas] the error that raises an AttributeError should be passed to __getattr__

2017-06-19 Thread Ethan Furman
On 06/19/2017 07:26 PM, Steven D'Aprano wrote: Or maybe we decide that it's actually a feature, not a problem, for an AttributeError inside self.attr.__get__ to look like self.attr is missing. It's a feature. It's why Enum classes can have members named 'value' and 'name'. -- ~Ethan~

Re: [Python-ideas] the error that raises an AttributeError should be passed to __getattr__

2017-06-19 Thread Steven D'Aprano
On Tue, Jun 20, 2017 at 11:31:34AM +1000, Chris Angelico wrote: > Why not just write cross-version-compatible code as > > def __getattr__(self, name, error=None): > > ? Is there something special about getattr? You've still got to write it in the first place. That's a pain, especially since

Re: [Python-ideas] the error that raises an AttributeError should be passed to __getattr__

2017-06-19 Thread Ethan Furman
On 06/19/2017 06:31 PM, Chris Angelico wrote: On Tue, Jun 20, 2017 at 10:18 AM, Steven D'Aprano wrote: Having said that, there's another problem: adding this feature (whatever it actually is) to __getattr__ will break every existing class that uses __getattr__. The problem

Re: [Python-ideas] socket module: plain stuples vs named tuples

2017-06-19 Thread INADA Naoki
Namedtuple in Python make startup time slow. So I'm very conservative to convert tuple to namedtuple in Python. INADA Naoki On Tue, Jun 20, 2017 at 7:27 AM, Victor Stinner wrote: > Oh, about the cost of writing C code, we started to enhance

Re: [Python-ideas] the error that raises an AttributeError should be passed to __getattr__

2017-06-19 Thread Chris Angelico
On Tue, Jun 20, 2017 at 10:18 AM, Steven D'Aprano wrote: > Apparently you heavily use properties, and __getattr__, and find that > the two don't interact well together when the property getters and > setters themselves raise AttributeError. I think that's relevant >

Re: [Python-ideas] the error that raises an AttributeError should be passed to __getattr__

2017-06-19 Thread Steven D'Aprano
On Mon, Jun 19, 2017 at 04:06:56PM -0500, Jason Maldonis wrote: > Hi everyone, > > A while back I had a conversation with some folks over on python-list. I > was having issues implementing error handling of `AttributeError`s using > `__getattr__`. [...] > For example, we cannot tell the

Re: [Python-ideas] Run length encoding

2017-06-19 Thread Erik
On 19/06/17 02:47, David Mertz wrote: As an only semi-joke, I have created a module on GH that meets the needs of this discussion (using the spelling I think are most elegant): https://github.com/DavidMertz/RLE It's a shame you have to build that list when encoding. I tried to work out a

Re: [Python-ideas] socket module: plain stuples vs named tuples

2017-06-19 Thread Victor Stinner
Oh, about the cost of writing C code, we started to enhance the socket module in socket.py but keep the C code unchanged. I am thinking to the support of enums. Some C functions are wrapped in Python. Victor Le 19 juin 2017 11:59 PM, "Guido van Rossum" a écrit : > There are

Re: [Python-ideas] socket module: plain stuples vs named tuples

2017-06-19 Thread Guido van Rossum
There are examples in timemodule.c which went through a similar conversion from plain tuples to (sort-of) named tuples. I agree that upgrading the tuples returned by the socket module to named tuples would be nice, but it's a low priority project. Maybe someone interested can create a PR? (First

Re: [Python-ideas] socket module: plain stuples vs named tuples

2017-06-19 Thread Victor Stinner
Hi, 2017-06-13 22:13 GMT+02:00 Thomas Güttler : > AFAIK the socket module returns plain tuples in Python3: > > https://docs.python.org/3/library/socket.html > > Why not use named tuples? For technical reasons: the socket module is mostly implemented in the C

Re: [Python-ideas] socket module: plain stuples vs named tuples

2017-06-19 Thread George Fischhof
+1 ;-) for example to get IP address of all interfaces we have to use the third (indexed as 2) member of "something" it is much more beatiful to get ip_address: *import *socket *for *ip *in *socket.gethostbyname_ex(socket.gethostname())[2]: print(ip) BR, George 2017-06-13 22:13 GMT+02:00

[Python-ideas] the error that raises an AttributeError should be passed to __getattr__

2017-06-19 Thread Jason Maldonis
Hi everyone, A while back I had a conversation with some folks over on python-list. I was having issues implementing error handling of `AttributeError`s using `__getattr__`. My problem is that it is currently impossible for a `__getattr__` in Python to know which method raised the

Re: [Python-ideas] Restore the __members__ behavior to python3 for C extension writers

2017-06-19 Thread Nick Coghlan
On 19 June 2017 at 04:10, Barry Scott wrote: > The code does this: > > Py::Object getattro( const Py::String _ ) > { > std::string name( name_.as_std_string( "utf-8" ) ); > > if( name == "value" ) > { > return m_value; >

Re: [Python-ideas] ImportError raised for a circular import

2017-06-19 Thread Nick Coghlan
On 19 June 2017 at 04:47, Mahmoud Hashemi wrote: > Barry, that kind of circular import is actually fine in many (if not most) > cases. Modules are immediately created and importable, thenincrementally > populated. The problem arises when you try to do something with contents

Re: [Python-ideas] Restore the __members__ behavior to python3 for C extension writers

2017-06-19 Thread Thomas Jollans
On 2017-06-18 20:10, Barry Scott wrote: > What is the way to tell python about 'value' in the python3 world? Implement a __dir__ method. This should call the superclass' (e.g. object's) __dir__ and add whatever it is you want to add to the list. In general I'd recommend using properties for