-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TypeVar objects not documenting as expected #9980
Comments
In PEP-484, the argument of TypeVar has been described as below:
So I think |
@tk0miya but even if I create a type var like |
Sorry, I'm not sure what you'd like to do. What is the expected type of argument? If you'd like to take |
I have a few modules that use Pandas syntax, but can also be used with Koalas. However, I don't want to import Pandas or Koalas as I have separate install requirements for Koalas and would like the user to be able to install either the Pandas-ready or Koalas-ready version. The module works fine without the imports, but to use type hints that directly reference Pandas/Koalas, I'd have to import them, which why I'm trying to use TypeVars instead. Hopefully I've made that relatively clear! |
IMO, your usecase of TypeVar is wrong. It is not an alias of class. It's mainly used to represent a generic class. See https://docs.python.org/3/library/typing.html#user-defined-generic-types For that purpose, please use |
I'll try this out, thanks! |
Describe the bug
I'm wanting to document some modules in a package I'm developing. Throughout the modules I've imported some TypeVar objects from a module within the package - these objects refer to different types of data objects. I've done this mainly so that I can use Pandas and Koalas dataframes within a given module without having to import Pandas/Koalas just for the type hints.
When I run sphinx to document the modules, I expect the value assigned to the TypeVar object to be displayed. However, I get the module where the TypeVar object is stored, plus the value assigned to the TypeVar object.
How to Reproduce
Let's say I have the following package structure:
I keep my TypeVar objects in
typevar_objects.py
:Then in my module
example_module.py
, I import the TypeVar object as shown:Using the following settings in
conf.py
:I run sphinx on the package using the commands:
rm -r doc sphinx-apidoc -F -M -d 1 --separate -o doc example_package cp conf.py doc cd doc make clean make html
Expected behavior
I would expect the documentation for
A.some_func
to showdf: pandas.core.frame.DataFrame
. However, it instead showsdf: example_package.typevar_objects.pandas.core.frame.DataFrame
:Your project
https://drive.google.com/file/d/1ncM_aEovRiqsJGOVJyBRUbJgDMzJIPF9/view?usp=sharing
Screenshots
No response
OS
Mac
Python version
3.8.9
Sphinx version
4.3.1
Sphinx extensions
sphinx.ext.autodoc, sphinx.ext.viewcode, sphinx.ext.todo, sphinx.ext.imgmath, sphinx.ext.autosummary
Extra tools
No response
Additional context
No response
The text was updated successfully, but these errors were encountered: