-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pre-commit hooks for pyright and mypy (only API tests) (#283)
* Added pre-commit hooks for pyright and mypy (only API tests) * Removed unnecessary noqa * Replaced tensorflow for numpy in type tests * Try tweaking pre-commit-config --------- Co-authored-by: Martí Zamora Casals <[email protected]> Co-authored-by: Patrick Kidger <[email protected]>
- Loading branch information
1 parent
c39abe7
commit 7d25a6b
Showing
3 changed files
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from dataclasses import dataclass | ||
|
||
import numpy as np | ||
from beartype import beartype | ||
|
||
from jaxtyping import Float, Int, jaxtyped | ||
|
||
|
||
@jaxtyped(typechecker=beartype) | ||
@dataclass | ||
class User: | ||
name: str | ||
age: int | ||
items: Float[np.ndarray, " N"] | ||
timestamps: Int[np.ndarray, " N"] | ||
|
||
|
||
@jaxtyped(typechecker=beartype) | ||
def transform_user(user: User, increment_age: int = 1) -> User: | ||
user.age += increment_age | ||
return user | ||
|
||
|
||
user = User( | ||
name="John", | ||
age=20, | ||
items=np.random.normal(size=10), | ||
timestamps=np.random.randint(0, 100, size=10), | ||
) | ||
|
||
new_user = transform_user(user, increment_age=2) |