Re: [Python-Dev] Python-versus-CPython question for __mul__ dispatch

2015-05-16 Thread Nick Coghlan
On 15 May 2015 at 10:45, Nathaniel Smith  wrote:
> Hi all,
>
> While attempting to clean up some of the more squamous aspects of
> numpy's operator dispatch code [1][2], I've encountered a situation
> where the semantics we want and are using are possible according to
> CPython-the-interpreter, but AFAICT ought not to be possible according
> to Python-the-language, i.e., it's not clear to me whether it's
> possible even in principle to implement an object that works the way
> numpy.ndarray does in any other interpreter. Which makes me a bit
> nervous, so I wanted to check if there was any ruling on this.

It's a known CPython operand precedence bug due to the fact several of
the builtin types only implement sq_concat & sq_repeat without
implementing nb_add & nb_mul: http://bugs.python.org/issue11477

There's then a related problem where we *don't* process
"NotImplemented" results from sq_concat and sq_repeat properly, so all
the builtin sequence types throw TypeError directly, instead of
returning NotImplemented when they don't recognise the other type.

I wrote a preliminary patch attempting to fix it a few years back
after the issue was discovered by Mike Bayer and Alex Gaynor when
porting SQL Alchemy to PyPy, but never committed it because my own
verdict on the approach I used was that it rendered the abstract
object API implementation for __mul__ and __add__ utterly
unmaintainable.

The better fix would be to make defining sq_concat and sq_repeat more
like defining __add__ and __mul__ at the Python level: PyType_Ready
should implicitly fill in nb_add and nb_mul references to standard
implementations that delegate to sq_concat and sq_repeat, and we
should update the implementations of the latter for the standard
library sequence types implemented in C to return NotImplemented
rather than throwing TypeError directly.

However, my intermittent attempts to get anyone else interested in
fixing it haven't borne any fruit, and I've prioritised other projects
over coming up with a different patch myself.

Cheers,
Nick.

-- 
Nick Coghlan   |   ncogh...@gmail.com   |   Brisbane, Australia
___
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Python-versus-CPython question for __mul__ dispatch

2015-05-16 Thread Nick Coghlan
On 15 May 2015 at 16:53, Nathaniel Smith  wrote:
> On Thu, May 14, 2015 at 9:29 PM, Guido van Rossum  wrote:
>> I expect you can make something that behaves like list by defining __mul__
>> and __rmul__ and returning NotImplemented.
>
> Hmm, it's fairly tricky, and part of the trick is that you can never
> return NotImplemented (because you have to pretty much take over and
> entirely replace the normal dispatch rules inside __mul__ and
> __rmul__), but see attached for something I think should work.
>
> So I guess this is just how Python's list, tuple, etc. work, and PyPy
> and friends need to match...

No, CPython is broken.

Cheers,
Nick.

-- 
Nick Coghlan   |   ncogh...@gmail.com   |   Brisbane, Australia
___
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Python-versus-CPython question for __mul__ dispatch

2015-05-16 Thread Nick Coghlan
On 16 May 2015 at 07:35, Nathaniel Smith  wrote:
> On Thu, May 14, 2015 at 11:53 PM, Nathaniel Smith  wrote:
>> On Thu, May 14, 2015 at 9:29 PM, Guido van Rossum  wrote:
>>> I expect you can make something that behaves like list by defining __mul__
>>> and __rmul__ and returning NotImplemented.
>>
>> Hmm, it's fairly tricky, and part of the trick is that you can never
>> return NotImplemented (because you have to pretty much take over and
>> entirely replace the normal dispatch rules inside __mul__ and
>> __rmul__), but see attached for something I think should work.
>>
>> So I guess this is just how Python's list, tuple, etc. work, and PyPy
>> and friends need to match...
>
> For the record, it looks like PyPy does already have a hack to
> implement this -- they do it by having a hidden flag on the built-in
> sequence types which the implementations of '*' and '+' check for, and
> if it's found it triggers a different rule for dispatching to the
> __op__ methods:
> 
> https://bitbucket.org/pypy/pypy/src/a1a494787f4112e42f50c6583e0fea18db3fb4fa/pypy/objspace/descroperation.py?at=default#cl-692

Oh, that's rather annoying that the PyPy team implemented bug-for-bug
compatibility there, and didn't follow up on the operand precedence
bug report to say that they had done so. We also hadn't previously
been made aware that NumPy is relying on this operand precedence bug
to implement publicly documented API behaviour, so fixing it *would*
break end user code :(

I guess that means someone in the numeric community will need to write
a PEP to make this "try the other operand first" "feature" part of the
language specification, so that other interpreters can implement it up
front, rather than all having to come up with their own independent
custom hacks just to make NumPy work.

Regards,
Nick.

P.S. It would also be nice if someone could take on the PEP for a
Python level buffer API for 3.6: http://bugs.python.org/issue13797

-- 
Nick Coghlan   |   ncogh...@gmail.com   |   Brisbane, Australia
___
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] No tags in semi-official github mirror of cpython repository.

2015-05-16 Thread Oleg Broytman
Hi!

On Sat, May 16, 2015 at 11:45:38AM +0900, INADA Naoki  
wrote:
> I foud "semi official github mirror" of cpython.
> https://github.com/python/cpython
> 
> I want to use it as upstream of our project (Translating docs in Japanese).
> But it doesn't have tags.
> 
> Is the repository stable enough for forking project like us? Or should we
> use mercurial?
> Could you mirror tags too?

   If you prefer to use git for development instead of mercurial, like I
do, you can try some hg-to-git gateways. I tried hg-fast-export and
git-remote-hg and found the latter to be much better.

   See https://github.com/felipec/git-remote-hg and
https://github.com/felipec/git/wiki/Comparison-of-git-remote-hg-alternatives

> Thanks
> -- 
> INADA Naoki  

Oleg.
-- 
 Oleg Broytmanhttp://phdru.name/p...@phdru.name
   Programmers don't die, they just GOSUB without RETURN.
___
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] cpython (merge 3.4 -> default): Added tests for more builtin types.

2015-05-16 Thread Ned Deily
In article <20150516183940.21146.77...@psf.io>,
 serhiy.storchaka  wrote:
> https://hg.python.org/cpython/rev/7b350f712c0e
> changeset:   96099:7b350f712c0e
> parent:  96096:f0c94892ac31
> parent:  96098:955dffec3d94
> user:Serhiy Storchaka 
> date:Sat May 16 21:35:56 2015 +0300
> summary:
>   Added tests for more builtin types.
> Made test_pprint discoverable.
> 
> files:
>   Lib/test/test_pprint.py |  17 -
>   1 files changed, 8 insertions(+), 9 deletions(-)

==
ERROR: test_coverage (test.test_trace.TestCoverage)
--
Traceback (most recent call last):
  File "/py/dev/3x/root/uxd/lib/python3.5/test/test_trace.py", line 312, 
in test_coverage
self._coverage(tracer)
  File "/py/dev/3x/root/uxd/lib/python3.5/test/test_trace.py", line 305, 
in _coverage
tracer.run(cmd)
  File "/py/dev/3x/root/uxd/lib/python3.5/trace.py", line 500, in run
self.runctx(cmd, dict, dict)
  File "/py/dev/3x/root/uxd/lib/python3.5/trace.py", line 508, in runctx
exec(cmd, globals, locals)
  File "", line 1, in 
AttributeError: module 'test.test_pprint' has no attribute 'test_main'

==
ERROR: test_coverage_ignore (test.test_trace.TestCoverage)
--
Traceback (most recent call last):
  File "/py/dev/3x/root/uxd/lib/python3.5/test/test_trace.py", line 327, 
in test_coverage_ignore
self._coverage(tracer)
  File "/py/dev/3x/root/uxd/lib/python3.5/test/test_trace.py", line 305, 
in _coverage
tracer.run(cmd)
  File "/py/dev/3x/root/uxd/lib/python3.5/trace.py", line 500, in run
self.runctx(cmd, dict, dict)
  File "/py/dev/3x/root/uxd/lib/python3.5/trace.py", line 508, in runctx
exec(cmd, globals, locals)
  File "", line 1, in 
AttributeError: module 'test.test_pprint' has no attribute 'test_main'

Also breaks 3.4.

-- 
 Ned Deily,
 n...@acm.org

___
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] cpython (merge 3.4 -> default): Added tests for more builtin types.

2015-05-16 Thread Serhiy Storchaka

On 17.05.15 02:44, Ned Deily wrote:

In article <20150516183940.21146.77...@psf.io>,
  serhiy.storchaka  wrote:

https://hg.python.org/cpython/rev/7b350f712c0e
changeset:   96099:7b350f712c0e
parent:  96096:f0c94892ac31
parent:  96098:955dffec3d94
user:Serhiy Storchaka 
date:Sat May 16 21:35:56 2015 +0300
summary:
   Added tests for more builtin types.
Made test_pprint discoverable.

files:
   Lib/test/test_pprint.py |  17 -
   1 files changed, 8 insertions(+), 9 deletions(-)


==
ERROR: test_coverage (test.test_trace.TestCoverage)
--
Traceback (most recent call last):
   File "/py/dev/3x/root/uxd/lib/python3.5/test/test_trace.py", line 312,
in test_coverage
 self._coverage(tracer)
   File "/py/dev/3x/root/uxd/lib/python3.5/test/test_trace.py", line 305,
in _coverage
 tracer.run(cmd)
   File "/py/dev/3x/root/uxd/lib/python3.5/trace.py", line 500, in run
 self.runctx(cmd, dict, dict)
   File "/py/dev/3x/root/uxd/lib/python3.5/trace.py", line 508, in runctx
 exec(cmd, globals, locals)
   File "", line 1, in 
AttributeError: module 'test.test_pprint' has no attribute 'test_main'

==
ERROR: test_coverage_ignore (test.test_trace.TestCoverage)
--
Traceback (most recent call last):
   File "/py/dev/3x/root/uxd/lib/python3.5/test/test_trace.py", line 327,
in test_coverage_ignore
 self._coverage(tracer)
   File "/py/dev/3x/root/uxd/lib/python3.5/test/test_trace.py", line 305,
in _coverage
 tracer.run(cmd)
   File "/py/dev/3x/root/uxd/lib/python3.5/trace.py", line 500, in run
 self.runctx(cmd, dict, dict)
   File "/py/dev/3x/root/uxd/lib/python3.5/trace.py", line 508, in runctx
 exec(cmd, globals, locals)
   File "", line 1, in 
AttributeError: module 'test.test_pprint' has no attribute 'test_main'

Also breaks 3.4.



Thank you Ned. Opened issue24215 for this because just restoring 
test_main perhaps not the best way.


___
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com