Skip to content

Commit

Permalink
perf: Optimize len(schema)
Browse files Browse the repository at this point in the history
Signed-off-by: Dmitry Dygalo <dmitry@dygalo.dev>
  • Loading branch information
Stranger6667 committed May 16, 2024
1 parent 9137858 commit 3b0043c
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ Changelog

**Performance**

- Optimize `get_operation_by_id` method performance and reduce memory usage.
- Optimize `get_operation_by_reference` method performance.
- Optimize ``get_operation_by_id`` method performance and reduce memory usage.
- Optimize ``get_operation_by_reference`` method performance.
- Less copying during schema traversal.

.. _v3.28.1:
Expand Down
4 changes: 2 additions & 2 deletions src/schemathesis/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def on_missing_operation(self, item: str, exc: KeyError) -> NoReturn:
raise NotImplementedError

def __len__(self) -> int:
return len(self.operations)
return self.operations_count

def hook(self, hook: str | Callable) -> Callable:
return self.hooks.register(hook)
Expand Down Expand Up @@ -446,7 +446,7 @@ def as_strategy(
**kwargs: Any,
) -> SearchStrategy:
"""Build a strategy for generating test cases for all defined API operations."""
assert len(self.operations) > 0, "No API operations found"
assert len(self) > 0, "No API operations found"
strategies = [
operation.as_strategy(
hooks=hooks,
Expand Down
2 changes: 1 addition & 1 deletion test/test_recoverable_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def test_in_cli(testdir, cli, open_api_3_schema_with_recoverable_errors, workers

def test_direct_access(schema):
# Then valid operations should be accessible via the mapping interface
assert len(schema) == 1
assert len(schema) == 2
assert schema["/bar"]["GET"]


Expand Down

0 comments on commit 3b0043c

Please sign in to comment.