classification
Title: dir of an "_sre.SRE_Match" object not working
Type: behavior Stage:
Components: Regular Expressions Versions: Python 3.0
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: amaury.forgeotdarc, vizcayno
Priority: normal Keywords:

Created on 2008-07-01 00:10 by vizcayno, last changed 2008-07-02 23:07 by amaury.forgeotdarc. This issue is now closed.

Messages (3)
msg69031 - (view) Author: vizcayno (vizcayno) Date: 2008-07-01 00:10
For Windows XP SP3:

v = 'add 1 to 4.56'
import re
r=re.search("([0-9]+)\D+(\d+\.\d+)","add 1 to 4.56")
r
<_sre.SRE_Match object at 0x00BED920>
r.groups()
('1', '4.56')
dir(r)
[]

in pyhton 2.5 it shows:
['__copy__', '__deepcopy__', 'end', 'expand', 'group', 'groupdict', 'gro
ups', 'span', 'start']
msg69117 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2008-07-02 20:43
The cause is that this object use a custom tp_getattr slot, and use
Py_FindMethod from there. and py3k removed the special "__methods__"
lookup that allowed to lists these items.

Of course, nowadays the way to add methods is not to put them in
tp_getattr, but in a tp_methods slot.
msg69141 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2008-07-02 23:07
Done in several changes: r64672 r64674 r64681.

Now the dir() is even more complete than before. I get:
['__class__', '__copy__', '__deepcopy__', '__delattr__', '__doc__',
'__eq__', '__format__', '__ge__', '__getattribute__', '__gt__',
'__hash__', '__init__', '__le__', '__lt__', '__ne__', '__new__',
'__reduce__', '__reduce_ex__', '__repr__','__setattr__', '__sizeof__',
'__str__', '__subclasshook__', 'end', 'endpos', 'expand', 'group',
'groupdict', 'groups', 'lastgroup', 'lastindex', 'pos', 're', 'regs',
'span', 'start', 'string']
History
Date User Action Args
2008-07-02 23:07:20amaury.forgeotdarcsetstatus: open -> closed
resolution: fixed
messages: + msg69141
2008-07-02 20:43:50amaury.forgeotdarcsetnosy: + amaury.forgeotdarc
messages: + msg69117
2008-07-01 00:10:50vizcaynocreate