Skip to main content

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()
()

Testing

python -m doctest is my test suite. Coverage is 100%.

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

nobeartype-0.1.0.tar.gz (4.3 kB view details)

Uploaded Source

Built Distribution

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

nobeartype-0.1.0-py3-none-any.whl (3.1 kB view details)

Uploaded Python 3

File details

Details for the file nobeartype-0.1.0.tar.gz.

File metadata

  • Download URL: nobeartype-0.1.0.tar.gz
  • Upload date:
  • Size: 4.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.3

File hashes

Hashes for nobeartype-0.1.0.tar.gz
Algorithm Hash digest
SHA256 3e1aa715c680a512b321b74ebb16cb2f653a4337f306baf3879b5faf5648461f
MD5 8ed0646b1792b20d3c8342b8b00f8166
BLAKE2b-256 2d0c58a8b932d40acad1e2338ff7460ab9cc16d0a75cbfdeca9bc299264c9dfc

See more details on using hashes here.

File details

Details for the file nobeartype-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for nobeartype-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 855c11aec10d00bd951081cbdc88e5f4574dcf12259c0cdc2ca78528cbef39e6
MD5 48381b22ef2adf458b08b7c0af23ff00
BLAKE2b-256 1c3194d241dd290dc39f83ec300030e5757b94f19384a65595f579ec523bba8b

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