Skip to content

Arguments ignored in substitution in typing.Callable #88956

Closed

Description

@serhiy-storchaka
BPO 44793
Nosy @gvanrossum, @serhiy-storchaka, @miss-islington, @Fidget-Spinner
PRs
  • bpo-44793: Fix checking the number of arguments when subscribe a gene… #27515
  • [3.10] bpo-44793: Fix checking the number of arguments when subscribe a generic type with ParamSpec parameter. (GH-27515) #27537
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2021-08-02.07:32:47.001>
    created_at = <Date 2021-07-31.12:24:26.513>
    labels = ['type-bug', 'library', '3.10', '3.11']
    title = 'Arguments ignored in substitution in typing.Callable'
    updated_at = <Date 2021-08-02.07:32:47.000>
    user = 'https://github.com/serhiy-storchaka'

    bugs.python.org fields:

    activity = <Date 2021-08-02.07:32:47.000>
    actor = 'serhiy.storchaka'
    assignee = 'none'
    closed = True
    closed_date = <Date 2021-08-02.07:32:47.001>
    closer = 'serhiy.storchaka'
    components = ['Library (Lib)']
    creation = <Date 2021-07-31.12:24:26.513>
    creator = 'serhiy.storchaka'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 44793
    keywords = ['patch']
    message_count = 5.0
    messages = ['398636', '398648', '398656', '398728', '398730']
    nosy_count = 4.0
    nosy_names = ['gvanrossum', 'serhiy.storchaka', 'miss-islington', 'kj']
    pr_nums = ['27515', '27537']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue44793'
    versions = ['Python 3.10', 'Python 3.11']

    Activity

    1. serhiy-storchaka commented on Jul 31, 2021

      @serhiy-storchaka
      MemberAuthor
      >>> import typing
      >>> T = typing.TypeVar('T')
      >>> P = typing.ParamSpec('P')
      >>> C = typing.Callable[P, T]
      >>> C[int, str, float]
      typing.Callable[[int], str]

      int substitutes P as [int], str substitutes T, and the third argument float is ignored.

    2. added
      3.11only security fixes
      stdlibStandard Library Python modules in the Lib/ directory
      type-bugAn unexpected behavior, bug, or error
      on Jul 31, 2021
    3. serhiy-storchaka commented on Jul 31, 2021

      @serhiy-storchaka
      MemberAuthor

      If Callable is nested, it works as expected:

      >>> typing.List[C][int, str, float]
      Traceback (most recent call last):
        File "<stdin>", line 1, in <module>
        File "/home/serhiy/py/cpython/Lib/typing.py", line 309, in inner
          return func(*args, **kwds)
                 ^^^^^^^^^^^^^^^^^^^
        File "/home/serhiy/py/cpython/Lib/typing.py", line 1028, in __getitem__
          _check_generic(self, params, len(self.__parameters__))
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/home/serhiy/py/cpython/Lib/typing.py", line 231, in _check_generic
          raise TypeError(f"Too {'many' if alen > elen else 'few'} parameters for {cls};"
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      TypeError: Too many parameters for typing.List[typing.Callable[~P, ~T]]; actual 3, expected 2

      collections.abc.Callable raises an error too.

    4. serhiy-storchaka commented on Jul 31, 2021

      @serhiy-storchaka
      MemberAuthor

      There is also similar bug in Generic:

      >>> from typing import *
      >>> T = TypeVar("T")
      >>> P = ParamSpec("P")
      >>> class X(Generic[T, P]):
      ...     f: Callable[P, int]
      ...     x: T
      ... 
      >>> P_2 = ParamSpec("P_2")
      >>> X[int, P_2, str]
      __main__.X[int, ~P_2]
    5. serhiy-storchaka commented on Aug 2, 2021

      @serhiy-storchaka
      MemberAuthor

      New changeset f92b913 by Serhiy Storchaka in branch 'main':
      bpo-44793: Fix checking the number of arguments when subscribe a generic type with ParamSpec parameter. (GH-27515)
      f92b913

    6. miss-islington commented on Aug 2, 2021

      @miss-islington
      Contributor

      New changeset c8db292 by Miss Islington (bot) in branch '3.10':
      bpo-44793: Fix checking the number of arguments when subscribe a generic type with ParamSpec parameter. (GH-27515)
      c8db292

    7. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      3.10 (EOL)end of life3.11only security fixesstdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions