Skip to content

varname doesn't play well with type annotations #31

@jaycunningham-8451

Description

@jaycunningham-8451

Thanks for making this available -- it's a very clever package.

I've noticed that varname doesn't play well with type annotations. Minimal code to reproduce an error:

from varname import varname

class Foo:
    def __init__(self):
        self.id = varname()

foo: Foo = Foo()
# => varname.VarnameRetrievingError: Failed to retrieve the variable name.

It also doesn't like Generic[T]:

from typing import Generic, TypeVar

T = TypeVar("T")

class Foo(Generic[T]):
    def __init__(self):
        self.id = varname()

foo = Foo[int]()
foo.id  # => 'result'

Are there any plans to support this better? I plead ignorance as to the complexity, admittedly, but it would be helpful for my use case.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions