Skip to content

Optional callable raises TypeError #87131

Description

@ofek
mannequin
BPO 42965
Nosy @ofek, @Fidget-Spinner

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-01-19.14:48:11.240>
created_at = <Date 2021-01-19.08:11:26.387>
labels = ['type-bug', 'library', '3.9']
title = 'Optional callable raises TypeError'
updated_at = <Date 2021-01-19.14:48:11.239>
user = 'https://github.com/ofek'

bugs.python.org fields:

activity = <Date 2021-01-19.14:48:11.239>
actor = 'Ofekmeister'
assignee = 'none'
closed = True
closed_date = <Date 2021-01-19.14:48:11.240>
closer = 'Ofekmeister'
components = ['Library (Lib)']
creation = <Date 2021-01-19.08:11:26.387>
creator = 'Ofekmeister'
dependencies = []
files = []
hgrepos = []
issue_num = 42965
keywords = []
message_count = 4.0
messages = ['385246', '385247', '385262', '385264']
nosy_count = 2.0
nosy_names = ['Ofekmeister', 'kj']
pr_nums = []
priority = 'normal'
resolution = 'fixed'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue42965'
versions = ['Python 3.9']

Activity

  1. ofek commented on Jan 19, 2021

    ofekmannequin
    MannequinAuthor

    https://docs.python.org/3.9/library/typing.html#callable

    Python 3.9.1 (default, Jan 12 2021, 16:45:25)
    [GCC 8.3.0] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> from typing import Optional
    >>> from collections.abc import Callable
    >>>
    >>> Hasher = Optional[Callable[[bytes], bytes]]
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/usr/local/lib/python3.9/typing.py", line 262, in inner
        return func(*args, **kwds)
      File "/usr/local/lib/python3.9/typing.py", line 339, in __getitem__
        return self._getitem(self, parameters)
      File "/usr/local/lib/python3.9/typing.py", line 463, in Optional
        return Union[arg, type(None)]
      File "/usr/local/lib/python3.9/typing.py", line 262, in inner
        return func(*args, **kwds)
      File "/usr/local/lib/python3.9/typing.py", line 339, in __getitem__
        return self._getitem(self, parameters)
      File "/usr/local/lib/python3.9/typing.py", line 451, in Union
        parameters = _remove_dups_flatten(parameters)
      File "/usr/local/lib/python3.9/typing.py", line 231, in _remove_dups_flatten
        return tuple(_deduplicate(params))
      File "/usr/local/lib/python3.9/typing.py", line 205, in _deduplicate
        all_params = set(params)
    TypeError: unhashable type: 'list'
    >>>
    >>> from typing import Tuple
    >>> Hasher = Optional[Callable[Tuple[bytes], bytes]]
    >>>
    

    Tuple type for arguments makes it work

  2. added
    stdlibStandard Library Python modules in the Lib/ directory
    type-bugAn unexpected behavior, bug, or error
    on Jan 19, 2021
  3. ofek commented on Jan 19, 2021

    ofekmannequin
    MannequinAuthor

    I'm using the deprecated typing.Callable instead now and that works

  4. Fidget-Spinner commented on Jan 19, 2021

    @Fidget-Spinner
    Member

    Hello, this issue is a byproduct of bpo-42195. It has already been fixed on Python 3.10, and on Python 3.9.2 (which isn't out yet). You can see the what's new for it here https://docs.python.org/3/whatsnew/3.9.html#notable-changes-in-python-3-9-2.

    The expected release date for Python 3.9.2 is Monday, 2021-02-15 according to PEP-596 https://www.python.org/dev/peps/pep-0596/.

    For now, I guess you'll have to use the old typing.Callable, then update it in newer versions of Python.

    On Python 3.10a4:
    >>> from typing import Optional
    >>> from collections.abc import Callable
    >>> Optional[Callable[[bytes], bytes]]
    typing.Optional[collections.abc.Callable[[bytes], bytes]]
  5. ofek commented on Jan 19, 2021

    ofekmannequin
    MannequinAuthor

    Ah I see, thanks!

  6. transferred this issue fromon Apr 10, 2022
  7. herambnemlekar commented on Mar 25, 2024

    @herambnemlekar

    Callable

    Which deprecated version did you use for typing.Callable? I am facing the same issue with Python 3.9

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.9 (EOL)end of lifestdlibStandard 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