Bear proof your functions. It's basic stuff.
Project description
nobeartype
Disable beartype's runtime type checking for a specific function, protecting it in case global runtime checking is on. This is needed if your functions expose return types from external libraries like flask which beartype can't inspect.
IMHO, when using beartype it's best to enable it on a per-function basis or after import in your testing suite: beartype_package('foo')
You could use beartype_this_package() in foo.__init__.py. That's pretty hardcore, though.
>>> from beartype import beartype
>>> nobeartype = NoBearType()
>>> # Contrived - @beartype would be applied at the import hook level
>>> @beartype
... @nobeartype
... def my_bad_func() -> int:
... '''Really bad stuff'''
... return "Foo" # no type error
>>> my_bad_func()
'Foo'
>>> my_bad_func.__doc__ # still wrapped
'Really bad stuff'
>>> @beartype
... def my_bad_func_unprotected() -> int:
... return "Foo" # type error
>>> my_bad_func_unprotected()
Traceback (most recent call last):
...
beartype.roar.BeartypeCallHintReturnViolation: Function ... return 'Foo' violates type hint <class 'int'>, as str 'Foo' not instance of int.
>>> NoBearType.registry() # doctest: +ELLIPSIS
{<function my_bad_func at 0x...>}
>>> assert len(nobeartype) == 1
>>> NoBearType.clear() # doctest: +ELLIPSIS
>>> assert len(nobeartype) == 0
>>> nobeartype.registry()
set()
Testing
python -m doctest is my test suite. Coverage is 100%.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file nobeartype-0.1.1.tar.gz.
File metadata
- Download URL: nobeartype-0.1.1.tar.gz
- Upload date:
- Size: 14.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2b166892bcf905a9b5c46160ed0416efd777cf5d292ef88114dfbe115b523863
|
|
| MD5 |
55c654b63cd0aa8517abc2127f92df47
|
|
| BLAKE2b-256 |
66e15a2e6ef5cac8ebcc058f7ec5d4f72fbff23a1a853ffa49c8de13cccc0320
|
File details
Details for the file nobeartype-0.1.1-py3-none-any.whl.
File metadata
- Download URL: nobeartype-0.1.1-py3-none-any.whl
- Upload date:
- Size: 3.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
047b44d6ce67ef74972cc655e5a136eb325c93af966ba7e62a764ba5240f2319
|
|
| MD5 |
64b842e6de2ce59774ffcec1d127a612
|
|
| BLAKE2b-256 |
ba52cccc0f83ba1841c76819b728897393105bea753c1537960c7d24a3374de1
|