On Sun, Dec 12, 2021 at 4:06 AM Christopher Barker <python...@gmail.com> wrote:
> Here’s a new (not well thought out) idea:
>
> @dataclasses.dataclass
> class A:
>     Input_list: list
>     length: int => len(input_list)
>
> So length gets set to a “late bound default expression” that Is an actual 
> value. It would have to store the expression itself, probably as a string, 
> and it would get evaluated in the namespace of the function, when the 
> function was called. So the generated __init__ would be the same as:
>
> def __init__(self, input_list, length=>len(input_list):

If I'm not mistaken, dataclasses generate __init__ using exec anyway,
so this would work with a plain string.

ChrisA
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/26KTI6DXSB5GJBXEHHFXZEW3222NVWWK/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to