sphinx icon indicating copy to clipboard operation
sphinx copied to clipboard

Autodoc: add ``:canonical:`` for all object types

Open flying-sheep opened this issue 4 years ago • 6 comments

Feature or Bugfix

  • Feature

Purpose

  • Creates a common superclass for all PyObject documenters
  • Moves the changes in #9026 to that superclass, so functions and methods get thir :canonical: as well

cc @tk0miya

  • Closes #5603

flying-sheep avatar Mar 27 '21 12:03 flying-sheep

OK, one test fails, how should we fix it?

It happens in a newer Python (e.g. 3.9), in case of a TypeVar that’s a class attribute.

__qualname__ is not set, so the code falls back to __name__, which is wrong.

grafik

flying-sheep avatar Mar 27 '21 12:03 flying-sheep

Could you let me know why do you add :canonical: options for everything? In my understanding, nobody refers the canonical functions, methods and others. I'd like to know the real usecase of this.

tk0miya avatar Apr 03 '21 07:04 tk0miya

Everything can be initially defined in one module and be exported in another, not just classes. As you can see in the test changes, it does happen!

Also I thought that one use case of this is that automatically generated reStructuredText code referring to f'{obj.__module__}.{obj.__qualname__}' works… Only inferring it for classes leaves it broken for functions and methods.

flying-sheep avatar Apr 03 '21 10:04 flying-sheep

Hi @tk0miya what do you think?

flying-sheep avatar Jul 14 '21 13:07 flying-sheep

@flying-sheep looks like this needs a rebase?

@tk0miya seems like this PR is awaiting your comment too...

webknjaz avatar Jan 04 '23 17:01 webknjaz

Hi @AA-Turner, I’d be happy if you bring this over the finish line (and that’d be probably faster), but if you want, I could also try fixing the tests.

flying-sheep avatar Oct 07 '24 09:10 flying-sheep

I'm happy with the implementation here but I haven't had time to fix the remaining tests or write any documentation -- would you have time to do so @flying-sheep? If so, I would like to get this in to v8.2.0.

A

AA-Turner avatar Jan 19 '25 23:01 AA-Turner

I’m checking it out. Questions:

  • 8158a1817df25e467ae211f4daa18d46e808617b is a pretty hacky way to fix builtins: that test was really wrong, now it works as expected, but do you want to keep this hack or is there a better way?
  • d691a85258ebdcd52b322b0cfa1ea83280d340b3 reverts a bunch of wrong :canonical: parameters you added in 142014eda7cee273944dae39e45e764657766ad0. Why did you add them? target.properties.Foo.prop1.fget.__qualname__ == "Foo.prop1" as expected!

flying-sheep avatar Jan 20 '25 08:01 flying-sheep

Why did you add them?

I was just mechanically trying to fix test output -- no other rationale.

A

AA-Turner avatar Jan 20 '25 16:01 AA-Turner