|
| 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") |
0 commit comments