Skip to main content

Python is a not typed language, and runs under the paradigm of first try and then it success or fails. This package allows you to have the capability of apply typing features in last versions of Python, allowing to the developer to have a transparent mechanism to grant that typing annotations are satisfied in the execution time of their programs.

Project description

safetypes package

Python is a non typed language, and runs under the paradigm of first try and then it success or fails. This package allows you to have the capability of apply typing features in last versions of Python, allowing to the developer to have a transparent mechanism to grant that typing annotations are satisfied in the execution time of their programs.

To use this package you only need to add an annotation before a function or method definition:

@safe_types
def my_func(test: str) -> int:
    ...

With this simple line when you run your program the annotation checks:

  1. The test argument satisfies the condition to be a str.
  2. The return value satisfies the condition to be an int.

Also, you can use the Typing package to have multiple types for the same argument or to extend the detail of typing your code::

from typing import Union

@safe_types
def my_func(test: Union[int, float]) -> Union[int, float]:
    ...

With this definition, the annotation checks if test argument and return value are one of two possible types: int and float. Note that not necessarily needs to be the same type in both cases, due to the annotation could not correlate a direct causality between arguments and return types.

If you have optional arguments, like this one:

@safe_types
def my_func(test: str = 'empty') -> None:
    ...

my_func()

Then the test argument is ignored if it is not used when you call the function.

If you want to accept unknown arguments using *args or **kwargs then you can use the non-strict validation as follows:

@safe_types(strict=False)
def my_func(test: str, *args, **kwargs) -> None:
    ...

my_func('yeah!', 'more... yeah!!', yeah='Not enough!!!')

In this case, the argument test will be checked but other parameters passed as additional and unknown arguments will be ignored and not checked.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

safetypes-0.1rc2.post3.tar.gz (7.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

safetypes-0.1rc2.post3-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

Details for the file safetypes-0.1rc2.post3.tar.gz.

File metadata

  • Download URL: safetypes-0.1rc2.post3.tar.gz
  • Upload date:
  • Size: 7.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.8

File hashes

Hashes for safetypes-0.1rc2.post3.tar.gz
Algorithm Hash digest
SHA256 d1d03a53c0db67db0ffa0de79b1cf9bd193adac3ab81ad455f1aee11cfc8ee4a
MD5 ad3d5a0bccc5b3747b1d0320ac588fd1
BLAKE2b-256 5671d83b2faf3b5b919ae382853bd3551403130b50ab56a96d43e097794ccfbd

See more details on using hashes here.

File details

Details for the file safetypes-0.1rc2.post3-py3-none-any.whl.

File metadata

File hashes

Hashes for safetypes-0.1rc2.post3-py3-none-any.whl
Algorithm Hash digest
SHA256 0ee2f5d0dadf4b597ab229fb4aa7a2444180a0cfe239937cefd043189b3c49bd
MD5 49b0792bd5438aba699d67919da87763
BLAKE2b-256 61ac6c6031c5222dd53e7e1f19e2bf7d732e21886dfc241c38c116b97b90aab2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page