• from __future__ import annotations bug?

    From Joseph Garvin@21:1/5 to All on Fri Jun 30 17:35:36 2023
    ```
    from __future__ import annotations
    from typing import Generic, TypeVar

    T = TypeVar("T")
    class Foo(Generic[T]): ...
    class Bar(Foo[Buzz]): ... # NameError here
    class Buzz: ...
    ```

    This will error, despite the __future__ import, because cpython is trying
    to look up Buzz before it's defined, even though we have supposedly
    prevented annotations from being processed. I realize that Class[Args] is allowed in that area in general and isn't always type annotation related,
    but does this mean that even with PEP 649 that forward references will
    still be needed?

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Joseph Garvin@21:1/5 to k04jg02@gmail.com on Fri Jun 30 18:55:19 2023
    Should mention this also affects Protocol[Buzz]

    On Fri, Jun 30, 2023, 5:35 PM Joseph Garvin <k04jg02@gmail.com> wrote:

    ```
    from __future__ import annotations
    from typing import Generic, TypeVar

    T = TypeVar("T")
    class Foo(Generic[T]): ...
    class Bar(Foo[Buzz]): ... # NameError here
    class Buzz: ...
    ```

    This will error, despite the __future__ import, because cpython is trying
    to look up Buzz before it's defined, even though we have supposedly
    prevented annotations from being processed. I realize that Class[Args] is allowed in that area in general and isn't always type annotation related,
    but does this mean that even with PEP 649 that forward references will
    still be needed?


    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Inada Naoki@21:1/5 to All on Sat Jul 1 15:20:18 2023
    but does this mean that even with PEP 649 that forward references will
    still be needed?

    Yes. Both of PEP 563 and PEP 649 solves not all forward reference issues.

    --
    Inada Naoki <songofacandy@gmail.com>

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)