Annotated
=========
Annotated provides a decorator that flags a function's annotations as useful, callable expressions. Each annotation will be called with its corresponding argument as first parameter, and the result will replace that argument.
If no annotation was specified for this particular argument, it will behave as if `lambda x: x` had been used as annotation.
`@annotated` Decorator
----------------------
The `@annotated` decorator is meant to decorate functions, or other objects with a `__code__` attribute (a class is **not** one). It indicates that the function decorated has "active" annotations, for example:
```python
from annotated import annotated
@annotated
def hello(name: str):
print('Hello, ' + name + '!')
hello('world')
# "Hello, world!"
hello(None)
# "Hello, None!"
```
Albeit a bad example (one would rather use `str.format` or the `%` notation to include a value in a string), this illustrates the behaviour of an `@annotated` function.
Used this way, `@annotated` ensures that the `name` argument of the `hello` function is **always** a character string.
`@annotated` also respects default values, and applies annotations to them. Thus, if we were to rewrite `hello` such as:
```python
from annotated import annotated
@annotated
def hello(name: str='world'):
print('Hello, ' + name + '!')
hello()
# "Hello, world!"
```
The default value would be honored, as well as any non-defaults.
It should be noted that `@annotated` supports both return annotations (`->`), keyword argument annotations and `*`/`**` annotations.
Using `@annotated` on an incompatible (`__code__`-less) object will result in a `TypeError` exception.
=========
Annotated provides a decorator that flags a function's annotations as useful, callable expressions. Each annotation will be called with its corresponding argument as first parameter, and the result will replace that argument.
If no annotation was specified for this particular argument, it will behave as if `lambda x: x` had been used as annotation.
`@annotated` Decorator
----------------------
The `@annotated` decorator is meant to decorate functions, or other objects with a `__code__` attribute (a class is **not** one). It indicates that the function decorated has "active" annotations, for example:
```python
from annotated import annotated
@annotated
def hello(name: str):
print('Hello, ' + name + '!')
hello('world')
# "Hello, world!"
hello(None)
# "Hello, None!"
```
Albeit a bad example (one would rather use `str.format` or the `%` notation to include a value in a string), this illustrates the behaviour of an `@annotated` function.
Used this way, `@annotated` ensures that the `name` argument of the `hello` function is **always** a character string.
`@annotated` also respects default values, and applies annotations to them. Thus, if we were to rewrite `hello` such as:
```python
from annotated import annotated
@annotated
def hello(name: str='world'):
print('Hello, ' + name + '!')
hello()
# "Hello, world!"
```
The default value would be honored, as well as any non-defaults.
It should be noted that `@annotated` supports both return annotations (`->`), keyword argument annotations and `*`/`**` annotations.
Using `@annotated` on an incompatible (`__code__`-less) object will result in a `TypeError` exception.
Metadata
Release files for annotated 0.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| annotated-0.0.2.tar.gz | 3.0 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| annotated-0.0.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 8.0 kB
Release files / annotated-0.0.2.tar.gz
| Download URL | annotated-0.0.2.tar.gz |
|---|---|
| Size | 3.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a729257585dd88763a142405cb74fa0a9c5d0ff4f4d15ef376ed1cf86085a42d
|
|
BLAKE2b-256 checksum How to use checksums |
da5426a73f158fca65bc14be01b25358c183f2939223e9d46b55124363dacd7d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / annotated-0.0.2-py3-none-any.whl
| Download URL | annotated-0.0.2-py3-none-any.whl |
|---|---|
| Size | 5.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
14125fa5166d444da8d9f582014b00d9ae49eb00c459c0e42537105611ab8110
|
|
BLAKE2b-256 checksum How to use checksums |
3eefe985819b40d16ec4fb19dd45332b5154b2b5316df2a11910861388de29d6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for annotated 0.0.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.