Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recursion error on converter with explicit nested models #329

Open
Tishka17 opened this issue Aug 14, 2024 · 1 comment
Open

Recursion error on converter with explicit nested models #329

Tishka17 opened this issue Aug 14, 2024 · 1 comment
Labels

Comments

@Tishka17
Copy link
Member

Tishka17 commented Aug 14, 2024

Code:

@dataclass
class A0:
    pass

@dataclass
class A:
    ass: Optional[list["A"]]

@impl_converter()
def a(src: A0, ass: Optional[list[A]]) -> A:
    ...

Part of result

  File "/usr/local/lib/python3.11/site-packages/adaptix/_internal/model_tools/introspection/callable.py", line 58, in get_callable_shape
    signature = inspect.signature(func)
                ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/inspect.py", line 3263, in signature
    return Signature.from_callable(obj, follow_wrapped=follow_wrapped,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/inspect.py", line 3011, in from_callable
    return _signature_from_callable(obj, sigcls=cls,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/inspect.py", line 2528, in _signature_from_callable
    return _signature_from_builtin(sigcls, obj,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/inspect.py", line 2328, in _signature_from_builtin
    return _signature_fromstr(cls, func, s, skip_bound_arg)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/inspect.py", line 2179, in _signature_fromstr
    _signature_strip_non_python_syntax(s)
  File "/usr/local/lib/python3.11/inspect.py", line 2121, in _signature_strip_non_python_syntax
    token_stream = tokenize.tokenize(generator)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/tokenize.py", line 427, in tokenize
    encoding, consumed = detect_encoding(readline)
                         ^^^^^^^^^^^^^^^^^^^^^^^^^
RecursionError: maximum recursion depth exceeded

This code works well on 3.0.0b6 on python 3.11

@Tishka17 Tishka17 changed the title Reucrsion error on converter with explicit Recursion error on converter with explicit ensted models Aug 14, 2024
@Tishka17 Tishka17 changed the title Recursion error on converter with explicit ensted models Recursion error on converter with explicit nested models Aug 14, 2024
@Tishka17
Copy link
Member Author

Tishka17 commented Aug 14, 2024

Workaround is to fill recursive fields with defaults in converter and fill manually in wrapper .
This could look ugly because there are no extra fields, but in real project there can be more fields, that are processed normally

@impl_converter(
    recipe=[
        link_constant(P[A].ass, value=None),
    ]
)
def _a(src: A0) -> A:
    ...


def a(src: A0, ass: Optional[list[A]]) -> A:
    res = _a(src)
    res.ass = ass
    return res

@zhPavel zhPavel added type: feature New feature or request domain: conversion labels Sep 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants