Any comment on using ctypesgen package?

Chris Angelico rosuav at gmail.com
Fri Mar 4 07:00:13 EST 2016


On Fri, Mar 4, 2016 at 10:08 PM,  <jfong at ms4.hinet.net> wrote:
> Below is the troubled codes in file lex.py:
> Note: In original codes (before 2To3 modify), there is "types.ObjectType" instead of "object".
> ---------
> # Available instance types.  This is used when lexers are defined by a class.
> # It's a little funky because I want to preserve backwards compatibility
> # with Python 2.0 where types.ObjectType is undefined.
> try:
>     _INSTANCETYPE = (types.InstanceType, object)
> except AttributeError:
>     _INSTANCETYPE = types.InstanceType
>     class object: pass   # Note: needed if no new-style classes present
> -----------
> The author had put some comments above these codes but I have no idea what he is talking about.

I'm not sure exactly what this is trying to do, but if it's just for
isinstance testing, you can save yourself a lot of trouble. In Python
3, *every* type inherits from 'object'. So _INSTANCETYPE can be set to
just object - and anything that's trying to query that can simply
assume it's true.

ChrisA



More information about the Python-list mailing list