[issue16694] Add pure Python operator module

2013-05-10 Thread Roundup Robot

Roundup Robot added the comment:

New changeset 4b3238923b01 by Raymond Hettinger in branch 'default':
Issue #16694:  Add source code link for operator.py
http://hg.python.org/cpython/rev/4b3238923b01

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16694
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16694] Add pure Python operator module

2013-04-20 Thread Roundup Robot

Roundup Robot added the comment:

New changeset 97834382c6cc by Antoine Pitrou in branch 'default':
Issue #16694: Add a pure Python implementation of the operator module.
http://hg.python.org/cpython/rev/97834382c6cc

--
nosy: +python-dev

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16694
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16694] Add pure Python operator module

2013-04-20 Thread Antoine Pitrou

Antoine Pitrou added the comment:

I've now commited the latest patch. Thank you very much, Zachary!

--
resolution:  - fixed
stage: commit review - committed/rejected
status: open - closed

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16694
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16694] Add pure Python operator module

2013-04-17 Thread Antoine Pitrou

Antoine Pitrou added the comment:

length_hint() looks ok as well.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16694
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16694] Add pure Python operator module

2013-04-16 Thread Raymond Hettinger

Raymond Hettinger added the comment:

I reviewed the attrgetter(), mathodgetter(), and itemgetter() code in 
py_operator.v12.diff.  The looks clean and correct.

--
assignee: rhettinger - 

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16694
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16694] Add pure Python operator module

2013-04-16 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Now we can remove all __func__s from _operator.c.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16694
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16694] Add pure Python operator module

2013-04-16 Thread Zachary Ware

Zachary Ware added the comment:

Thank you for the review, Raymond.

Since Serhiy agrees that the _operator __func__s are unnecessary, here's a v13 
that removes them.  Again, I'm not a native C speaker, so these new changes in 
_operator.c deserve a bit of extra scrutiny.  Everything builds and still 
passes the test suite, though.

Also changed in this patch, test_pow and test_inplace remove explicit testing 
of __func__s.  Those tests are useless, as they are merely rerunning already 
run tests on the same function with a different name, which is confirmed by 
test_dunder_is_original.  I can extend that test with an explicit list of funcs 
which should have a __func__ if anyone thinks it's worth it.

--
Added file: http://bugs.python.org/file29887/py_operator.v13.diff

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16694
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16694] Add pure Python operator module

2013-04-15 Thread Zachary Ware

Zachary Ware added the comment:

Here's another new version of the patch, addressing Ezio's review comments and 
a few things I found after giving operator.py a closer look myself.

Things changed in operator.py in this version:

- all ``__func__ = func`` assignments are moved to the end, after importing * 
from _operator.  With the assignments after each func, __func__ was still the 
Python version after importing from _operator.  I suspect this means that 
_operator.c could be changed to not mess with creating each __func__ and just 
let operator.py do it, but not being a native C speaker, I don't know how to do 
it.  Also, there is an added test case to test whether __func__ is func.  It 
passes with the rest of the patch, but would fail on current operator.c; it 
seems that operator.c actually creates separate __func__ and func functions 
(that do the same thing).

- If importing from _operator succeeds, import __doc__ from _operator as well.  
The Python implementation has an extra note at the end of __doc__ advertising 
that it is a Python implementation.


Also, after submitting this patch, I'm going to try to clean up the files list 
on this issue a bit.  I'll clear the nosy list while I do so to avoid spamming 
everybody with messages about it.  (At least, I assume I can do so, I haven't 
tried this before :).  If I can't clear the nosy list, I won't bother with 
cleaning up the files, again to avoid spamming)

--
Added file: http://bugs.python.org/file29869/py_operator.v12.diff

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16694
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16694] Add pure Python operator module

2013-04-15 Thread Zachary Ware

Changes by Zachary Ware zachary.w...@gmail.com:


--
nosy:  -Arfrever, brett.cannon, eric.araujo, ezio.melotti, jcea, meador.inge, 
pitrou, serhiy.storchaka, zach.ware

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16694
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16694] Add pure Python operator module

2013-04-15 Thread Zachary Ware

Changes by Zachary Ware zachary.w...@gmail.com:


Removed file: http://bugs.python.org/file28327/operator.py

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16694
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16694] Add pure Python operator module

2013-04-15 Thread Zachary Ware

Changes by Zachary Ware zachary.w...@gmail.com:


Removed file: http://bugs.python.org/file28328/py_operator.diff

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16694
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16694] Add pure Python operator module

2013-04-15 Thread Zachary Ware

Changes by Zachary Ware zachary.w...@gmail.com:


Removed file: http://bugs.python.org/file28374/py_operator.v3.diff

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16694
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16694] Add pure Python operator module

2013-04-15 Thread Zachary Ware

Changes by Zachary Ware zachary.w...@gmail.com:


Removed file: http://bugs.python.org/file28388/py_operator.v5.diff

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16694
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16694] Add pure Python operator module

2013-04-15 Thread Zachary Ware

Changes by Zachary Ware zachary.w...@gmail.com:


Removed file: http://bugs.python.org/file28383/py_operator.v4.diff

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16694
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16694] Add pure Python operator module

2013-04-15 Thread Zachary Ware

Changes by Zachary Ware zachary.w...@gmail.com:


Removed file: http://bugs.python.org/file28522/py_operator.v7.diff

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16694
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16694] Add pure Python operator module

2013-04-15 Thread Zachary Ware

Changes by Zachary Ware zachary.w...@gmail.com:


Removed file: http://bugs.python.org/file28524/py_operator.v8.diff

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16694
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16694] Add pure Python operator module

2013-04-15 Thread Zachary Ware

Changes by Zachary Ware zachary.w...@gmail.com:


Removed file: http://bugs.python.org/file28532/py_operator.v9.diff

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16694
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16694] Add pure Python operator module

2013-04-15 Thread Zachary Ware

Changes by Zachary Ware zachary.w...@gmail.com:


--
nosy: +Arfrever, brett.cannon, eric.araujo, ezio.melotti, jcea, meador.inge, 
pitrou, serhiy.storchaka, zach.ware

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16694
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16694] Add pure Python operator module

2013-04-15 Thread Zachary Ware

Zachary Ware added the comment:

A change that I mentioned in a Rietveld comment on v10, but not in my last 
message: __all__ in operator.py no longer includes all of the __func__s, as 
currently doing from operator import * does not import all of the __func__s.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16694
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16694] Add pure Python operator module

2013-04-15 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

I think Antoine is more appropriate for committing this patch. I waited so long 
with this because I do not dare to take responsibility for themselves (it's 
almost like adding a new module).

--
assignee: serhiy.storchaka - 

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16694
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16694] Add pure Python operator module

2013-04-15 Thread Raymond Hettinger

Raymond Hettinger added the comment:

I would like to spend some time with this before it goes forward (especially 
the attrgetter, itemgetter, methodgetter group).

Right now, it looks like a nice effort but I don't see how it makes Python any 
better for adding it.  The odds are that this code will add bloat but not 
benefit any user (it won't get called at all).

--
assignee:  - rhettinger
nosy: +rhettinger

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16694
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16694] Add pure Python operator module

2013-04-15 Thread R. David Murray

R. David Murray added the comment:

Raymond: it's not for the benefit of CPython.

--
nosy: +r.david.murray

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16694
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16694] Add pure Python operator module

2013-04-15 Thread Raymond Hettinger

Raymond Hettinger added the comment:

[David]
 Raymond: it's not for the benefit of CPython.

IIRC, all the other implementations of Python already have this code passing 
tests, so it isn't really for their benefit either.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16694
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16694] Add pure Python operator module

2013-04-15 Thread Alex Gaynor

Alex Gaynor added the comment:

If a pure python operator module were a part of the stdlib, we (PyPy) would 
probably delete most (if not all) of our own operator module.

--
nosy: +alex

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16694
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16694] Add pure Python operator module

2013-04-14 Thread Antoine Pitrou

Antoine Pitrou added the comment:

Thank you!
One optional thing, the code churn could be minimized in test_operator.py by 
writing operator = self.module at the beginning of each test method.
Otherwise, looks good to me.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16694
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16694] Add pure Python operator module

2013-04-13 Thread Antoine Pitrou

Antoine Pitrou added the comment:

Zachary, I suppose Modules/_operator.c is a rename of Modules/operator.c.
Could you generate your patch using hg diff --git so that history isn't lost 
here?

See also http://docs.python.org/devguide/committing.html#minimal-configuration

--
nosy: +pitrou

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16694
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16694] Add pure Python operator module

2013-04-13 Thread Zachary Ware

Zachary Ware added the comment:

 Zachary, I suppose Modules/_operator.c is a rename of Modules/operator.c.
 Could you generate your patch using hg diff --git so that history isn't 
 lost here?

Of course; I thought I already had, but apparently I messed that up a bit. v11 
is in the proper format.  In it, you can actually see what was changed in 
Modules/operator.c, which is the necessary s/operator/_operator/ changes, and a 
few extra commas removed from a couple of docstrings (to match the docstrings 
in the new Python versions).

 See also http://docs.python.org/devguide/committing.html#minimal-configuration

Thank you for that link! I had read through this some time ago, but either 
missed the part about the diff section, or it just didn't sink in or something. 
 That is now added to my hg config file :)

--
Added file: http://bugs.python.org/file29844/py_operator.v11.diff

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16694
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16694] Add pure Python operator module

2013-01-29 Thread Zachary Ware

Zachary Ware added the comment:

Since the older Windows project files were removed, v10 removes the patches to 
them.

Everything else still applies cleanly.

Also, in the spirit of what Brett said in 16651 about not re-implementing 
blindly, I did just look up what Jython, IronPython, and PyPy do for the 
operator module.  The first two implement it in their VM language, and PyPy 
uses a very specialized version that didn't look easy to adapt to CPython, at 
least at a glance.  It was fun for me to write any way about it, though :)

--
Added file: http://bugs.python.org/file28904/py_operator.v10.diff

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16694
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16694] Add pure Python operator module

2013-01-02 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

v8 LGTM (except some trailing whitespaces).

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16694
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16694] Add pure Python operator module

2013-01-02 Thread Zachary Ware

Zachary Ware added the comment:

Note to self: learn to run patchcheck.py before posting.  Whitespace issues 
fixed in v9.

--
Added file: http://bugs.python.org/file28532/py_operator.v9.diff

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16694
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16694] Add pure Python operator module

2013-01-02 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

If no one objects I will commit this next week.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16694
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16694] Add pure Python operator module

2013-01-01 Thread Zachary Ware

Zachary Ware added the comment:

Sorry, I misunderstood Éric's suggestions regarding the tests; v6 is useless.  
v7 forthcoming.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16694
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16694] Add pure Python operator module

2013-01-01 Thread Zachary Ware

Changes by Zachary Ware zachary.w...@gmail.com:


Removed file: http://bugs.python.org/file28391/py_operator.v6.diff

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16694
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16694] Add pure Python operator module

2013-01-01 Thread Zachary Ware

Zachary Ware added the comment:

Ok, I believe the attached v7 properly addresses Éric's concerns about test 
discovery, and has no other changes unrelated to that compared to v5.

Thank you very much to Ezio for directing me towards the json tests for an 
example to work from.

--
nosy: +ezio.melotti
Added file: http://bugs.python.org/file28522/py_operator.v7.diff

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16694
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16694] Add pure Python operator module

2013-01-01 Thread Zachary Ware

Changes by Zachary Ware zachary.w...@gmail.com:


Added file: http://bugs.python.org/file28524/py_operator.v8.diff

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16694
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16694] Add pure Python operator module

2012-12-29 Thread Serhiy Storchaka

Changes by Serhiy Storchaka storch...@gmail.com:


--
assignee:  - serhiy.storchaka

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16694
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16694] Add pure Python operator module

2012-12-28 Thread Meador Inge

Changes by Meador Inge mead...@gmail.com:


--
nosy: +meador.inge

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16694
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16694] Add pure Python operator module

2012-12-22 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

I don't understand what is difference between v5 and v6.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16694
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16694] Add pure Python operator module

2012-12-21 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

About length_hint():

I were mean something like (even explicit getattr() not needed):

try:
hint = type(obj).__length_hint__
except AttributeError:
return default
try:
val = hint(obj)
except TypeError:
return default
...

This is a little faster because there is only one attribute lookup instead two. 
This is a little safer because there is a little less chance of race when an 
attribute changed between two lookups (it is enough non-probably and doesn't 
matter).

There is type(obj) here because the C code uses _PyObject_LookupSpecial() which 
doesn't honor instance attributes and looks only class attributes.


About concat() and iconcat():

I think only first argument can be checked. If arguments are not concatenable 
then '+'/'+=' operator will raise an exception. I'm not sure. Does anyone have 
any thoughts about this?


About methodcaller():

Here is a catch. With this implementation you can't use `methodcaller('foo', 
name='spam')` or `methodcaller('foo', self='spam')` (please add tests for those 
cases). Here is a trick needed:

def __init__(*args, **kwargs):
self = args[0]
self._name = args[1]
self._args = args[2:]
self._kwargs = kwargs

(You can add a code for better error reporting).


I have added smaller comments on Rietveld.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16694
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16694] Add pure Python operator module

2012-12-21 Thread Éric Araujo

Changes by Éric Araujo mer...@netwok.org:


--
nosy: +eric.araujo

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16694
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16694] Add pure Python operator module

2012-12-21 Thread Zachary Ware

Zachary Ware added the comment:

Here's another new version.  Changes include:

- Address Serhiy's Rietveld comments
- Fix length_hint() the way it was meant to be fixed last time.
- Remove __getitem__ check on 'b' in concat and iconcat.  More notes on this 
below.
- Fix methodcaller as Serhiy suggested
- Add test case for methodcaller for 'name' and 'self' keyword arguments
- Add comments to 'subdivide' the module into the rough sections the docs are 
divided into.  Move length_hint() with other sequence operations to also match 
the doc order.

On concat and iconcat: Looking at the glossary, a sequence should actually have 
both __getitem__ and __len__.  The test class in the test case for iconcat only 
defines __getitem__, though.  Should we check only for __getitem__ on the first 
argument, or check for both __getitem__ and __len__, and add __len__ to the 
test class?  Requiring __len__ may cause breakage for anyone using the Python 
implementation with a class they defined and used with the C implementation 
with only __getitem__, so I'm leaning towards only checking for __getitem__.  I 
can't really tell what the C implementation really looks for as I don't speak 
C, but it almost looks to me like it may be only checking for __getitem__.  
Latest patch only checks argument 'a' for __getitem__.

--
Added file: http://bugs.python.org/file28388/py_operator.v5.diff

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16694
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16694] Add pure Python operator module

2012-12-21 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Good work, Zachary. I have no more nitpicks for you. ;)

LGTM.

--
stage: patch review - commit review

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16694
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16694] Add pure Python operator module

2012-12-21 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

One comment to a committer. Don't forget to run `hg rename Modules/operator.c 
Modules/_operator.c` before applying the patch.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16694
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16694] Add pure Python operator module

2012-12-21 Thread Zachary Ware

Zachary Ware added the comment:

Nits are no fun; thank you for picking them, Serhiy ;)

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16694
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16694] Add pure Python operator module

2012-12-21 Thread Éric Araujo

Éric Araujo added the comment:

FYI Mercurial can use the extended diff format invented by git, which supports 
renames, changes to file permissions, etc.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16694
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16694] Add pure Python operator module

2012-12-21 Thread Éric Araujo

Éric Araujo added the comment:

The base test class should not inherit from TestCase: it will be picked up by 
test discovery and then will break, as self.module will be None.

Typical usage:

class OperatorTestsMixin:
module = None

class COperatorTests(OperatorTestsMixin, unittest.TestCase):
module = _operator

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16694
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16694] Add pure Python operator module

2012-12-21 Thread Zachary Ware

Zachary Ware added the comment:

Did not know that about test discovery, thank you Éric.  Fixed in v6.

A few other test modules may need the same fix; I based my changes to 
Lib/test/test_operator.py on Lib/test/test_heapq.py which has the same issue.  
I'll open a new report for it and any others I find.

Also, this patch was created with `hg diff -g`; the operator.c rename should be 
well taken care of by this patch.

--
Added file: http://bugs.python.org/file28391/py_operator.v6.diff

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16694
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16694] Add pure Python operator module

2012-12-20 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Sorry, I forgot push a Publish All My Drafts button. Please consider other my 
comments to first patch. I also have added new comments about length_hint().

Your implementation of attrgetter() looks good. One possible disadvantage of 
pure functional approach is that attrgetter() will be not a class. Unlikely 
someone subclass attrgetter, but it can be used in an isinstance() check. You 
solve this issue.

The same approach can be applied to itemgetter().

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16694
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16694] Add pure Python operator module

2012-12-20 Thread Zachary Ware

Zachary Ware added the comment:

Here's v4, addressing Serhiy's comments on Reitveld.

--
Added file: http://bugs.python.org/file28383/py_operator.v4.diff

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16694
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16694] Add pure Python operator module

2012-12-19 Thread Zachary Ware

Zachary Ware added the comment:

Sorry to have disappeared on this, other things took priority...

Thank you for the comments, Serhiy.  v2 of the patch renames Modules/operator.c 
to Modules/_operator.c, and changes that name every place I could find it.

I also tried to tidy up some of the error message mismatches.  I didn't bother 
with the ones regarding missing arguments, as that would mean checking args and 
throwing an exception in each and every function.

I do like the functional attrgetter better than the object version I wrote.  
The main reason I went with an object version in the first place was because 
that's what the C implementation used.  Is there any reason not to break with 
the C implementation and use a function instead?  The updated patch takes a 
rather ugly hack to try to use the functional version in an object.

length_hint() was horrible and has been rewritten.  It should be less horrible 
now :).  It should also follow the C implementation quite a bit better.

--
Added file: http://bugs.python.org/file28373/py_operator.v2.diff

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16694
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16694] Add pure Python operator module

2012-12-19 Thread Zachary Ware

Zachary Ware added the comment:

Considering what a huge headache it was to get my own patch to apply at home on 
Linux rather than at work on Windows, here's a new version of the patch that 
straightens out the line ending nightmare present in v2. No other changes made.

--
Added file: http://bugs.python.org/file28374/py_operator.v3.diff

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16694
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16694] Add pure Python operator module

2012-12-19 Thread Zachary Ware

Changes by Zachary Ware zachary.w...@gmail.com:


Removed file: http://bugs.python.org/file28373/py_operator.v2.diff

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16694
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16694] Add pure Python operator module

2012-12-17 Thread Jesús Cea Avión

Changes by Jesús Cea Avión j...@jcea.es:


--
nosy: +jcea

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16694
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16694] Add pure Python operator module

2012-12-16 Thread Serhiy Storchaka

Changes by Serhiy Storchaka storch...@gmail.com:


--
stage:  - patch review

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16694
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16694] Add pure Python operator module

2012-12-16 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Here is a functional (and more effective) equivalent of attrgetter:

def attrgetter(attr, *attrs):

Return a callable object that fetches the given attribute(s) from its 
operand.
After f=attrgetter('name'), the call f(r) returns r.name.
After g=attrgetter('name', 'date'), the call g(r) returns (r.name, r.date).
After h=attrgetter('name.first', 'name.last'), the call h(r) returns
(r.name.first, r.name.last).

if not attrs:
if not isinstance(attr, str):
raise TypeError('attribute name must be a string')
names = attr.split('.')
def func(obj):
for name in names:
obj = getattr(obj, name)
return obj
return func
else:
getters = tuple(map(attrgetter, (attr,) + attrs))
def func(obj):
return tuple(getter(obj) for getter in getters)
return func

--
nosy: +serhiy.storchaka

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16694
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16694] Add pure Python operator module

2012-12-16 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Perhaps Modules/operator.c should be renamed to Modules/_operator.c.

Also note, that error messages in Python an C implementations sometimes differ.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16694
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16694] Add pure Python operator module

2012-12-16 Thread Arfrever Frehtes Taifersar Arahesis

Changes by Arfrever Frehtes Taifersar Arahesis arfrever@gmail.com:


--
nosy: +Arfrever

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16694
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16694] Add pure Python operator module

2012-12-15 Thread Zachary Ware

New submission from Zachary Ware:

(Brett, I've made you nosy due to the relation to Issue16651.)

Here is a pure Python implementation of the operator module, or at least a 
first draft thereof :).  I'm attaching the module itself, as well as a patch to 
integrate it.

Any and all review is quite welcome. I'm confident in the fact that the module 
as it stands passes all current tests, but how it gets there is entirely up for 
debate (namely, the attrgetter, itemgetter, and methodcaller classes, as well 
as length_hint(), countOf(), and indexOf()).

Note that there's also a change to hmac.py; _compare_digest() in operator.c 
doesn't seem to have any relation to the rest of the module (see issue15061 
discussion) and is private anyway, so operator.py doesn't go near it.  hmac.py 
has to import directly from _operator.

Thanks,

Zach Ware

--
components: Extension Modules, Library (Lib)
files: operator.py
messages: 177579
nosy: brett.cannon, zach.ware
priority: normal
severity: normal
status: open
title: Add pure Python operator module
type: enhancement
versions: Python 3.4
Added file: http://bugs.python.org/file28327/operator.py

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16694
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16694] Add pure Python operator module

2012-12-15 Thread Zachary Ware

Changes by Zachary Ware zachary.w...@gmail.com:


--
keywords: +patch
Added file: http://bugs.python.org/file28328/py_operator.diff

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16694
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: Python ++ Operator?

2011-07-19 Thread Chris Torek
In article mailman.1057.1310717193.1164.python-l...@python.org
Chris Angelico  ros...@gmail.com wrote:
I agree that [C's ++ operators are] often confusing (i+j) ...

For what it is worth, this has to be written as:

i++ + ++j /* or i+++ ++j */

or similar (e.g., newline after the middle + operator) as the
lexer will group adjacent ++ characters into a single ++ operator
whenever it can (the so-called greedy matching that regular
expression recognizers are famous for), and only later will the
parser and semantic analysis phases realize that i++ ++ +j is
invalid and complain.

but there are several places where they're handy. ...
However, Python doesn't work as close to the bare metal, so it
doesn't have such constructs.

More specifically, Python has appropriate higher-level constructs
that, in effect, maintain mental invariants in a better (for some
value of better) way.  Instead of:

lst[i++] = val; /* or: *p++ = val; */

which has the effect of appending an item to an array-based list
of items -- the invariant here is that i (or p in the pointer
version) always tells you where the place the *next* item -- one
simply writes:

lst.append(val)

(which also makes sure that there is *room* in the array-based
list, something that requires a separate step in C).
-- 
In-Real-Life: Chris Torek, Wind River Systems
Intel require I note that my opinions are not those of WRS or Intel
Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W)  +1 801 277 2603
email: gmail (figure it out)  http://web.torek.net/torek/index.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python ++ Operator?

2011-07-16 Thread Waldek M.
Dnia Fri, 15 Jul 2011 23:09:02 +0200, Stefan Behnel napisał(a):
[...]
 array[count++]=value;

 or the more direct pointer management:
 *ptr++=value;
 
 More direct, sure. But readable? Well, only when you know what this 
 specific pattern does. If you have to think about it, it may end up hurting 
 your eyes before you figure it out.

Oh, come on. I don't say the post- and pre-incrementing is 
good or bad, but please don't exagerate. 

Almost any other construction is unreadable to people, who
don't know this construction, eg. a==1, a+=1
may be completely senseless to mathematicians.

Best regards,
Waldek
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python ++ Operator?

2011-07-16 Thread Nobody
On Fri, 15 Jul 2011 23:09:02 +0200, Stefan Behnel wrote:

 or the more direct pointer management:

 *ptr++=value;
 
 More direct, sure. But readable? Well, only when you know what this
 specific pattern does. If you have to think about it, it may end up
 hurting your eyes before you figure it out.

If you have to think about it, you shouldn't even be using C.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python ++ Operator?

2011-07-16 Thread Adam Przybyla
Chris Angelico ros...@gmail.com wrote:
 On Sat, Jul 16, 2011 at 6:26 AM, Dan Stromberg drsali...@gmail.com wrote:

 I don't regard this as a low level versus VHLL issue - I regard it as a
 matter of operators with side effects being too error prone.  Adding such
 operators to Python has been discussed (it'd almost certainly be easy to
 add), and rejected.
 
 It's not that it has or has not, due to its highness of level, but
 more a needs or needs not. In Python, iterating over an array is done
 with a for loop and the array's own iterator (or enumerate() if you
 need the indices), but C doesn't have iterators, so it needs a
 convenient notation for incrementing through the array.
 
 BTW, array operations optimize to the same thing as pointer arithmetic in
 most C compilers, but the latter tends to be less clear.
 
 I'm not fully convinced; there are many times when incrementing
 pointers allows for much cleaner code. However, we are talking about
 the readability of C among Python programmers. Personally, I find
 pointer-dereference-and-post-increment to be perfectly readable, but
 it's a construct that I use practically on a daily basis. To someone
 who's not familiar with Python, list comps could suffer from the same
 issues - what does THIS do? oh.
list_ptr=list_a
list_ptr=list_ptr[1:]
Regards
Adam Przybyla
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python ++ Operator?

2011-07-16 Thread Robert Kern

On 7/16/11 4:55 AM, Waldek M. wrote:

Dnia Fri, 15 Jul 2011 23:09:02 +0200, Stefan Behnel napisał(a):
[...]

array[count++]=value;

or the more direct pointer management:
*ptr++=value;


More direct, sure. But readable? Well, only when you know what this
specific pattern does. If you have to think about it, it may end up hurting
your eyes before you figure it out.


Oh, come on. I don't say the post- and pre-incrementing is
good or bad, but please don't exagerate.

Almost any other construction is unreadable to people, who
don't know this construction, eg. a==1, a+=1
may be completely senseless to mathematicians.


No construction is truly intuitive and immediately understandable to everyone, 
but there are constructions that are less easy to understand than others. a==1 
and a+=1 both have few moving parts that you have to learn, and they combine 
with other constructions fairly straightforwardly. *ptr++=value has several 
moving parts, each of which are understandable separately, but understanding 
their separate functions does not give immediate understanding of their combined 
meaning. You not only have to learn the meaning of each component, you have to 
separately learn how they combine.


--
Robert Kern

I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth.
  -- Umberto Eco

--
http://mail.python.org/mailman/listinfo/python-list


Python ++ Operator?

2011-07-15 Thread Rafael Durán Castañeda
Hello all,

I seem something like this on python code:

for  :
for  :
 spam[i][eggs] = ham
   ++i
.
.
.

What's the meaning of using i++? Even, does exist ++ operator in python?

Bye
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python ++ Operator?

2011-07-15 Thread Björn Lindqvist
2011/7/15 Rafael Durán Castañeda rafadurancastan...@gmail.com:
 What's the meaning of using i++? Even, does exist ++ operator in python?

No it doesn't, which is a good thing. Python differentiates between
expressions and variable assignments. i++ in C both assigns the
value i + 1 to i AND evaluates to i. Pre and post-increments are
almost always confusing unless they are used as the counter-variable
inside for-loops.


-- 
mvh/best regards Björn Lindqvist
http://www.footballexperts.net/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python ++ Operator?

2011-07-15 Thread Chris Angelico
2011/7/15 Rafael Durán Castañeda rafadurancastan...@gmail.com:
 Hello all,
 What's the meaning of using i++? Even, does exist ++ operator in python?

++i is legal Python but fairly useless. It's the unary + operator,
applied twice. It doesn't increment the variable.

Now, i+=1 IS valid Python, and WILL do what a C programmer expects it to.

ChrisA
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python ++ Operator?

2011-07-15 Thread Chris Angelico
2011/7/15 Björn Lindqvist bjou...@gmail.com:
 Pre and post-increments are
 almost always confusing unless they are used as the counter-variable
 inside for-loops.

I agree that they're often confusing (i+j) but there are several
places where they're handy.

array[count++]=value;

or the more direct pointer management:

*ptr++=value;

However, Python doesn't work as close to the bare metal, so it doesn't
have such constructs.

ChrisA
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python ++ Operator?

2011-07-15 Thread Dan Stromberg
On Fri, Jul 15, 2011 at 1:06 AM, Chris Angelico ros...@gmail.com wrote:

 2011/7/15 Björn Lindqvist bjou...@gmail.com:
  Pre and post-increments are
  almost always confusing unless they are used as the counter-variable
  inside for-loops.

 I agree that they're often confusing (i+j) but there are several
 places where they're handy.

 array[count++]=value;

 or the more direct pointer management:

 *ptr++=value;

 However, Python doesn't work as close to the bare metal, so it doesn't
 have such constructs.


I don't regard this as a low level versus VHLL issue - I regard it as a
matter of operators with side effects being too error prone.  Adding such
operators to Python has been discussed (it'd almost certainly be easy to
add), and rejected.

BTW, array operations optimize to the same thing as pointer arithmetic in
most C compilers, but the latter tends to be less clear.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python ++ Operator?

2011-07-15 Thread Chris Torek
In article mailman.1055.1310716536.1164.python-l...@python.org
Chris Angelico  ros...@gmail.com wrote:
2011/7/15 Rafael Durán Castañeda rafadurancastan...@gmail.com:
 Hello all,
 What's the meaning of using i++? Even, does exist ++ operator in python?

++i is legal Python but fairly useless. It's the unary + operator,
applied twice. It doesn't increment the variable.

Well...

class Silly:
def __init__(self, value):
self.value = value
self._pluscount = 0
def __str__(self):
return str(self.value)
def __pos__(self):
self._pluscount += 1
if self._pluscount == 2:
self.value += 1
self._pluscount = 0
return self

def main():
i = Silly(0)
print('initially, i = %s' % i)
print('plus-plus i = %s' % ++i)
print('finally, i = %s' % i)

main()

:-)

(Of course, +i followed by +i *also* increments i...)
-- 
In-Real-Life: Chris Torek, Wind River Systems
Intel require I note that my opinions are not those of WRS or Intel
Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W)  +1 801 277 2603
email: gmail (figure it out)  http://web.torek.net/torek/index.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python ++ Operator?

2011-07-15 Thread Stefan Behnel

Chris Angelico, 15.07.2011 10:06:

2011/7/15 Björn Lindqvist:

Pre and post-increments are
almost always confusing unless they are used as the counter-variable
inside for-loops.


I agree that they're often confusing (i+j) but there are several
places where they're handy.

array[count++]=value;

or the more direct pointer management:

*ptr++=value;


More direct, sure. But readable? Well, only when you know what this 
specific pattern does. If you have to think about it, it may end up hurting 
your eyes before you figure it out.


Stefan

--
http://mail.python.org/mailman/listinfo/python-list


Re: Python ++ Operator?

2011-07-15 Thread Chris Angelico
On Sat, Jul 16, 2011 at 6:26 AM, Dan Stromberg drsali...@gmail.com wrote:

 I don't regard this as a low level versus VHLL issue - I regard it as a
 matter of operators with side effects being too error prone.  Adding such
 operators to Python has been discussed (it'd almost certainly be easy to
 add), and rejected.

It's not that it has or has not, due to its highness of level, but
more a needs or needs not. In Python, iterating over an array is done
with a for loop and the array's own iterator (or enumerate() if you
need the indices), but C doesn't have iterators, so it needs a
convenient notation for incrementing through the array.

 BTW, array operations optimize to the same thing as pointer arithmetic in
 most C compilers, but the latter tends to be less clear.

I'm not fully convinced; there are many times when incrementing
pointers allows for much cleaner code. However, we are talking about
the readability of C among Python programmers. Personally, I find
pointer-dereference-and-post-increment to be perfectly readable, but
it's a construct that I use practically on a daily basis. To someone
who's not familiar with Python, list comps could suffer from the same
issues - what does THIS do? oh.

Chris Angelico
-- 
http://mail.python.org/mailman/listinfo/python-list


php vs python (operator comparison)-repost

2006-06-21 Thread brandon.mcginty








Im sorry if this was already posted to the list; Ive
been having major e-mail problems lately.



Hi All,



Ive already done a large amount of searching on
Google to find out this information, but to no avale.



Does anyone here know of a list of operators in python and
there counterparts in php, or a website with this information?



Im going to be trying to port some php and perl stuff
to python, and this information would be extremely useful, rather than going
through all the documentation

and reinventing the wheel.



Thanks Much,







--

Brandon McGinty

Email:b[EMAIL PROTECTED]
Skype:brandon.mcginty
Msn:[EMAIL PROTECTED]
Aim:brandonmcginty0 (Not currently available.)
Cell:4802025790 (Weekends and nights only, please.)
Languages:python, php, autoit; Currently Learning:perl

Kindness is a language that the deaf can hear and the
blind can see.
Mark Twain








-- 
http://mail.python.org/mailman/listinfo/python-list