Skip to content

how to get 'module' of TypeVar ? #754

Closed

Description

@devdoomari3

Hello!

I'm currently working on py_type_extractor for getting TypeNode-ASTs at runtime (it's a py3.6+ compat-layer for codegens / runtime-type-validations / etc)

While working on the project, I couldn't get the module (or module name) of TypeVars, unlike classses/functions/etc.

Is there simply no way to get 'module' of TypeVars?

here's some code-examples to show what I'm hoping to extract from TypeVars:

  1. Source file
# --------  {proj_root}/packageA/packageB/some_file.py file  --------

from typing import TypeVar, Generic

SomeTypeVarA = TypeVar('SomeTypeVarA')
...
  1. Extractor
# --------  extract_typevar.py  --------
from packageA.packageB.some_file import (
    SomeTypeVarA
)

# how to access module (or module name) of SomeTypeVarA ?
SomeTypeVarA.__module__  # points to some python-typing internals 😭 

# what I'm hoping to get:
get_module_from_typevar(SomeTypeVarA) == 'packageA.packageB.some_file'

Thank you!

Activity

  1. gvanrossum commented on Sep 18, 2020

    @gvanrossum
    Member

    Sorry, there is no way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to 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