Skip to content

Explore adding an ignore decorator to ignore the intermediate calls for varname #33

@pwwang

Description

@pwwang

I assume you mean allowing both Foo() and Foo[int]() which would require different values for caller. I think this is a good example of how trying to specify a value for caller is often difficult or impossible. An alternative strategy is to mark certain functions as functions that varname should 'ignore', as in "I never want the varname from here". So you might write something like:

import typing
import varname

varname.ignore(typing._GenericAlias.__call__)

And then when varname is looking for the caller, it skips frames with the code object from there.

This gets more complicated when the function has been decorated and you don't have easy access to the original. In that case one possibility is to pass the qualified function name as a string, maybe something like:

import typing
import varname

varname.ignore(typing, "_GenericAlias.__call__")

executing can usually get the qualified name from a code object, although now of course many caveats apply like source code being available and the function name being unique.

Originally posted by @alexmojaki in #31 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions