This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Add mapping of symbol to function to operator module
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.5
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: barry, belopolsky, brett.cannon, cvrebert, eric.araujo, ezio.melotti, ncoghlan, rhettinger, ron_adam, serhiy.storchaka, zach.ware
Priority: normal Keywords: patch

Created on 2013-07-12 20:46 by zach.ware, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
operator-symbol-map.diff zach.ware, 2013-07-12 20:46 Implement operator.symbol_map and operator.get_op review
Messages (7)
msg192970 - (view) Author: Zachary Ware (zach.ware) * (Python committer) Date: 2013-07-12 20:46
In a thread on python-ideas[1], Nick mentioned the idea of ``operator.by_symbol['+=']`` which would be an alternative method of getting the operator.iadd function.  The idea struck my fancy, so I implemented it (regardless of the very real possibility of being rejected anyway, judging by the current split vote in the thread :)).  

I also implemented Brett's suggestion of supporting '.attribute' and '[item]' as well.

Here's the (still a bit rough) patch.

[1] http://mail.python.org/pipermail/python-ideas/2013-July/022078.html
msg192973 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2013-07-12 21:41
Added some comments on Rietveld.
msg193058 - (view) Author: Ron Adam (ron_adam) * Date: 2013-07-14 15:48
Regarding opertor.get_op:

Look at help("symbols") output for consistancy.  There may be items in one that can be included in the other.

The operator.get_op addition would be useful for improving help on the symbol information for help/pydoc. Currently it seems overly general for symbols.

Also patch, http://bugs.python.org/issue18387, which adds help("symbols") output to pydocs web browser interface.  It could use a review.
msg193080 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2013-07-15 07:57
What is a purpose of this feature? Why you need it?
msg193106 - (view) Author: Zachary Ware (zach.ware) * (Python committer) Date: 2013-07-15 14:30
The purpose is to make usage of the operator module more readable, particularly for some of the more exotic operators.  For instance, I find ``operator.get_op(">>=")`` to be a lot more obvious about what's going to happen than ``operator.irshift``.

Also, I think it is helpful to have available a listing of all the operators that Python supports.  If we're going to have such a listing, why not make it a mapping of op to function?  And once we have such a mapping, it would be nice to have a nice interface to it.

Having this available would make it easy to implement the kind of function that Nick mentioned in the python-ideas thread, that takes an operator string instead of only a function.

I will admit that the need is not great, and obviously this isn't something that someone who needs it couldn't do themselves.  But I think the convenience of it makes it at least worth consideration.
msg193107 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2013-07-15 14:37
I liked Ron's suggestion of using it to improve the output of help() (by getting access to the docstrings of the operator functions, and then enhancing those to be a bit more informative)
msg223957 - (view) Author: Zachary Ware (zach.ware) * (Python committer) Date: 2014-07-25 15:15
With no one (including me) clamoring for this, I'm going to go ahead and reject it.  If someone in the future does really want this, I'd be happy to review a new patch.
History
Date User Action Args
2022-04-11 14:57:47adminsetgithub: 62636
2014-07-25 15:15:10zach.waresetstatus: open -> closed
versions: + Python 3.5, - Python 3.4
messages: + msg223957

resolution: rejected
stage: resolved
2013-08-08 17:40:32ezio.melottisetnosy: + ezio.melotti
2013-07-19 18:17:22cvrebertsetnosy: + cvrebert
2013-07-15 14:37:02ncoghlansetmessages: + msg193107
2013-07-15 14:30:45zach.waresetmessages: + msg193106
2013-07-15 07:57:56serhiy.storchakasetnosy: + rhettinger
messages: + msg193080
2013-07-14 15:48:13ron_adamsetnosy: + ron_adam
messages: + msg193058
2013-07-12 21:41:27eric.araujosetnosy: + eric.araujo
messages: + msg192973
2013-07-12 20:46:46zach.warecreate