autoslot icon indicating copy to clipboard operation
autoslot copied to clipboard

Can you tell me how to adjust to support python2 for autoslot ?

Open ChenJhua opened this issue 2 years ago • 1 comments

I have a lot of python2 object initialization, resulting in a large memory, file modification and upgrading python3 is a big move for me, so I am looking for automatic generation of slots, but I did not find a suitable method. Can you tell me how autoslot supports python2? Because the dis library is too different

ChenJhua avatar Mar 18 '23 06:03 ChenJhua

I apologise for missing your question! I only saw it now.

The basic design of autoslot is to scan the byte code of the __init__ method of a class and detect assignments to attributes of the object (self). This work is actually done in a metaclass, because doing so allows the metaclass to set the __slots__ field during class creation. (The purposes of metaclass is to modify the behaviour of class construction).

The code of autoslot is quite short, so perhaps you can figure out it out just be reading the code, and modifying the detected bytecode operations to detect assignment.

cjrh avatar Jun 04 '23 20:06 cjrh