Skip to content

Commit

Permalink
Fixed Concatenate raising TypeError in check_callable()
Browse files Browse the repository at this point in the history
Fixes #338.
  • Loading branch information
agronholm committed Apr 11, 2023
1 parent 7c7acff commit 6fca343
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion docs/features.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ The following type checks are not yet supported in Typeguard:
* Stubs defined with :func:`@overload <typing.overload>` (the implementation is checked
if instrumented)
* ``yield_from`` statements in generator functions
* ``ParamSpec`` is currently ignored
* ``ParamSpec`` and ``Concatenate`` are currently ignored

Other limitations
-----------------
Expand Down
2 changes: 2 additions & 0 deletions docs/versionhistory.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ This library adheres to `Semantic Versioning 2.0 <https://semver.org/#semantic-v
(``SomeType[...]``) being replaced with ``Any[...]`` instead of just ``Any``
- Fixed instrumentation inadvertently mutating a function's annotations on Python 3.7
and 3.8
- Fixed ``Concatenate[...]`` in ``Callable`` parameters causing ``TypeError`` to be
raised

**4.0.0rc3** (2023-04-10)

Expand Down
4 changes: 3 additions & 1 deletion src/typeguard/_checkers.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,9 @@ def check_callable(
return

argument_types = args[0]
if argument_types is not Ellipsis:
if isinstance(argument_types, list) and not any(
type(item) is ParamSpec for item in argument_types
):
# The callable must not have keyword-only arguments without defaults
unfulfilled_kwonlyargs = [
param.name
Expand Down
10 changes: 8 additions & 2 deletions tests/test_checkers.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@
from typing_extensions import LiteralString

if sys.version_info >= (3, 10):
from typing import TypeGuard
from typing import Concatenate, ParamSpec, TypeGuard
else:
from typing_extensions import TypeGuard
from typing_extensions import Concatenate, ParamSpec, TypeGuard

if sys.version_info >= (3, 9):
from typing import Annotated
Expand All @@ -78,6 +78,8 @@
else:
from typing_extensions import Literal, TypedDict

P = ParamSpec("P")


class TestAnyStr:
@pytest.mark.parametrize(
Expand Down Expand Up @@ -257,6 +259,10 @@ def test_builtin(self):
"""
check_type([].append, Callable[[int], Any])

def test_concatenate(self):
"""Test that ``Concatenate`` in the arglist is ignored."""
check_type([].append, Callable[Concatenate[object, P], Any])


class TestLiteral:
def test_literal_union(self):
Expand Down

0 comments on commit 6fca343

Please sign in to comment.