patrick-kidger / patrick-kidger/jaxtyping

Module-level import hook

Open
#127 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

question
Dominant language
Python
Stars
1.9k
Forks
96
PR merge metrics
No merged PRs in 30d

Description

Hi Patrick,

I would love to have a module-level import hook, similarly to the one implemented in beartype (discussed here, beartype.claw.beartype_this_package) that could be used just by calling a single function on top of __init__.py:

# __init__.py
from jaxtyping import module_wise_import_hook
module_wise_import_hook("beartype.beartype")

from .some_file import some_function # some_function gets typechecked
...

I would say that this is should be a really low priority feature, since I don't think it's that critical, even though it is convenient: I can simulate the same behaviour by doing something like:

# __init.py__
from jaxtyping import install_import_hook
with install_import_hook("module name", "beartype.beartype"):
    from .some_file import some_function

Besides, the implementation of this feature in a safe manner seems to be quite complex, judging by the fact that I was not able to force myself through reading all the source code of beartype implementation.

But, I think that having this written down is important: maybe at some point someone will have enough time to actually implement this. And, of course, there is always hope that you will propose a solution that would take only a single line of code.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the existing install_import_hook API and the beartype.claw.beartype_this_package implementation referenced in the issue. Determine how a module-level function could provide the requested init.py usage without the context manager. Done means the proposed hook works for imports within a package and has coverage for its intended behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.