Skip to content

[Feature request] Automagical Import Hook #43

@leycec

Description

@leycec

@zeevox of SentiPy and Sentiment Investor fame kindly requested automation to automagically decorate all callables in a given package with @beartype without needing to explicitly do so:

Is it necessary to annotate each function with @beartype? Is there a way of more concisely adding beartype everywhere automagically?

This feature request tracks our eventual (hopefully not too eventual) solution: a beartype import hook. Specifically:

  • We need to implement a new AST-based beartype.hook.beartype_everything() import hook inspired by typeguard's comparable typeguard.importhook.install_import_hook() function. That's only 162 lines of pure Python, which means this is mostly trivial, but it's a dense 162 lines, which means this might take an undefinable quantum of space-time.
  • Interested third parties will then call our import hook at the top of their top-level __init__ submodules to globally and transparently apply @beartype across their entire codebases.

Grab that popcorn! @leycec's Wild Ride is now boarding for an improved @beartype user experience (UX).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions