Skip to content

Python 3.13 compatibility problem (with fix) #223

@rolandmas

Description

@rolandmas
  • app-model version: 0.3.0
  • Python version: 3.13
  • Operating System: Debian unstable

Description

Running the testsuite on Debian unstable with Python 3.13 fails because the code generates warnings, and pytest dislikes warnings. The warning is due to the fact that lines 513-514 of src/app_model/expressions/ cause the constructor for ast.Set to be called with a ctx keyword which it doesn't know about. This was silently ignored in Python 3.12, but causes warnings in 3.13 (and will cause errors in 3.15 if I understand correctly):

_________________________ test_serdes[1 in {1, 2, 3}] __________________________

expr = '1 in {1, 2, 3}'

    @pytest.mark.parametrize("expr", GOOD_EXPRESSIONS)
    def test_serdes(expr):
>       assert str(parse_expression(expr)) == expr

tests/test_context/test_expressions.py:204: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
app_model/expressions/_expressions.py:68: in parse_expression
    return ExprTransformer().visit(tree.body)
app_model/expressions/_expressions.py:565: in visit
    kwargs[name] = [self.visit(item) for item in field]
app_model/expressions/_expressions.py:570: in visit
    return cast(Expr, globals()[type_](**kwargs))
app_model/expressions/_expressions.py:514: in __init__
    super().__init__(elts=[Expr._cast(e) for e in elts], **kwargs)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = Expr.parse('{1, 2, 3}'), args = ()
kwargs = {'col_offset': 0, 'ctx': <ast.Load object at 0x7f9601d9a810>, 'elts': [Expr.parse('1'), Expr.parse('2'), Expr.parse('3')], 'lineno': 1}

    def __init__(self, *args: Any, **kwargs: Any) -> None:
        if type(self).__name__ == "Expr":
            raise RuntimeError("Don't instantiate Expr. Use `Expr.parse`")
>       super().__init__(*args, **kwargs)
E       DeprecationWarning: Set.__init__ got an unexpected keyword argument 'ctx'. Support for arbitrary keyword arguments is deprecated and will be removed in Python 3.15.

app_model/expressions/_expressions.py:186: DeprecationWarning

What I Did

I rebuilt the package for the current Debian unstable, which has started to support python3.13 a few days ago.

Simple fix

Just drop line 513 (kwargs["ctx"] = ctx) in Set.init(). I added that as a patch to the Debian package, but it would be better if it were included upstream.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions