Skip to content
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

Incorrect base class detection #9607

Closed
adamjstewart opened this issue Sep 3, 2021 · 2 comments
Closed

Incorrect base class detection #9607

adamjstewart opened this issue Sep 3, 2021 · 2 comments

Comments

@adamjstewart
Copy link
Contributor

Describe the bug

I have a chain of subclasses, like A -> B -> C -> D. When I document class D, it lists the base class as A instead of C.

How to Reproduce

$ git clone https://github.com/microsoft/torchgeo.git
$ cd torchgeo/docs
$ pip install -r requirements.txt
$ make html
$ # open _build/html/api/datasets.html and see that the base class is torch.utils.data.Dataset instead of RasterDataset

Expected behavior

I would expect the base class to be the direct super class.

Your project

https://github.com/microsoft/torchgeo

Screenshots

No response

OS

macOS 10.15.7, Linux (whatever RtD uses)

Python version

3.8.11

Sphinx version

4.0.1, 4.0.2

Sphinx extensions

sphinx.ext.autodoc

Extra tools

No response

Additional context

I don't think this is the same as #9504 because I can reproduce it with 4.0.1 too.

Could be related to #9395.

For a class like Landsat, even though the super class is RasterDataset, the base class is listed as torch.utils.data.Dataset.

@calebrob6

@tk0miya
Copy link
Member

tk0miya commented Sep 19, 2021

It seems Landsat.__orig_bases__ is incorrect. It should be (RasterDataset, abc.ABC). But it returns (Dataset, abc.ABC) instead. It must be a bug of Python interpreter.

$ python
Python 3.8.12 (default, Sep  3 2021, 02:24:44)
[GCC 10.2.1 20210110] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from torchgeo.datasets import Landsat
>>> Landsat.__mro__
(<class 'torchgeo.datasets.Landsat'>, <class 'torchgeo.datasets.RasterDataset'>, <class 'torchgeo.datasets.GeoDataset'>, <class 'torch.utils.data.Dataset'>, <class 'typing.Generic'>, <class 'abc.ABC'>, <class 'object'>)
>>> Landsat.__orig_bases__
(torch.utils.data.Dataset[typing.Dict[str, typing.Any]], <class 'abc.ABC'>)

I got the same result with 3.9.7.

$ python
Python 3.9.7 (default, Sep  3 2021, 02:02:37)
[GCC 10.2.1 20210110] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from torchgeo.datasets import Landsat
>>> Landsat.__mro__
(<class 'torchgeo.datasets.Landsat'>, <class 'torchgeo.datasets.RasterDataset'>, <class 'torchgeo.datasets.GeoDataset'>, <class 'torch.utils.data.Dataset'>, <class 'typing.Generic'>, <class 'abc.ABC'>, <class 'object'>)
>>> Landsat.__orig_bases__
(torch.utils.data.Dataset[typing.Dict[str, typing.Any]], <class 'abc.ABC'>)

Note: This is a Dockefile for reproduce.

FROM python:3.8-slim

RUN apt update; apt install -y build-essential curl git make unzip vim
RUN git clone https://github.com/microsoft/torchgeo.git
WORKDIR /torchgeo/docs
RUN pip install -r requirements.txt
RUN make html

@tk0miya
Copy link
Member

tk0miya commented Sep 20, 2021

I found a workaround for Python's behavior (refs: #9654). It will be merged and fixed in 4.3.0.

tk0miya added a commit that referenced this issue Sep 26, 2021
Fix #9607: autodoc: Incorrect base class detection
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 27, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants