Skip to content

Restored CollectionCheckStrategy.ALL_ITEMS as the default policy #516

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions docs/versionhistory.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ Version history
This library adheres to
`Semantic Versioning 2.0 <https://semver.org/#semantic-versioning-200>`_.

**UNRELEASED**

- **BACKWARD INCOMPATIBLE** Due to numerous bug reports, collection checks once again
default to checking all elements rather than just the first one. Set
``typeguard.config.collection_check_strategy`` to
``typeguard.CollectionCheckStrategy.FIRST_ITEM`` to restore the previous behavior.

**4.4.2** (2025-02-16)

- Fixed ``TypeCheckError`` in unpacking assignment involving properties of a parameter
Expand Down
4 changes: 2 additions & 2 deletions src/typeguard/_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class TypeCheckConfiguration:
Specifies how thoroughly the contents of collections (list, dict, etc.) are
type checked.

Default: ``FIRST_ITEM``
Default: ``ALL_ITEMS``

.. attribute:: debug_instrumentation
:type: bool
Expand All @@ -98,7 +98,7 @@ class TypeCheckConfiguration:
forward_ref_policy: ForwardRefPolicy = ForwardRefPolicy.WARN
typecheck_fail_callback: TypeCheckFailCallback | None = None
collection_check_strategy: CollectionCheckStrategy = (
CollectionCheckStrategy.FIRST_ITEM
CollectionCheckStrategy.ALL_ITEMS
)
debug_instrumentation: bool = False

Expand Down
13 changes: 10 additions & 3 deletions tests/test_checkers.py
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,11 @@ def test_bad_type(self):
)

def test_first_check_success(self):
check_type(["aa", "bb", 1], List[str])
check_type(
["aa", "bb", 1],
List[str],
collection_check_strategy=CollectionCheckStrategy.FIRST_ITEM,
)

def test_first_check_empty(self):
check_type([], List[str])
Expand Down Expand Up @@ -582,7 +586,11 @@ def test_bad_type(self):
[pytest.param([1, "bb"], id="list"), pytest.param((1, "bb"), id="tuple")],
)
def test_first_check_success(self, value):
check_type(value, Sequence[int])
check_type(
value,
Sequence[int],
collection_check_strategy=CollectionCheckStrategy.FIRST_ITEM,
)

def test_first_check_empty(self):
check_type([], Sequence[int])
Expand All @@ -598,7 +606,6 @@ def test_full_check_fail(self):
check_type,
[1, 2, "bb"],
Sequence[int],
collection_check_strategy=CollectionCheckStrategy.ALL_ITEMS,
).match("list is not an instance of int")


Expand Down