On 4/23/22 06:55, Jelle Zijlstra wrote:
So to reiterate, your proposal would be to write this as:
forward class B:
pass
class A:
value: B
continue class B:
value: A
Not quite; the "forward class" statement doesn't have a colon or a class
body. This would be written as:
forward class B
class A:
value: B
continue class B:
value: A
While the current workaround is:
class A:
value: "B"
class B:
value: "A"
In this example, with two toy classes in one file, it shouldn't be
necessary to quote the annotation in B. So all you need is the quotes
around the first annotation:
class A:
value: "B"
class B:
value: A
I don't think I would write the "forward class" version if I had the
choice. It's clunkier and requires more refactoring if I change my
mind about whether the `value` attribute should exist.
In this toy example, it adds an extra line. Describing that as "clunky"
is a matter of opinion; I disagree and think it's fine.
But the real difference is when it comes to larger codebases. If
classes "A" and "B" are referenced dozens or even hundreds of times,
you'd have to add quote marks around every annotation that references
one (both?). Manual stringization of large codebases was sufficiently
disliked as to have brought about the creation and acceptance of PEP
563. Judicious use of the "forward class" statement should obviate most
(all?) the manual stringizing in these codebases.
//arry/
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at
https://mail.python.org/archives/list/python-dev@python.org/message/TVCB6ITGHO5QI5GYFNMEVEZKE6K24UDB/
Code of Conduct: http://python.org/psf/codeofconduct/