FAQ
I've been working with the modulefinder.py code recently and I've come
across a bit of code I'm not grasping. In the scan_code function, there
are the following lines:
if sys.version_info >= (2, 5):
scanner = self.scan_opcodes_25
else:
scanner = self.scan_opcodes
I don't understand their purpose. Why would I be running a version of
python less than 2.6 and using the 2.6 module? Should this be looking at
the version of python that was used to compile 'co'?

In my use, I'm subclassing the modulefinder class and adapting the
scan_code function to do what I need, but I've found I need separate
classes for (2.4, 2.5) and 2.6 because when running 2.4 or 2.5, the
above code traces back. (In 2.4 because self.scan_opcodes isn't defined,
in 2.5 because self.scan_opcodes_25 isn't.)

In the end, I've gotten everything working to my satisfaction, but I'm
curious about how this module (and those lines in particular) were
designed to be used. Any insight would be appreciated.

Thanks,
Brock

Search Discussions

  • Gabriel Genellina at Jan 13, 2010 at 8:52 am
    En Tue, 12 Jan 2010 23:15:17 -0300, Brock Pytlik <bpytlik at sun.com>
    escribi?:
    I've been working with the modulefinder.py code recently and I've come
    across a bit of code I'm not grasping. In the scan_code function, there
    are the following lines:
    if sys.version_info >= (2, 5):
    scanner = self.scan_opcodes_25
    else:
    scanner = self.scan_opcodes
    I don't understand their purpose. Why would I be running a version of
    python less than 2.6 and using the 2.6 module? Should this be looking at
    the version of python that was used to compile 'co'?
    According to the comment at the top of modulefinder.py, for some reason
    (unknown to me) the module must remain compatible with Python 2.2. So the
    code from the 2.6 version should work fine when run under Python 2.2 (and
    indeed it does).
    In my use, I'm subclassing the modulefinder class and adapting the
    scan_code function to do what I need, but I've found I need separate
    classes for (2.4, 2.5) and 2.6 because when running 2.4 or 2.5, the
    above code traces back. (In 2.4 because self.scan_opcodes isn't defined,
    in 2.5 because self.scan_opcodes_25 isn't.)
    You could use a private copy of the last released version of modulefinder.
    In the end, I've gotten everything working to my satisfaction, but I'm
    curious about how this module (and those lines in particular) were
    designed to be used. Any insight would be appreciated.
    The bit I don't know is *why* modulefinder must remain 2.2 compatible;
    PEP291 says nothing. Maybe it is required by distutils.

    --
    Gabriel Genellina

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedJan 13, '10 at 2:15a
activeJan 13, '10 at 8:52a
posts2
users2
websitepython.org

2 users in discussion

Gabriel Genellina: 1 post Brock Pytlik: 1 post

People

Translate

site design / logo © 2022 Grokbase