Skip to content

Commit

Permalink
Enforce positional-only parameters for: isassignable, eval_type_str
Browse files Browse the repository at this point in the history
References #18
  • Loading branch information
davidfstr committed Dec 23, 2023
1 parent 1128d15 commit 07f2be3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
5 changes: 4 additions & 1 deletion README.md
Expand Up @@ -406,7 +406,7 @@ Footnotes:
def isassignable(
value: object,
tp: TypeForm[T]† | TypeFormString[T]‡,
*, eval: bool = True
/, *, eval: bool = True
) -> TypeGuard[T]: ...
```

Expand Down Expand Up @@ -472,6 +472,9 @@ Raises:
* Enforce that calls to `trycast()` pass the first 2 arguments in
positional fashion like `trycast(T, value)` and not in a named fashion
like `trycast(tp=T, value=value)`. ([#18](https://github.com/davidfstr/trycast/issues/18))
* Enforce that calls to `isassignable()` pass the first 2 arguments in
positional fashion like `isassignable(value, T)` and not in a named fashion
like `isassignable(value=value, tp=T)`. **(Breaking change)**

### v1.1.0

Expand Down
12 changes: 6 additions & 6 deletions trycast.py
Expand Up @@ -880,26 +880,26 @@ def _is_simple_typevar(T: object, covariant: bool = False) -> bool:


@overload
def isassignable(value: object, tp: str, *, eval: Literal[False]) -> NoReturn:
def isassignable(value: object, tp: str, /, *, eval: Literal[False]) -> NoReturn:
... # pragma: no cover


@overload
def isassignable(value: object, tp: str, *, eval: bool = True) -> bool:
def isassignable(value: object, tp: str, /, *, eval: bool = True) -> bool:
... # pragma: no cover


@overload
def isassignable(value: object, tp: Type[_T], *, eval: bool = True) -> TypeGuard[_T]: # type: ignore[invalid-annotation] # pytype
def isassignable(value: object, tp: Type[_T], /, *, eval: bool = True) -> TypeGuard[_T]: # type: ignore[invalid-annotation] # pytype
... # pragma: no cover


@overload
def isassignable(value: object, tp: object, *, eval: bool = True) -> bool:
def isassignable(value: object, tp: object, /, *, eval: bool = True) -> bool:
... # pragma: no cover


def isassignable(value, tp, *, eval=True):
def isassignable(value, tp, /, *, eval=True):
"""
Returns whether `value` is in the shape of `tp`
(as accepted by a Python typechecker conforming to PEP 484 "Type Hints").
Expand Down Expand Up @@ -981,7 +981,7 @@ def isassignable(value, tp, *, eval=True):


@functools.lru_cache()
def eval_type_str(tp: str) -> object:
def eval_type_str(tp: str, /) -> object:
"""
Resolves a string-reference to a type that can be imported,
such as `'typing.List'`.
Expand Down

0 comments on commit 07f2be3

Please sign in to comment.