Re: [Python-Dev] Intricacies of calling __eq__

2014-03-19 Thread Mark Shannon
On 18/03/14 07:52, Maciej Fijalkowski wrote: Hi I have a question about calling __eq__ in some cases. We're thinking about doing an optimization where say: if x in d: return d[x] where d is a dict would result in only one dict lookup (the second one being constant folded away). The

Re: [Python-Dev] Intricacies of calling __eq__

2014-03-19 Thread Maciej Fijalkowski
On Tue, Mar 18, 2014 at 11:19 PM, Paul Moore p.f.mo...@gmail.com wrote: On 18 March 2014 19:46, Maciej Fijalkowski fij...@gmail.com wrote: A question: how far away will this optimization apply? if x in d: do_this() do_that() do_something_else() spam =

Re: [Python-Dev] Intricacies of calling __eq__

2014-03-19 Thread Antoine Pitrou
On Tue, 18 Mar 2014 09:52:05 +0200 Maciej Fijalkowski fij...@gmail.com wrote: We're thinking about doing an optimization where say: if x in d: return d[x] where d is a dict would result in only one dict lookup (the second one being constant folded away). The question is whether it's

Re: [Python-Dev] Intricacies of calling __eq__

2014-03-19 Thread Maciej Fijalkowski
On Wed, Mar 19, 2014 at 2:42 PM, Antoine Pitrou solip...@pitrou.net wrote: On Tue, 18 Mar 2014 09:52:05 +0200 Maciej Fijalkowski fij...@gmail.com wrote: We're thinking about doing an optimization where say: if x in d: return d[x] where d is a dict would result in only one dict lookup

Re: [Python-Dev] Intricacies of calling __eq__

2014-03-19 Thread Hrvoje Niksic
On 03/18/2014 10:19 PM, Paul Moore wrote: Surely in the presence of threads the optimisation is invalid anyway Why? As written, the code uses no synchronization primitives to ensure that the modifications to the dict are propagated at a particular point. As a consequence, it cannot rely on

Re: [Python-Dev] Intricacies of calling __eq__

2014-03-19 Thread Antoine Pitrou
On Wed, 19 Mar 2014 15:09:04 +0200 Maciej Fijalkowski fij...@gmail.com wrote: I would like to point out that instructing people does not really work. Besides, other examples like this: if d[x] = 3: d[x] += 1 don't really work. That's a good point. But then, perhaps PyPy should analyze

Re: [Python-Dev] Intricacies of calling __eq__

2014-03-19 Thread Maciej Fijalkowski
On Wed, Mar 19, 2014 at 3:17 PM, Antoine Pitrou solip...@pitrou.net wrote: On Wed, 19 Mar 2014 15:09:04 +0200 Maciej Fijalkowski fij...@gmail.com wrote: I would like to point out that instructing people does not really work. Besides, other examples like this: if d[x] = 3: d[x] += 1

Re: [Python-Dev] Intricacies of calling __eq__

2014-03-19 Thread Thomas Wouters
On Wed, Mar 19, 2014 at 6:26 AM, Antoine Pitrou solip...@pitrou.net wrote: On Wed, 19 Mar 2014 15:21:16 +0200 Maciej Fijalkowski fij...@gmail.com wrote: On Wed, Mar 19, 2014 at 3:17 PM, Antoine Pitrou solip...@pitrou.net wrote: On Wed, 19 Mar 2014 15:09:04 +0200 Maciej Fijalkowski

Re: [Python-Dev] Issues about relative absolute import way for Porting from python2.4 to python2.7

2014-03-19 Thread Brett Cannon
This mailing list is for the development *of* Python, the the *use* of Python. Your best option for getting an answer is to ask on python-list or python-help. On Tue, Mar 18, 2014 at 9:50 PM, 北冰洋 wtz...@foxmail.com wrote: Dear, I just wrote a sample like this: testPy/ __init__.py

Re: [Python-Dev] Intricacies of calling __eq__

2014-03-19 Thread Antoine Pitrou
On Wed, 19 Mar 2014 07:09:23 -0700 Thomas Wouters tho...@python.org wrote: He means you're being unrealistically pedantic :) The number of calls to __eq__ is _already_ unpredictable, since (as Mark Shannon said) it depends among other things on the hashing algorithm and the size of the dict.

Re: [Python-Dev] Intricacies of calling __eq__

2014-03-19 Thread Antony Lee
The docs don't seem to make any guarantee about calling __eq__ or __hash__: d[key] Return the item of d with key key. Raises a KeyError if key is not in the map. which seems to indicate that this kind of optimization should be fine. In fact I would very much like messing with the semantics of

Re: [Python-Dev] 'Add/Remove Programs' entry missing for 'current user only' 32-bit installations on 64-bit Windows

2014-03-19 Thread Martin v. Löwis
Am 17.03.14 22:10, schrieb Jurko Gospodnetić: Fixing this required manually cleaning up leftover CPython 3.4.0rc3 windows installer registry entries. Note that the issue could not be fixed by using the CPython 3.4.0rc3 installer as it failed due to the same problem. Did you try the 3.4.0rc3

Re: [Python-Dev] Intricacies of calling __eq__

2014-03-19 Thread Kevin Modzelewski
Sorry, I definitely didn't mean to imply that this kind of optimization is valid on arbitrary subscript expressions; I thought we had restricted ourselves to talking about builtin dicts. If we do, I think this becomes a discussion about what subset of the semantics of CPython's builtins are

Re: [Python-Dev] 'Add/Remove Programs' entry missing for 'current user only' 32-bit installations on 64-bit Windows

2014-03-19 Thread Jurko Gospodnetić
Hi. On 19.3.2014. 16:38, Martin v. Löwis wrote: Am 17.03.14 22:10, schrieb Jurko Gospodnetić: Fixing this required manually cleaning up leftover CPython 3.4.0rc3 windows installer registry entries. Note that the issue could not be fixed by using the CPython 3.4.0rc3 installer as it failed

Re: [Python-Dev] Intricacies of calling __eq__

2014-03-19 Thread Maciej Fijalkowski
On Wed, Mar 19, 2014 at 3:26 PM, Antoine Pitrou solip...@pitrou.net wrote: On Wed, 19 Mar 2014 15:21:16 +0200 Maciej Fijalkowski fij...@gmail.com wrote: On Wed, Mar 19, 2014 at 3:17 PM, Antoine Pitrou solip...@pitrou.net wrote: On Wed, 19 Mar 2014 15:09:04 +0200 Maciej Fijalkowski

Re: [Python-Dev] Intricacies of calling __eq__

2014-03-19 Thread Maciej Fijalkowski
On Wed, Mar 19, 2014 at 8:38 AM, Kevin Modzelewski k...@dropbox.com wrote: Sorry, I definitely didn't mean to imply that this kind of optimization is valid on arbitrary subscript expressions; I thought we had restricted ourselves to talking about builtin dicts. If we do, I think this becomes a

Re: [Python-Dev] Intricacies of calling __eq__

2014-03-19 Thread Stephen J. Turnbull
Kevin Modzelewski writes: Sorry, I definitely didn't mean to imply that this kind of optimization is valid on arbitrary subscript expressions; I thought we had restricted ourselves to talking about builtin dicts. Ah, maybe so -- Maciej made that clear later for PyPy. My bad. (With the

Re: [Python-Dev] 'Add/Remove Programs' entry missing for 'current user only' 32-bit installations on 64-bit Windows

2014-03-19 Thread Jurko Gospodnetić
Hi. Did you try the 3.4.0rc3 repair installation? That should have undeleted (repaired) the files that you had manually deleted. Just tested this out and repairing the same matching installation does revert the removed files. It does not reinstall pip and setuptools packages but that

Re: [Python-Dev] 'Add/Remove Programs' entry missing for 'current user only' 32-bit installations on 64-bit Windows

2014-03-19 Thread Jurko Gospodnetić
Hi. On 19.3.2014. 16:38, Martin v. Löwis wrote: Am 17.03.14 22:10, schrieb Jurko Gospodnetić: Fixing this required manually cleaning up leftover CPython 3.4.0rc3 windows installer registry entries. Note that the issue could not be fixed by using the CPython 3.4.0rc3 installer as it failed

[Python-Dev] asyncio.wait(FIRST_COMPLETED) returns more than one completions - 3.4rc2

2014-03-19 Thread Imran Geriskovan
Code below has been written with the intension of acquiring ONLY one lock. There are two issues: 1- Sometimes it returns more than one lock in done. 2- Sometimes, even if wait exits with zero or one locks, it seems there are other locks are acquired too. Though, I couldn't isolate the exact case

Re: [Python-Dev] asyncio.wait(FIRST_COMPLETED) returns more than one completions - 3.4rc2

2014-03-19 Thread Guido van Rossum
Hi Imran, The python-dev list is not the place to ask questions about the usage of Python modules or features. However, since you are asking an asyncio-related question, you should be welcome at the python-tulip list: https://groups.google.com/forum/?fromgroups#!forum/python-tulip --Guido On

Re: [Python-Dev] 'Add/Remove Programs' entry missing for 'current user only' 32-bit installations on 64-bit Windows

2014-03-19 Thread Jurko Gospodnetić
Hi. Should I open a 'Add/Remove Programs' dialog related issue in the CPython issue tracker? Please do. It would also good if somebody volunteered to reproduce the issue. Opened issue #20984. http://bugs.python.org/issue20984 Anyone have Windows 8 x64 available to try this out

[Python-Dev] Making proxy types easier to write and maintain

2014-03-19 Thread Antoine Pitrou
Hello, It is known to be cumbersome to write a proxy type that will correctly proxy all special methods (this has to be done manually on the type, since special methods are not looked up on the instance: a __getattr__ method would not work). Recently we've had reports of two stdlib types that

Re: [Python-Dev] unit tests for error messages

2014-03-19 Thread Antoine Pitrou
On Wed, 19 Mar 2014 10:53:31 -0700 Ethan Furman et...@stoneleaf.us wrote: I just made a change to some error messages [1] (really, just one): old behavior: '%o' % 3.14 'float' object cannot be interpreted as an integer new behavior: '%o' % 3.14 %o format: an integer is

[Python-Dev] unit tests for error messages

2014-03-19 Thread Ethan Furman
I just made a change to some error messages [1] (really, just one): old behavior: '%o' % 3.14 'float' object cannot be interpreted as an integer new behavior: '%o' % 3.14 %o format: an integer is required, not float Would we normally add a test for that? -- ~Ethan~ [1] Issue 19995:

Re: [Python-Dev] 'Add/Remove Programs' entry missing for 'current user only' 32-bit installations on 64-bit Windows

2014-03-19 Thread Andrew M. Hettinger
Sure, I'll check it this evening. Jurko Gospodnetić jurko.gospodne...@pke.hr wrote on 03/19/2014 01:41:19 PM: Hi. Should I open a 'Add/Remove Programs' dialog related issue in the CPython issue tracker? Please do. It would also good if somebody volunteered to reproduce the

Re: [Python-Dev] unit tests for error messages

2014-03-19 Thread Georg Brandl
Am 19.03.2014 19:55, schrieb Antoine Pitrou: On Wed, 19 Mar 2014 10:53:31 -0700 Ethan Furman et...@stoneleaf.us wrote: I just made a change to some error messages [1] (really, just one): old behavior: '%o' % 3.14 'float' object cannot be interpreted as an integer new behavior:

[Python-Dev] Making proxy types easier to write and maintain

2014-03-19 Thread Brett Cannon
On Wed Mar 19 2014 at 2:46:48 PM, Antoine Pitrou solip...@pitrou.net wrote: Hello, It is known to be cumbersome to write a proxy type that will correctly proxy all special methods (this has to be done manually on the type, since special methods are not looked up on the instance: a

Re: [Python-Dev] Making proxy types easier to write and maintain

2014-03-19 Thread Paul Moore
On 19 March 2014 18:46, Antoine Pitrou solip...@pitrou.net wrote: In http://bugs.python.org/issue19359#msg213530 I proposed to introduce a proxy protocol (__proxy__ / tp_proxy) that would be used as a fallback by _PyObject_LookupSpecial to fetch the lookup target, i.e.: def

Re: [Python-Dev] Making proxy types easier to write and maintain

2014-03-19 Thread Antoine Pitrou
On Wed, 19 Mar 2014 19:32:50 + Brett Cannon bcan...@gmail.com wrote: In http://bugs.python.org/issue19359#msg213530 I proposed to introduce a proxy protocol (__proxy__ / tp_proxy) that would be used as a fallback by _PyObject_LookupSpecial to fetch the lookup target, i.e.: def

Re: [Python-Dev] Making proxy types easier to write and maintain

2014-03-19 Thread Antoine Pitrou
On Wed, 19 Mar 2014 20:15:15 + Paul Moore p.f.mo...@gmail.com wrote: On 19 March 2014 18:46, Antoine Pitrou solip...@pitrou.net wrote: In http://bugs.python.org/issue19359#msg213530 I proposed to introduce a proxy protocol (__proxy__ / tp_proxy) that would be used as a fallback by

Re: [Python-Dev] Intricacies of calling __eq__

2014-03-19 Thread Nick Coghlan
On 20 Mar 2014 02:37, Stephen J. Turnbull step...@xemacs.org wrote: Kevin Modzelewski writes: Sorry, I definitely didn't mean to imply that this kind of optimization is valid on arbitrary subscript expressions; I thought we had restricted ourselves to talking about builtin dicts. Ah,

Re: [Python-Dev] Intricacies of calling __eq__

2014-03-19 Thread Nick Coghlan
On 20 Mar 2014 07:38, Nick Coghlan ncogh...@gmail.com wrote: Correct, but I think this discussion has established that how many times dict lookup calls __eq__ on the key is one such thing. In CPython, it already varies based on: - dict contents (due to the identity check and the distribution

Re: [Python-Dev] Making proxy types easier to write and maintain

2014-03-19 Thread Nick Coghlan
On 20 Mar 2014 06:24, Antoine Pitrou solip...@pitrou.net wrote: On Wed, 19 Mar 2014 19:32:50 + Brett Cannon bcan...@gmail.com wrote: In http://bugs.python.org/issue19359#msg213530 I proposed to introduce a proxy protocol (__proxy__ / tp_proxy) that would be used as a fallback by

Re: [Python-Dev] Making proxy types easier to write and maintain

2014-03-19 Thread Antoine Pitrou
On Thu, 20 Mar 2014 07:54:39 +1000 Nick Coghlan ncogh...@gmail.com wrote: Graeme Dumpleton has also subsequently written a library to handle easier creation of correct proxy types: https://pypi.python.org/pypi/wrapt (is Graeme another spelling for Graham?) It isn't as simple as changing one

[Python-Dev] unittest assertRaisesRegex bug?

2014-03-19 Thread Ethan Furman
Here's the code in question: class PsuedoFloat: def __init__(self, value): self.value = float(value) def __int__(self): return int(self.value) pi = PsuedoFloat(3.1415) self.assertRaisesRegex(TypeError, '%x format:

Re: [Python-Dev] unittest assertRaisesRegex bug?

2014-03-19 Thread Antoine Pitrou
On Wed, 19 Mar 2014 14:37:42 -0700 Ethan Furman et...@stoneleaf.us wrote: Here's the code in question: class PsuedoFloat: def __init__(self, value): self.value = float(value) def __int__(self): return int(self.value)

Re: [Python-Dev] unittest assertRaisesRegex bug?

2014-03-19 Thread Ethan Furman
On 03/19/2014 03:13 PM, Antoine Pitrou wrote: On Wed, 19 Mar 2014 14:37:42 -0700 Ethan Furman et...@stoneleaf.us wrote: Here's the code in question: class PsuedoFloat: def __init__(self, value): self.value = float(value) def

Re: [Python-Dev] unittest assertRaisesRegex bug?

2014-03-19 Thread Antoine Pitrou
On Wed, 19 Mar 2014 15:17:53 -0700 Ethan Furman et...@stoneleaf.us wrote: On 03/19/2014 03:13 PM, Antoine Pitrou wrote: On Wed, 19 Mar 2014 14:37:42 -0700 Ethan Furman et...@stoneleaf.us wrote: Here's the code in question: class PsuedoFloat: def __init__(self,

Re: [Python-Dev] unittest assertRaisesRegex bug?

2014-03-19 Thread Ethan Furman
On 03/19/2014 03:57 PM, Antoine Pitrou wrote: On Wed, 19 Mar 2014 15:17:53 -0700 Ethan Furman et...@stoneleaf.us wrote: On 03/19/2014 03:13 PM, Antoine Pitrou wrote: On Wed, 19 Mar 2014 14:37:42 -0700 Ethan Furman et...@stoneleaf.us wrote: Here's the code in question: class

Re: [Python-Dev] unittest assertRaisesRegex bug?

2014-03-19 Thread Thomas Wouters
On Wed, Mar 19, 2014 at 4:13 PM, Ethan Furman et...@stoneleaf.us wrote: On 03/19/2014 03:57 PM, Antoine Pitrou wrote: On Wed, 19 Mar 2014 15:17:53 -0700 Ethan Furman et...@stoneleaf.us wrote: On 03/19/2014 03:13 PM, Antoine Pitrou wrote: On Wed, 19 Mar 2014 14:37:42 -0700 Ethan Furman

Re: [Python-Dev] unit tests for error messages

2014-03-19 Thread R. David Murray
On Wed, 19 Mar 2014 20:32:38 +0100, Georg Brandl g.bra...@gmx.net wrote: Am 19.03.2014 19:55, schrieb Antoine Pitrou: On Wed, 19 Mar 2014 10:53:31 -0700 Ethan Furman et...@stoneleaf.us wrote: I just made a change to some error messages [1] (really, just one): old behavior:

Re: [Python-Dev] Making proxy types easier to write and maintain

2014-03-19 Thread Steven D'Aprano
On Wed, Mar 19, 2014 at 11:01:39PM +0100, Antoine Pitrou wrote: On Thu, 20 Mar 2014 07:54:39 +1000 Nick Coghlan ncogh...@gmail.com wrote: Graeme Dumpleton has also subsequently written a library to handle easier creation of correct proxy types: https://pypi.python.org/pypi/wrapt (is

Re: [Python-Dev] unittest assertRaisesRegex bug?

2014-03-19 Thread R. David Murray
On Wed, 19 Mar 2014 16:41:10 -0700, Thomas Wouters tho...@python.org wrote: On Wed, Mar 19, 2014 at 4:13 PM, Ethan Furman et...@stoneleaf.us wrote: On 03/19/2014 03:57 PM, Antoine Pitrou wrote: On Wed, 19 Mar 2014 15:17:53 -0700 Ethan Furman et...@stoneleaf.us wrote: On 03/19/2014

Re: [Python-Dev] unittest assertRaisesRegex bug?

2014-03-19 Thread Ethan Furman
On 03/19/2014 04:41 PM, Thomas Wouters wrote: What Antoine is trying to tell you is that the traceback you pasted shows this: File /home/ethan/source/python/__issue19995/Lib/test/test___unicode.py, line 1156, in test_formatting self.assertRaisesRegex(__TypeError, '%c'.__mod__, pi),

Re: [Python-Dev] Making proxy types easier to write and maintain

2014-03-19 Thread Nick Coghlan
On 20 Mar 2014 10:34, Steven D'Aprano st...@pearwood.info wrote: On Wed, Mar 19, 2014 at 11:01:39PM +0100, Antoine Pitrou wrote: On Thu, 20 Mar 2014 07:54:39 +1000 Nick Coghlan ncogh...@gmail.com wrote: Graeme Dumpleton has also subsequently written a library to handle easier