
Security News
Vite Releases Technical Preview of Rolldown-Vite, a Rust-Based Bundler
Vite releases Rolldown-Vite, a Rust-based bundler preview offering faster builds and lower memory usage as a drop-in replacement for Vite.
Extend typehints to include dynamic checks (that might otherwise be dealt with by assertions) in Python.
For more info, please visit the GitHub page of this project.
import parameter_checks as pc
@pc.hints.cleanup # be left with only type-annotations
@pc.hints.enforce # enforce the lambda but not the types
def div(a: int, b: pc.annotations.Checks[int, lambda b: b != 0]):
return a / b
div(1, 1) # returns 1.0
div(1, 0) # raises ValueError
As can be seen in this example, this package provides a new type-annotation:
pc.annotations.Checks
(it also provides pc.annotations.Hooks, see below).
Using @pc.hints.enforce on a function
will enforce the checks given to those annotations (but not the types).
@pc.hints.cleanup would produce the
div.__annotations__
of {"a": int, "b": int}
in the example above.
import parameter_checks as pc
def decision_boundary(fct, parameter, parameter_name, typehint):
if type(parameter) is not typehint:
err_str = f"In function {fct}, parameter {parameter_name}={parameter} " \
f"is not of type {typehint}!"
raise TypeError(err_str)
return 3 + 4 * parameter - parameter ** 2
@pc.hints.enforce
def classify(
x: pc.annotations.Hooks[float, decision_boundary],
additional_offset: pc.annotations.Checks[float, lambda b: 0 <= b <= 100] = 0.
) -> bool:
return (x + additional_offset) >= 0
if __name__ == '__main__':
assert classify(1.) is True # 6.
assert classify(2.) is True # 7.
assert classify(5.) is False # -2.
assert classify(5., 2.) is True # 0.
classify("not a float!") # raises TypeError
classify(1., -1.) # raises ValueError
For additional comments on this example (and much more), visit the GitHub page of this project.
FAQs
Extend typehints to include dynamic checks (that might otherwise be dealt with by assertions) in Python.
We found that parameter-checks demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Vite releases Rolldown-Vite, a Rust-based bundler preview offering faster builds and lower memory usage as a drop-in replacement for Vite.
Research
Security News
A malicious npm typosquat uses remote commands to silently delete entire project directories after a single mistyped install.
Research
Security News
Malicious PyPI package semantic-types steals Solana private keys via transitive dependency installs using monkey patching and blockchain exfiltration.