Skip to content

Commit c6604ed

Browse files
committed
Add strict-kwargs stress fixture
1 parent 2a3590d commit c6604ed

5 files changed

Lines changed: 124 additions & 0 deletions

File tree

strict_kwargs_stress/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""Stress fixture for strict-kwargs."""

strict_kwargs_stress/main.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
"""Call-site stress cases for strict-kwargs."""
2+
3+
from __future__ import annotations
4+
5+
import sys
6+
from collections.abc import Callable
7+
from typing import NewType, ParamSpec, TypeAliasType, TypeVar, TypeVarTuple
8+
9+
from strict_kwargs_stress.pkg.lib import (
10+
Data,
11+
Service,
12+
first_party_function,
13+
positional_only,
14+
)
15+
16+
_P = ParamSpec("_P")
17+
_T = TypeVar("_T")
18+
_Ts = TypeVarTuple("_Ts") # noqa: PYI018
19+
UserId = NewType("UserId", int)
20+
Vector = TypeAliasType("Vector", list[int]) # noqa: UP040
21+
_VECTOR_SAMPLE: Vector = []
22+
23+
24+
def _preserve_signature(func: Callable[_P, _T]) -> Callable[_P, _T]: # noqa: UP047
25+
"""Return the given callable with its ParamSpec signature
26+
preserved.
27+
"""
28+
return func
29+
30+
31+
@_preserve_signature
32+
def _sample(value: int) -> int:
33+
"""Return a sample value for exercising the ParamSpec helper."""
34+
return value
35+
36+
37+
def _accept_user_id(user_id: UserId) -> UserId:
38+
"""Return a sample ``NewType`` value."""
39+
return user_id
40+
41+
42+
_SAMPLE_RESULT = _sample(value=1)
43+
_USER_ID_VALUE = UserId(1) # type: ignore[misc]
44+
_USER_ID = _accept_user_id(user_id=_USER_ID_VALUE)
45+
46+
47+
type _Packed[*_Ts] = tuple[*_Ts] # noqa: PYI047
48+
49+
first_party_function(1, 2) # type: ignore[misc]
50+
first_party_function(a=1, b=2)
51+
positional_only(1)
52+
53+
Service("svc") # type: ignore[misc]
54+
Service(name="svc").method(3) # type: ignore[misc]
55+
service = Service(name="svc")
56+
service.method(7) # type: ignore[misc]
57+
Service.method(Service(name="svc"), item=4) # type: ignore[misc]
58+
Service.method(Service(name="svc"), 4) # type: ignore[misc]
59+
Service.class_method(5) # type: ignore[misc]
60+
Service.static_method(6) # type: ignore[misc]
61+
Data("name") # type: ignore[misc]
62+
63+
sys.stdout.write("ok\n")
64+
str.lower("ABC")
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""Stress-test package for strict-kwargs."""

strict_kwargs_stress/pkg/lib.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
"""Support callables for the strict-kwargs stress fixture."""
2+
3+
from __future__ import annotations
4+
5+
from dataclasses import dataclass
6+
7+
8+
def first_party_function(a: int, b: int = 0) -> int:
9+
"""Return the sum of two integers."""
10+
return a + b
11+
12+
13+
def positional_only(value: int, /) -> int:
14+
"""Return the positional-only value."""
15+
return value
16+
17+
18+
class Service:
19+
"""Service with representative method shapes."""
20+
21+
def __init__(self, name: str) -> None:
22+
"""Initialize the service."""
23+
self.name = name
24+
25+
def method(self, item: int) -> int:
26+
"""Return an instance-method item."""
27+
return item
28+
29+
@classmethod
30+
def class_method(cls, item: int) -> int:
31+
"""Return a class-method item."""
32+
return item
33+
34+
@staticmethod
35+
def static_method(item: int) -> int:
36+
"""Return a static-method item."""
37+
return item
38+
39+
40+
@dataclass
41+
class Data:
42+
"""Simple dataclass with a synthesized constructor."""
43+
44+
name: str
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[project]
2+
name = "strict-kwargs-stress"
3+
version = "0"
4+
classifiers = [
5+
"Programming Language :: Python :: 3 :: Only",
6+
"Programming Language :: Python :: 3.10",
7+
"Programming Language :: Python :: 3.11",
8+
"Programming Language :: Python :: 3.12",
9+
"Programming Language :: Python :: 3.13",
10+
"Programming Language :: Python :: 3.14",
11+
]
12+
13+
[tool.strict_kwargs]
14+
ignore_names = []

0 commit comments

Comments
 (0)