Skip to content

Commit 86f6853

Browse files
Add architecture guard against isinstance str/int checks
Co-authored-by: Shri Sukhani <shrisukhani@users.noreply.github.com>
1 parent cb3d3f9 commit 86f6853

3 files changed

Lines changed: 25 additions & 1 deletion

File tree

CONTRIBUTING.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ This runs lint, format checks, compile checks, tests, and package build.
8686
- `tests/test_makefile_quality_targets.py` (Makefile quality-gate target enforcement),
8787
- `tests/test_pyproject_architecture_marker.py` (pytest marker registration enforcement),
8888
- `tests/test_architecture_marker_usage.py` (architecture marker coverage across guard modules),
89-
- `tests/test_readme_examples_listing.py` (README example-listing consistency enforcement).
89+
- `tests/test_readme_examples_listing.py` (README example-listing consistency enforcement),
90+
- `tests/test_plain_type_guard_usage.py` (`str`/`int` guardrail enforcement via plain-type checks).
9091

9192
## Code quality conventions
9293

tests/test_architecture_marker_usage.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"tests/test_makefile_quality_targets.py",
1717
"tests/test_pyproject_architecture_marker.py",
1818
"tests/test_architecture_marker_usage.py",
19+
"tests/test_plain_type_guard_usage.py",
1920
)
2021

2122

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+
_ISINSTANCE_PLAIN_TYPE_PATTERN = re.compile(
10+
r"isinstance\s*\([^)]*,\s*(?:str|int)\s*\)"
11+
)
12+
13+
14+
def test_sdk_modules_avoid_isinstance_str_and_int_guards():
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 _ISINSTANCE_PLAIN_TYPE_PATTERN.search(line_text):
20+
violations.append(f"{module_path}:{line_number}")
21+
22+
assert violations == []

0 commit comments

Comments
 (0)