Skip to content

io.BytesIO.read doesn't match typing.Callable[[int], bytes] #400

@andrew-ld

Description

@andrew-ld

Things to check first

  • I have searched the existing issues and didn't find my bug already reported there

  • I have checked that my bug is still present in the latest release

Typeguard version

4.1.2 (archlinux repo) and 4.1.4 (pip)

Python version

Python 3.11.5 (main, Aug 28 2023, 20:02:58) [GCC 13.2.1 20230801] on linux

What happened?

Traceback (most recent call last):
  File "/home/andrew/typeguard_bug.py", line 12, in <module>
    test_bug(b"")
  File "/home/andrew/typeguard_bug.py", line 8, in test_bug
    return io.BytesIO(buffer).read
  File "/usr/lib/python3.11/site-packages/typeguard/_functions.py", line 167, in check_return_type
    check_type_internal(retval, annotation, memo)
  File "/usr/lib/python3.11/site-packages/typeguard/_checkers.py", line 774, in check_type_internal
    checker(value, origin_type, args, memo)
  File "/usr/lib/python3.11/site-packages/typeguard/_checkers.py", line 197, in check_callable
    raise TypeCheckError(
typeguard.TypeCheckError: the return value (builtin_function_or_method) has too few arguments in its declaration; expected 1 but 0 argument(s) declared
andrew@arch ~ [1]> 

How can we reproduce the bug?

import io
import typeguard
import typing


@typeguard.typechecked
def test_bug(buffer: bytes) -> typing.Callable[[int], bytes]:
    return io.BytesIO(buffer).read


if __name__ == "__main__":
    test_bug(b"")

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions