[issue25652] collections.UserString.__rmod__() raises NameError
Jonathan Goble added the comment: I would prefer to keep __rmod__ and fix the bug, given that the use case I described above would otherwise create an inconsistency in subclasses, which would be able to easily extend __mod__ by calling super(), but would be forced to fully implement __rmod__ themselves. That said, I will defer to those who are more experienced here. -- ___ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue25652> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue25652] collections.UserString.__rmod__() raises NameError
Jonathan Goble added the comment: Any decision on this? I recently played around and found a reasonable use case where UserString.__rmod__ does get called; run the attached userstringerror.py to see it in action. Basically, it seems the idea of UserString is to subclass it, tweak as desired, and use your subclass as necessary. If you then subclass your subclass (e.g. for a portion of your code with a specialized need) and extend __mod__ and __rmod__ in that sub-subclass (calling the parent method with super()), then any case of "subclass instance % sub-subclass instance" results in Python calling the sub-subclass's __rmod__ method directly without trying a __mod__ method. If that method then calls super().__rmod__ (e.g. it just needed to pre-process the data, such as to normalize it, before the formatting operation), then UserString.__rmod__ will be called and result in the NameError. -- versions: +Python 3.7 -Python 3.5 Added file: http://bugs.python.org/file46854/userstringerror.py ___ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue25652> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue30299] Display the bytecode when compiled a regular expression in debug mode
Changes by Jonathan Goble <jcgob...@gmail.com>: -- nosy: +Jonathan Goble ___ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue30299> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue25652] collections.UserString.__rmod__() raises NameError
Jonathan Goble added the comment: Code analysis, if it can even be called that. I was simply looking through the source of the collections module one day out of curiosity (mainly to see how various things in it were implemented) and this bug jumped out at me as I was reading the code. I do not have a use case for the __rmod__() method. -- ___ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue25652> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue25652] collections.UserString.__rmod__() raises NameError
Jonathan Goble added the comment: *ping* Can this be reviewed? It's a simple fix to a problem that happens consistently, and it would be nice to get it into the next bugfix release. -- versions: +Python 3.6 ___ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue25652> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue26336] Expose regex bytecode as attribute of compiled pattern object
Jonathan Goble added the comment: Noting for the record that, as I had brought up on python-ideas [1], in addition to simply exposing the raw code, it would be nice to have a public constructor for the compiled pattern type and a 'dis'-like module for support. The former would enable optimizers, and the latter would simplify programmatic analysis. [1] https://mail.python.org/pipermail/python-ideas/2016-February/thread.html#38488 -- ___ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue26336> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue26336] Expose regex bytecode as attribute of compiled pattern object
Jonathan Goble added the comment: It would indeed be marked as a CPython implementation detail, and with no guarantee of backward compatibility. Others (well, at least one other) have suggested the same on python-ideas. So a simple note in the accompanying documentation would suffice. -- ___ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue26336> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue26336] Expose regex bytecode as attribute of compiled pattern object
New submission from Jonathan Goble: Once a regular expression is compiled with `obj = re.compile()`, it would be nice to have access to the raw bytecode, probably as `obj.code` or `obj.bytecode`, so it can be explored programmatically. Currently, regex bytecode is only stored in a C struct and not exposed to Python code; the only way to examine the compiled version is to pass the `re.DEBUG` flag to `re.compile()`, which prints only to stdout and outputs not the finished bytecode, but a "pretty-printed" intermediate representation useless for programmatic analysis. This is basically requesting the equivalent of the `co_code` attribute of the code object returned by the built-in `compile()`, but for regular expression objects instead of Python code objects. Given that the bytecode can actually be multi-byte integers, `regexobj.bytecode` should return a list (perhaps even just the same list passed to the C function?) or an `array.array()` instance, rather than a bytestring. -- components: Library (Lib), Regular Expressions messages: 260072 nosy: Jonathan Goble, ezio.melotti, mrabarnett, pitrou, serhiy.storchaka priority: normal severity: normal status: open title: Expose regex bytecode as attribute of compiled pattern object type: enhancement versions: Python 3.6 ___ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue26336> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue25652] collections.UserString.__rmod__() raises NameError
New submission from Jonathan Goble: In an instance of collections.UserString, any call to the __rmod__() method will raise NameError, due to the undefined "args" name in the method. -- components: Library (Lib) messages: 254830 nosy: Jonathan Goble, rhettinger priority: normal severity: normal status: open title: collections.UserString.__rmod__() raises NameError type: behavior versions: Python 3.5 ___ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue25652> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue25652] collections.UserString.__rmod__() raises NameError
Jonathan Goble added the comment: c06b2480766d appears to be the offending changeset. -- ___ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue25652> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com