Skip to content

Invalid class description of set/frozenset in docs #114336

Closed as duplicate of#113746
Closed as duplicate of#113746
@skirpichev

Description

@skirpichev

The class sphinx directive is used (see it's docs), but wrongly:

.. class:: set([iterable])
frozenset([iterable])
Return a new set or frozenset object whose elements are taken from
*iterable*. The elements of a set must be :term:`hashable`. To
represent sets of sets, the inner sets must be :class:`frozenset`
objects. If *iterable* is not specified, a new empty set is
returned.

It looks (despite this seems to be not documented in sphinx-doc), that the second signature takes precedence and methods below could be referenced (either internally in CPython or with the intersphinx for external projects) only like frozenset.foo, which is especially silly in cases like frozenset.add.

We could mitigate this by reordering set and frozenset in the class directive (references to set's methods are more common), but this is not a real solution.

One option to solve the problem is using two class directives (like for list/tuple). BTW, while technically the set is not a subtype of the frozenset, in fact it just has some overloaded ops and a bunch of new methods...

Another option is a new sphinx directive like currentmodule: "Directive currentclass (similar to currentmodule) would help us." Originally posted by @serhiy-storchaka in #114280 (comment)

Finally, it could be viewed as a sphinx-only issue: the class directive must support references for every declared signature (i.e. both set.add and frozenset.add).

Metadata

Metadata

Assignees

No one assigned

    Labels

    docsDocumentation in the Doc dir

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions