Skip to content

Commit 143888b

Browse files
Add architecture guard for direct str/int type identity checks
Co-authored-by: Shri Sukhani <shrisukhani@users.noreply.github.com>
1 parent 7890baf commit 143888b

3 files changed

Lines changed: 24 additions & 0 deletions

File tree

CONTRIBUTING.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ This runs lint, format checks, compile checks, tests, and package build.
8888
- `tests/test_architecture_marker_usage.py` (architecture marker coverage across guard modules),
8989
- `tests/test_readme_examples_listing.py` (README example-listing consistency enforcement),
9090
- `tests/test_plain_type_guard_usage.py` (`str`/`int` guardrail enforcement via plain-type checks),
91+
- `tests/test_plain_type_identity_usage.py` (direct `type(... ) is str|int` guardrail enforcement via shared helpers),
9192
- `tests/test_type_utils_usage.py` (type `__mro__` boundary centralization in `hyperbrowser/type_utils.py`),
9293
- `tests/test_polling_loop_usage.py` (`while True` polling-loop centralization in `hyperbrowser/client/polling.py`),
9394
- `tests/test_core_type_helper_usage.py` (core transport/config/header/file/polling/session/error/parsing manager+tool module enforcement of shared plain-type helper usage),

tests/test_architecture_marker_usage.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"tests/test_pyproject_architecture_marker.py",
1818
"tests/test_architecture_marker_usage.py",
1919
"tests/test_plain_type_guard_usage.py",
20+
"tests/test_plain_type_identity_usage.py",
2021
"tests/test_type_utils_usage.py",
2122
"tests/test_polling_loop_usage.py",
2223
"tests/test_core_type_helper_usage.py",
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import re
2+
from pathlib import Path
3+
4+
import pytest
5+
6+
pytestmark = pytest.mark.architecture
7+
8+
9+
_PLAIN_TYPE_IDENTITY_PATTERN = re.compile(
10+
r"type\s*\([^)]*\)\s+is(?:\s+not)?\s+(?:str|int)\b"
11+
)
12+
13+
14+
def test_sdk_modules_avoid_direct_str_int_type_identity_checks():
15+
violations: list[str] = []
16+
for module_path in sorted(Path("hyperbrowser").rglob("*.py")):
17+
module_text = module_path.read_text(encoding="utf-8")
18+
for line_number, line_text in enumerate(module_text.splitlines(), start=1):
19+
if _PLAIN_TYPE_IDENTITY_PATTERN.search(line_text):
20+
violations.append(f"{module_path}:{line_number}")
21+
22+
assert violations == []

0 commit comments

Comments
 (0)