Skip to main content

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%.

Metadata

Release files for nobeartype 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for nobeartype 0.1.1
File Size Uploaded
nobeartype-0.1.1.tar.gz 14.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for nobeartype 0.1.1
File Interpreter ABI Platform
nobeartype-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 17.9 kB

Release files / nobeartype-0.1.1.tar.gz

Download URL nobeartype-0.1.1.tar.gz
Size 14.7 kB
Tags Source
SHA-256 checksum
How to use checksums
2b166892bcf905a9b5c46160ed0416efd777cf5d292ef88114dfbe115b523863
BLAKE2b-256 checksum
How to use checksums
66e15a2e6ef5cac8ebcc058f7ec5d4f72fbff23a1a853ffa49c8de13cccc0320
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.8.14

Release files / nobeartype-0.1.1-py3-none-any.whl

Download URL nobeartype-0.1.1-py3-none-any.whl
Size 3.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
047b44d6ce67ef74972cc655e5a136eb325c93af966ba7e62a764ba5240f2319
BLAKE2b-256 checksum
How to use checksums
ba52cccc0f83ba1841c76819b728897393105bea753c1537960c7d24a3374de1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.8.14

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page