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

bpo-43224: Draft implementation of PEP 646 #30398

Closed
wants to merge 18 commits into from
Closed

Commits on Jan 2, 2022

  1. Configuration menu
    Copy the full SHA
    64abc0a View commit details
    Browse the repository at this point in the history

Commits on Jan 3, 2022

  1. Configuration menu
    Copy the full SHA
    b725671 View commit details
    Browse the repository at this point in the history
  2. PEP 646: Add AST tests for *args annotations

    Formatted, the generated AST is as follows.
    
    `def f(*args: *Ts): pass`:
    
    ```
    (
        "Module",
        [
            (
                "FunctionDef",
                (1, 0, 1, 23),
                "f",
                (
                    "arguments",
                    [],
                    [],
                    (
                        "arg",
                        (1, 7, 1, 16),
                        "args",
                        (
                            "Starred",
                            (1, 13, 1, 16),
                            ("Name", (1, 14, 1, 16), "Ts", ("Load",)),
                            ("Load",),
                        ),
                        None,
                    ),
                    [],
                    [],
                    None,
                    [],
                ),
                [("Pass", (1, 19, 1, 23))],
                [],
                None,
                None,
            )
        ],
        [],
    )
    ```
    
    `def f(*args: *tuple[int, ...]): pass`:
    
    ```
    (
        "Module",
        [
            (
                "FunctionDef",
                (1, 0, 1, 36),
                "f",
                (
                    "arguments",
                    [],
                    [],
                    (
                        "arg",
                        (1, 7, 1, 29),
                        "args",
                        (
                            "Starred",
                            (1, 13, 1, 29),
                            (
                                "Subscript",
                                (1, 14, 1, 29),
                                ("Name", (1, 14, 1, 19), "tuple", ("Load",)),
                                (
                                    "Tuple",
                                    (1, 20, 1, 28),
                                    [
                                        ("Name", (1, 20, 1, 23), "int", ("Load",)),
                                        ("Constant", (1, 25, 1, 28), Ellipsis, None),
                                    ],
                                    ("Load",),
                                ),
                                ("Load",),
                            ),
                            ("Load",),
                        ),
                        None,
                    ),
                    [],
                    [],
                    None,
                    [],
                ),
                [("Pass", (1, 32, 1, 36))],
                [],
                None,
                None,
            )
        ],
        [],
    )
    ```
    
    `def f(*args: *tuple[int, *Ts]): pass`:
    
    ```
    (
        "Module",
        [
            (
                "FunctionDef",
                (1, 0, 1, 36),
                "f",
                (
                    "arguments",
                    [],
                    [],
                    (
                        "arg",
                        (1, 7, 1, 29),
                        "args",
                        (
                            "Starred",
                            (1, 13, 1, 29),
                            (
                                "Subscript",
                                (1, 14, 1, 29),
                                ("Name", (1, 14, 1, 19), "tuple", ("Load",)),
                                (
                                    "Tuple",
                                    (1, 20, 1, 28),
                                    [
                                        ("Name", (1, 20, 1, 23), "int", ("Load",)),
                                        (
                                            "Starred",
                                            (1, 25, 1, 28),
                                            ("Name", (1, 26, 1, 28), "Ts", ("Load",)),
                                            ("Load",),
                                        ),
                                    ],
                                    ("Load",),
                                ),
                                ("Load",),
                            ),
                            ("Load",),
                        ),
                        None,
                    ),
                    [],
                    [],
                    None,
                    [],
                ),
                [("Pass", (1, 32, 1, 36))],
                [],
                None,
                None,
            )
        ],
        [],
    )
    ```
    mrahtz committed Jan 3, 2022
    Configuration menu
    Copy the full SHA
    ea329b9 View commit details
    Browse the repository at this point in the history
  3. PEP 646: Add AST tests for return types with unpacking

    Formatted, generated AST is as follows.
    
    `def f() -> tuple[*Ts]: pass`:
    
    ```
    (
        "Module",
        [
            (
                "FunctionDef",
                (1, 0, 1, 27),
                "f",
                ("arguments", [], [], None, [], [], None, []),
                [("Pass", (1, 23, 1, 27))],
                [],
                (
                    "Subscript",
                    (1, 11, 1, 21),
                    ("Name", (1, 11, 1, 16), "tuple", ("Load",)),
                    (
                        "Tuple",
                        (1, 17, 1, 20),
                        [
                            (
                                "Starred",
                                (1, 17, 1, 20),
                                ("Name", (1, 18, 1, 20), "Ts", ("Load",)),
                                ("Load",),
                            )
                        ],
                        ("Load",),
                    ),
                    ("Load",),
                ),
                None,
            )
        ],
        [],
    )
    ```
    
    `def f() -> tuple[int, *Ts]: pass`:
    
    ```
    (
        "Module",
        [
            (
                "FunctionDef",
                (1, 0, 1, 32),
                "f",
                ("arguments", [], [], None, [], [], None, []),
                [("Pass", (1, 28, 1, 32))],
                [],
                (
                    "Subscript",
                    (1, 11, 1, 26),
                    ("Name", (1, 11, 1, 16), "tuple", ("Load",)),
                    (
                        "Tuple",
                        (1, 17, 1, 25),
                        [
                            ("Name", (1, 17, 1, 20), "int", ("Load",)),
                            (
                                "Starred",
                                (1, 22, 1, 25),
                                ("Name", (1, 23, 1, 25), "Ts", ("Load",)),
                                ("Load",),
                            ),
                        ],
                        ("Load",),
                    ),
                    ("Load",),
                ),
                None,
            )
        ],
        [],
    )
    ```
    
    `def f() -> tuple[int, *tuple[int, ...]]: pass`:
    
    ```
    (
        "Module",
        [
            (
                "FunctionDef",
                (1, 0, 1, 45),
                "f",
                ("arguments", [], [], None, [], [], None, []),
                [("Pass", (1, 41, 1, 45))],
                [],
                (
                    "Subscript",
                    (1, 11, 1, 39),
                    ("Name", (1, 11, 1, 16), "tuple", ("Load",)),
                    (
                        "Tuple",
                        (1, 17, 1, 38),
                        [
                            ("Name", (1, 17, 1, 20), "int", ("Load",)),
                            (
                                "Starred",
                                (1, 22, 1, 38),
                                (
                                    "Subscript",
                                    (1, 23, 1, 38),
                                    ("Name", (1, 23, 1, 28), "tuple", ("Load",)),
                                    (
                                        "Tuple",
                                        (1, 29, 1, 37),
                                        [
                                            ("Name", (1, 29, 1, 32), "int", ("Load",)),
                                            ("Constant", (1, 34, 1, 37), Ellipsis, None),
                                        ],
                                        ("Load",),
                                    ),
                                    ("Load",),
                                ),
                                ("Load",),
                            ),
                        ],
                        ("Load",),
                    ),
                    ("Load",),
                ),
                None,
            )
        ],
        [],
    )
    ```
    mrahtz committed Jan 3, 2022
    Configuration menu
    Copy the full SHA
    681dc4e View commit details
    Browse the repository at this point in the history
  4. PEP 646: Add AST tests for variable annotations with unpacking

    Formatted, generated AST is as follows:
    
    `x: tuple[*Ts]`:
    
    ```
    (
        "Module",
        [
            (
                "AnnAssign",
                (1, 0, 1, 13),
                ("Name", (1, 0, 1, 1), "x", ("Store",)),
                (
                    "Subscript",
                    (1, 3, 1, 13),
                    ("Name", (1, 3, 1, 8), "tuple", ("Load",)),
                    (
                        "Tuple",
                        (1, 9, 1, 12),
                        [
                            (
                                "Starred",
                                (1, 9, 1, 12),
                                ("Name", (1, 10, 1, 12), "Ts", ("Load",)),
                                ("Load",),
                            )
                        ],
                        ("Load",),
                    ),
                    ("Load",),
                ),
                None,
                1,
            )
        ],
        [],
    )
    ```
    
    `x: tuple[int, *Ts]`:
    
    ```
    (
        "Module",
        [
            (
                "AnnAssign",
                (1, 0, 1, 18),
                ("Name", (1, 0, 1, 1), "x", ("Store",)),
                (
                    "Subscript",
                    (1, 3, 1, 18),
                    ("Name", (1, 3, 1, 8), "tuple", ("Load",)),
                    (
                        "Tuple",
                        (1, 9, 1, 17),
                        [
                            ("Name", (1, 9, 1, 12), "int", ("Load",)),
                            (
                                "Starred",
                                (1, 14, 1, 17),
                                ("Name", (1, 15, 1, 17), "Ts", ("Load",)),
                                ("Load",),
                            ),
                        ],
                        ("Load",),
                    ),
                    ("Load",),
                ),
                None,
                1,
            )
        ],
        [],
    )
    ```
    
    `x: tuple[int, *tuple[str, ...]]`:
    
    ```
    (
        "Module",
        [
            (
                "AnnAssign",
                (1, 0, 1, 31),
                ("Name", (1, 0, 1, 1), "x", ("Store",)),
                (
                    "Subscript",
                    (1, 3, 1, 31),
                    ("Name", (1, 3, 1, 8), "tuple", ("Load",)),
                    (
                        "Tuple",
                        (1, 9, 1, 30),
                        [
                            ("Name", (1, 9, 1, 12), "int", ("Load",)),
                            (
                                "Starred",
                                (1, 14, 1, 30),
                                (
                                    "Subscript",
                                    (1, 15, 1, 30),
                                    ("Name", (1, 15, 1, 20), "tuple", ("Load",)),
                                    (
                                        "Tuple",
                                        (1, 21, 1, 29),
                                        [
                                            ("Name", (1, 21, 1, 24), "str", ("Load",)),
                                            ("Constant", (1, 26, 1, 29), Ellipsis, None),
                                        ],
                                        ("Load",),
                                    ),
                                    ("Load",),
                                ),
                                ("Load",),
                            ),
                        ],
                        ("Load",),
                    ),
                    ("Load",),
                ),
                None,
                1,
            )
        ],
        [],
    )
    ```
    mrahtz committed Jan 3, 2022
    Configuration menu
    Copy the full SHA
    69f575f View commit details
    Browse the repository at this point in the history
  5. PEP 646: Add support for starring tuple types

    E.g. tuple[*tuple[int, str]].
    mrahtz committed Jan 3, 2022
    Configuration menu
    Copy the full SHA
    095a620 View commit details
    Browse the repository at this point in the history
  6. Configuration menu
    Copy the full SHA
    6713748 View commit details
    Browse the repository at this point in the history
  7. Configuration menu
    Copy the full SHA
    038b8f0 View commit details
    Browse the repository at this point in the history
  8. Configuration menu
    Copy the full SHA
    f028339 View commit details
    Browse the repository at this point in the history

Commits on Jan 4, 2022

  1. PEP 646: Add tests for typing.get_{origin,args}

    and fix a couple of bugs the tests revealed
    mrahtz committed Jan 4, 2022
    Configuration menu
    Copy the full SHA
    38c17d3 View commit details
    Browse the repository at this point in the history

Commits on Jan 15, 2022

  1. PEP 646: Various fixes to genericaliasobject.c

    Based on Fidget-Spinner's feedback:
    1. Remove the explicit flag for 'exhausted', instead using 'gi->obj == NULL' to tell whether the iterator is exhausted.
    2. Construct `starred_tuple` using the `Py_GenericAlias` constructor instead of constructing it manually.
    3. Fix reference counting.
    4. Make `Py_GenericAliasIterType` static.
    mrahtz committed Jan 15, 2022
    Configuration menu
    Copy the full SHA
    9991937 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    9017d22 View commit details
    Browse the repository at this point in the history

Commits on Jan 17, 2022

  1. Configuration menu
    Copy the full SHA
    07ed599 View commit details
    Browse the repository at this point in the history

Commits on Jan 20, 2022

  1. Configuration menu
    Copy the full SHA
    74e5252 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    6cb3aa5 View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    daef59b View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    3c2a7e7 View commit details
    Browse the repository at this point in the history

Commits on Jan 25, 2022

  1. Configuration menu
    Copy the full SHA
    456156a View commit details
    Browse the repository at this point in the history