pjkundert / cpppo

Communications Protocol Python Parser and Originator -- EtherNet/IP CIP
https://hardconsulting.com/products/6-cpppo-enip-api
Other
328 stars 108 forks source link

Support python 3.11, fix bug in CodeType arg order #110

Open crmaxj opened 1 year ago

crmaxj commented 1 year ago

I had an import failing when trying to run my cpppo code in python 3.11:

  File "/Users/maxj/Documents/Charge/factory/factory/drivers/al1120.py", line 16, in <module>
    from cpppo.server.enip.get_attribute import proxy_simple
  File "/Users/maxj/Library/Caches/pypoetry/virtualenvs/factory-4i3Wbpjw-py3.11/lib/python3.11/site-packages/cpppo/__init__.py", line 29, in <module>
    from .automata import *
  File "/Users/maxj/Library/Caches/pypoetry/virtualenvs/factory-4i3Wbpjw-py3.11/lib/python3.11/site-packages/cpppo/automata.py", line 33, in <module>
    from . import misc
  File "/Users/maxj/Library/Caches/pypoetry/virtualenvs/factory-4i3Wbpjw-py3.11/lib/python3.11/site-packages/cpppo/misc.py", line 221, in <module>
    change_function( __normal, co_filename=logging._srcfile )
  File "/Users/maxj/Library/Caches/pypoetry/virtualenvs/factory-4i3Wbpjw-py3.11/lib/python3.11/site-packages/cpppo/misc.py", line 180, in change_function
    modi_code           = types.CodeType( *modi_args )

I looked into this and it looked like there was some python-version-specific code in misc.py.

In addition to adding support for python version 3.11, I also noticed what I think is a bug in the existing code. If you run help(types.CodeType) in a python 3.8, 3.9, or 3.10 shell, you'll see that the second argument to code is posonlyargcount, but in the current code it is assumed to be kwonlyargcount. I fixed that in this PR as well.

I tested this by running the import in python versions 3.7, 3.9, 3.10, and 3.11. I did not test in python 2.

It would be cool if someone with more knowledge of this code than me could kill this function entirely! Also I didn't see any CONTRIBUTING docs, so apologies if I'm doing this wrong. Thank you!

djformby commented 1 year ago

I ran into this too and made my own fix before finding yours. I just tested your changes with version 3.11 and can confirm that it fixed my problem

acode-x commented 7 months ago

Can we get this merged?

crmaxj commented 2 months ago

Hi @pjkundert, just wanted to follow up on this, any chance we could please merge this PR?

pjkundert commented 2 months ago

Hi, @crmaxj;

Sorry, I've been super busy with other work!  I have a huge branch that includes all this and many other fixes (feature-pro).

Unfortunately, nobody seems all that interested in this project, so I've had to prioritise paying work!  I'll see if I can get to it soon.
crmaxj commented 2 months ago

No worries at all, that is super understandable! Just sent a small donation your way, keep up the good work.

pjkundert commented 2 months ago

Wow thanks! That's really appreciated. I'll try to get to it soon.