forked from agronholm/typeguard
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit a570ce3
Showing
10 changed files
with
870 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[run] | ||
source = typeguard | ||
|
||
[report] | ||
show_missing = true |
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,13 @@ | ||
.project | ||
.pydevproject | ||
.idea | ||
.tox | ||
.coverage | ||
.cache | ||
.eggs/ | ||
*.egg-info/ | ||
*.pyc | ||
__pycache__/ | ||
docs/_build/ | ||
dist/ | ||
build/ |
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,15 @@ | ||
sudo: false | ||
|
||
language: python | ||
|
||
python: | ||
- "pypy3" | ||
- "3.3" | ||
- "3.4" | ||
- "3.5" | ||
|
||
install: pip install tox-travis coveralls | ||
|
||
script: tox | ||
|
||
after_success: coveralls |
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,19 @@ | ||
This is the MIT license: http://www.opensource.org/licenses/mit-license.php | ||
|
||
Copyright (c) Alex Grönholm | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of this | ||
software and associated documentation files (the "Software"), to deal in the Software | ||
without restriction, including without limitation the rights to use, copy, modify, merge, | ||
publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons | ||
to whom the Software is furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all copies or | ||
substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, | ||
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR | ||
PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE | ||
FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR | ||
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
DEALINGS IN THE SOFTWARE. |
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,82 @@ | ||
.. image:: https://travis-ci.org/agronholm/typeguard.svg?branch=master | ||
:target: https://travis-ci.org/agronholm/typeguard | ||
:alt: Build Status | ||
.. image:: https://coveralls.io/repos/agronholm/typeguard/badge.svg?branch=master&service=github | ||
:target: https://coveralls.io/github/agronholm/typeguard?branch=master | ||
:alt: Code Coverage | ||
.. image:: https://codeclimate.com/github/agronholm/typeguard/badges/gpa.svg | ||
:target: https://codeclimate.com/github/agronholm/typeguard | ||
:alt: Code Climate | ||
|
||
This library provides run-time type checking for functions defined with argument type annotations. | ||
|
||
The ``typing`` module introduced in Python 3.5 (and available on PyPI for older versions of | ||
Python 3) is supported. See below for details. | ||
|
||
There are two principal ways to use type checking, each with its pros and cons: | ||
|
||
#. calling ``check_type_arguments()`` from within the function body: | ||
debugger friendly but cannot check the type of the return value | ||
#. decorating the function with ``@typechecked``: | ||
can check the type of the return value but adds an extra frame to the call stack for every call | ||
to a decorated function | ||
|
||
If a function is called with incompatible argument types or a ``@typechecked`` decorated function | ||
returns a value incompatible with the declared type, a descriptive ``TypeError`` exception is | ||
raised. | ||
|
||
Type checks can be fairly expensive so it is recommended to run Python in "optimized" mode | ||
(``python -O`` or setting the ``PYTHONOPTIMIZE`` environment variable) when running code containing | ||
type checks in production. The optimized mode will disable the type checks, by virtue of removing | ||
all ``assert`` statements and setting the ``__debug__`` constant to ``False``. | ||
|
||
Using ``check_type_arguments()``: | ||
|
||
.. code-block:: python | ||
from typeguard import check_argument_types | ||
def some_function(a: int, b: float, c: str, *args: str): | ||
assert check_argument_types(some_function) | ||
... | ||
Using ``@typechecked``: | ||
|
||
.. code-block:: python | ||
from typeguard import typechecked | ||
@typechecked | ||
def some_function(a: int, b: float, c: str, *args: str) -> bool: | ||
... | ||
To enable type checks even in optimized mode: | ||
|
||
.. code-block:: python | ||
@typechecked(always=True) | ||
def foo(a: str, b: int, c: Union[str, int]) -> bool: | ||
... | ||
The following types from the ``typing`` package have specialized support: | ||
|
||
============ ============================================================ | ||
Type Notes | ||
============ ============================================================ | ||
``Dict`` Keys and values are typechecked | ||
``List`` Contents are typechecked | ||
``Set`` Contents are typechecked | ||
``Tuple`` Contents are typechecked | ||
``Callable`` Argument count is checked but types are not (yet) | ||
``TypeVar`` Constraints, bound types and co/contravariance are supported | ||
but custom generic types are not (due to type erasure) | ||
``Union`` | ||
============ ============================================================ | ||
|
||
|
||
Project links | ||
------------- | ||
|
||
* `Source repository <https://github.com/agronholm/typeguard>`_ | ||
* `Issue tracker <https://github.com/agronholm/typeguard/issues>`_ |
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,6 @@ | ||
[flake8] | ||
max-line-length = 99 | ||
|
||
[pytest] | ||
addopts = -rsx --tb=short --cov | ||
testpaths = tests |
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,41 @@ | ||
import os.path | ||
|
||
from setuptools import setup | ||
|
||
here = os.path.dirname(__file__) | ||
readme_path = os.path.join(here, 'README.rst') | ||
readme = open(readme_path).read() | ||
|
||
setup( | ||
name='typeguard', | ||
use_scm_version={ | ||
'local_scheme': 'dirty-tag' | ||
}, | ||
description='Run-time type checker for Python', | ||
long_description=readme, | ||
author='Alex Grönholm', | ||
author_email='alex.gronholm@nextday.fi', | ||
url='https://github.com/agronholm/typeguard', | ||
classifiers=[ | ||
'Development Status :: 5 - Production/Stable', | ||
'Intended Audience :: Developers', | ||
'License :: OSI Approved :: MIT License', | ||
'Programming Language :: Python', | ||
'Programming Language :: Python :: 3', | ||
'Programming Language :: Python :: 3.2', | ||
'Programming Language :: Python :: 3.3', | ||
'Programming Language :: Python :: 3.4', | ||
'Programming Language :: Python :: 3.5' | ||
], | ||
license='MIT', | ||
zip_safe=True, | ||
py_modules=['typeguard'], | ||
setup_requires=[ | ||
'setuptools_scm >= 1.7.0' | ||
], | ||
extras_require={ | ||
':python_version == "3.2"': 'typing >= 3.5', | ||
':python_version == "3.3"': 'typing >= 3.5', | ||
':python_version == "3.4"': 'typing >= 3.5' | ||
} | ||
) |
Oops, something went wrong.