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

Error occurs when using converters.optional and converters.pipe together #1348

Open
MioYvo opened this issue Sep 18, 2024 · 0 comments
Open

Comments

@MioYvo
Copy link

MioYvo commented Sep 18, 2024

23.2.0 is OK.

Python 3.10.13 (main, Dec  6 2023, 12:01:00) [GCC 13.2.1 20230801] on linux
>>> import attr
>>> attr.__version__
'23.2.0'
>>> @attr.define
... class A:
...     abc: int | None = attr.field(converter=attr.converters.optional(attr.converters.pipe(str, int)), default=None)
...     
>>> A()
A(abc=None)
>>> A('1')
A(abc=1)

after 24.1.0, error occurs:

Python 3.10.13 (main, Dec  6 2023, 12:01:00) [GCC 13.2.1 20230801] on linux
>>> import attr
>>> attr.__version__
'24.2.0'
>>> @attr.define
... class A:
...     abc: int | None = attr.field(converter=attr.converters.optional(attr.converters.pipe(str, int)), default=None)
...     
>>> A()
A(abc=None)
>>> A('1')
Traceback (most recent call last):
  File "/opt/pycharm-professional/plugins/python-ce/helpers/pydev/pydevconsole.py", line 364, in runcode
    coro = func()
  File "<input>", line 1, in <module>
  File "<attrs generated init __main__.A>", line 3, in __init__
  File "/home/mio/Work/venv/calliper310N/lib/python3.10/site-packages/attr/converters.py", line 40, in optional_converter
    return converter(val)
TypeError: Converter.__init__.<locals>.<lambda>() missing 2 required positional arguments: 'instance' and 'field'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant