Skip to content

[Feature Request] Type Inference API: beartype.door.infer_hint() 🤯  #403

@leycec

Description

@leycec

Discussed in #402

Originally posted by Moosems June 30, 2024
I want to have beartype print out the proper type annotation for a variable because I can't seem to do it right myself. Example:

from beartype.typing import Callable
from pygments.lexers import PythonLexer
from pygments.lexer import RegexLexer
from pygments.token import _TokenType
lexer: RegexLexer = PythonLexer()
root_tokens: list[str] | list[tuple[str, _TokenType | Callable, str]] = (
    lexer.tokens["root"]
)
print(root_tokens)

Now try using beartype_this_package with that. I could just use type list and call it a day but that just feels wrong. The thing is this list can be different depending on what Lexer I use and theres so many possible subtle variations possible and I don't have the time to write that all out when the logic I use to deal with that list works anyway.

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