On Tue, Apr 26, 2022 at 12:33 AM Mehdi2277 <med2...@gmail.com> wrote:

> The forward class annotations would not need need to be processed at
> runtime and could be no-ops.
>
> forward class A:
>   x: int
>   y: list[int]
>
>

So, as I"ve written before, since there seems to be no way out of Writing
Everything Twice
what about:

```
from typing import Protocol

class AProto(Protocol):
     x: int
     y: list[int]

     def distance(self, x: int, y: int) -> list[float]:
         ...

class B:
     value: AProto

class A(AProto):  #  inheriting from the protocol is optional, as per
PEP-544
    x: int
    y: list[int]

    def distance(self, x: int, y: int) -> list[float]:
         # code for distance goes here
         ...
```

The best advantage of this particular bikeshed is that it makes
full use of Guido's Time Machine and is readily usable from Python 3.8
onwards!


A.__annotations__ could be empty. For a more complete example you could
> have,
>
> forward class A:
>   value: B # This annotation is solely for type checker and is not
> actually saved at runtime.
>
> class B:
>   value: A # Real annotation that is saved.
>
> continue class A:
>   value: B # Real annotation that is saved.
>
> The rule would then be that any annotation inside forward class is
> equivalent to a noop. Continue class would still need to have same
> annotation repeated to actually set it at runtime.
> _______________________________________________
> 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/O3HMCIWUM6NGTSCGL7HFRBSDT7A4KFHP/
> Code of Conduct: http://python.org/psf/codeofconduct/
>
_______________________________________________
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/3CIYJ43YQ5SCGO7M4LU2P6YCWNDV64DC/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to