ponyorm / pony

Pony Object Relational Mapper
Apache License 2.0
3.63k stars 245 forks source link

Fix Python 3.11 compatibility #671

Closed roehling closed 1 year ago

jspricke commented 1 year ago

I opted for skipping the test in old Python versions. Both fixing the indention or dedent to match the output seems to need non trivial amount of code.

boxed commented 1 year ago

What's the status here?

If just some indent is changed but the code works, might I suggest duplicating the tests and set skip properly for each version?

copalco commented 1 year ago

Any news?

pjdewitte commented 1 year ago

It is great to see work is being done to support Python 3.11!

I tested this pull request and found an expression that no longer decompiles properly:

(person for person in Person if (person.address is None or person.address.street == "void"))

When using Python 3.11, "is None" decompiles to "is not None". When using Python 3.10, it does work correctly.

I dug into the decompiling and found that POP_JUMP_FORWARD_IF_NONE gets negated, while it shouldn't in this case.

BTW: assertDecompilesTo is great for checking this. The "not-so-better workaround" seems fine to me: stripping whitespace makes sense.

roehling commented 1 year ago

When using Python 3.11, "is None" decompiles to "is not None". When using Python 3.10, it I dug into the decompiling and found that POP_JUMP_FORWARD_IF_NONE gets negated, while it shouldn't in this case.

You are right! I remember I found this before and thought I had fixed this, but apparently I forgot to update the PR accordingly. Sorry!

pjdewitte commented 1 year ago

@roehling Thanks for fixing this!

My testing didn't reveal other bugs.

nburns commented 1 year ago

really looking forward to using this

fredrik-smedberg commented 1 year ago

@kozlovsky please check.

mmuehle commented 1 year ago

Maybe it would be a good idea to drop support of deprecated python version 3.6 and 3.7 for future releases? No one should use these versions in production code, because they have no security patches any more.

Peoples which like to have support for older version can still use previous releases of pony.

My team would like to use python 3.11 as it is the actual python version with active support. Therfore it would be great to merge these changes into a new official release.

kozlovsky commented 1 year ago

Thank you for this PR, and I am sorry for the delay! Confirmed it works for Python 3.8-3.11. I agree that it is time to drop support of Python versions < 3.8.

boxed commented 1 year ago

Could we get a release on pypi for this? I would love to be able to close the open issue I have on mutmut for this..

nburns commented 12 months ago

Seems to not support JUMP_BACKWARD correctly?

On the latest version I get the following error:

> python --version
Python 3.11.5
> pip freeze | grep pony
pony==0.7.17
models/permissions/position.py:58: in positions_with_permission_type
    empty_set = select(p for p in Position if False)
../../.asdf/installs/python/3.11.5/lib/python3.11/site-packages/pony/orm/core.py:5560: in select
    return make_query(args, frame_depth=cut_traceback_depth+1)
../../.asdf/installs/python/3.11.5/lib/python3.11/site-packages/pony/orm/core.py:5546: in make_query
    tree, external_names, cells = decompile(gen)
../../.asdf/installs/python/3.11.5/lib/python3.11/site-packages/pony/orm/decompiling.py:43: in decompile
    decompiler = Decompiler(codeobject)
../../.asdf/installs/python/3.11.5/lib/python3.11/site-packages/pony/orm/decompiling.py:162: in __init__
    decompiler.decompile()
../../.asdf/installs/python/3.11.5/lib/python3.11/site-packages/pony/orm/decompiling.py:273: in decompile
    throw(DecompileError('Unsupported operation: %s' % opname))
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

exc_type = DecompileError('Unsupported operation: JUMP_BACKWARD'), args = (), kwargs = {}

    def throw(exc_type, *args, **kwargs):
        if isinstance(exc_type, Exception):
            assert not args and not kwargs
            exc = exc_type
        else: exc = exc_type(*args, **kwargs)
        exc.__cause__ = None
        try:
            if not (pony.MODE == 'INTERACTIVE' and options.CUT_TRACEBACK):
>               raise exc
E               pony.orm.decompiling.DecompileError: Unsupported operation: JUMP_BACKWARD

../../.asdf/installs/python/3.11.5/lib/python3.11/site-packages/pony/utils/utils.py:99: DecompileError