Skip to content

Subclasses of Polygon with numpydoc xref throws error b/c of CapStyle, JoinStyle #19839

Closed as not planned

Description

@nstarman

Problem

The sphinx links to CapStyle and JoinStyle in v3.4.0 are relative to the file, so a subclass of matplotlib.patches.Patch in a package with numpydoc xref (https://numpydoc.readthedocs.io/en/latest/install.html) turned on cannot link to the objects and errors with.
WARNING: py:obj reference target not found: CapStyle
WARNING: py:obj reference target not found: JoinStyle

https://matplotlib.org/stable/api/_as_gen/matplotlib.patches.Patch.html#matplotlib.patches.Patch.set_capstyle
https://matplotlib.org/stable/api/_as_gen/matplotlib.patches.Patch.html#matplotlib.patches.Patch.set_joinstyle

   @docstring.interpd
    def set_capstyle(self, s):
        """
        Set the `.CapStyle`.

        Parameters
        ----------
        s : `.CapStyle` or %(CapStyle)s
        """
        cs = CapStyle(s)
        self._capstyle = cs
        self.stale = True

Edit:

The problem also appears to involve Patches.__init__. I can monkey-patch a fix with

Polygon.__init__.__doc__ = Polygon.__init__.__doc__.replace(
    "`.CapStyle`", "``matplotlib._enums.CapStyle``")
Polygon.__init__.__doc__ = Polygon.__init__.__doc__.replace(
    "`.JoinStyle`", "``matplotlib._enums.JoinStyle``")
Polygon.set_capstyle.__doc__ = Polygon.set_capstyle.__doc__.replace(
    "`.CapStyle`", "``matplotlib._enums.CapStyle``")
Polygon.set_joinstyle.__doc__ = Polygon.set_joinstyle.__doc__.replace(
    "`.JoinStyle`", "``matplotlib._enums.JoinStyle``")

Suggested Improvement

  • This line could be be changed to say
   @docstring.interpd
    def set_capstyle(self, s):
        """
        Set the `~matplotlib._enums.CapStyle`.

        Parameters
        ----------
        s : `~matplotlib._enums.CapStyle` or %(CapStyle)s
        """
        cs = CapStyle(s)
        self._capstyle = cs
        self.stale = True

Matplotlib version

  • Operating system: Big Sur & Ubuntu
  • Matplotlib version 3.4.0
  • Matplotlib documentation version (is listed under the logo): 3.4.0

Activity

  1. changed the title [-]Subclasses Polygon with numpydoc xref throws error b/c of CapStyle, JoinStyle[/-] [+]Subclasses of Polygon with numpydoc xref throws error b/c of CapStyle, JoinStyle[/+] on Mar 31, 2021
  2. jklymak commented on Mar 31, 2021

    @jklymak
    Member

    Umm, how did we end up with private libraries linked in the public docs? That shouldn't have happened. https://matplotlib.org/stable/api/_enums_api.html#matplotlib._enums.CapStyle I think @brunobeltran and @timhoffm worked on this?

  3. timhoffm commented on Mar 31, 2021

    @timhoffm
    Member

    The use of private modules is a workaround. The classes themselves are not public, but the concepts they describe are. We need a location to document these concepts and the simplest solution is with the classes that represent these concepts. There are other ways to solve this as I've proposed in #18544, but that would require additional machinery and was not appreciated in that discussion.

    as for the xref thing, I do not fully understand where the warning is coming from and need to have a closer look.

  4. nstarman commented on Apr 1, 2021

    @nstarman
    Author

    As far as I can tell, the xref issue stems from the fact that references to CapStyle and JoinStyle are relative paths, not absolute. I've found for other references in Astropy that changing `.object` to `~package.subpackage.object` resolves the issue

  5. added a commit that references this issue on Apr 2, 2021
  6. added this to the v3.4.2 milestone on Apr 2, 2021
  7. pllim commented on Apr 3, 2021

    @pllim

    Circling back here... The patch suggested above did get around the ReadTheDocs "fail on warning" problem; see astropy/astropy#11466 though you still see those warnings in the log but they somehow not blocking RTD check. FYI 🤷

    And for completeness: xref astropy/astropy#11458

  8. anntzer commented on Apr 3, 2021

    @anntzer
    Contributor

    I think this may be related to sphinx-doc/sphinx#6211 (which I basically opened based on my experience with matplotlib)?

  9. anntzer commented on Apr 8, 2021

    @anntzer
    Contributor

    I am bit confused why this specific dotted reference breaks your build whereas a lot of other dotted references (e.g. .Transform) don't?

  10. pllim commented on Apr 8, 2021

    @pllim

    @anntzer , these are the warnings (it breaks because we have RTD set to fail on warning):

    MatplotlibDeprecationWarning:
    The validCap attribute was deprecated in Matplotlib 3.4 and will be removed two minor releases later.
      return getattr(obj, attr, *defargs)
    
    MatplotlibDeprecationWarning:
    The validJoin attribute was deprecated in Matplotlib 3.4 and will be removed two minor releases later.
      return getattr(obj, attr, *defargs)
    

    The code in astropy does not specifically have them, but rather a subclass inherited them. And then Sphinx tries to render docstring for inherited attributes. We also use sphinx-automodapi plugin to render it. So, it is really a perfect storm of a few things put together.

    References: astropy/astropy#11458 astropy/sphinx-automodapi#125

  11. timhoffm commented on Apr 8, 2021

    @timhoffm
    Member

    I'm now confused: Are you breaking because of the deprecation warnings or because of "reference target not found" in the first comment above? Or both?

  12. pllim commented on Apr 8, 2021

    @pllim

    Ah, not really. I was redirected to this issue from #19850 . I specifically speaking about the MatplotlibDeprecationWarning. I don't know what the "reference target not found" issue is about but I think @nstarman found a fix.

  13. 23 remaining items

  14. modified the milestones: v3.6.2, v3.6.3 on Oct 27, 2022
  15. modified the milestones: v3.6.3, v3.7.0 on Jan 11, 2023
  16. modified the milestones: v3.7.0, v3.7.1 on Feb 14, 2023
  17. modified the milestones: v3.7.1, v3.7-doc on Mar 4, 2023
  18. modified the milestones: v3.7-doc, v3.8-doc on Sep 9, 2023
  19. jklymak commented on Oct 8, 2023

    @jklymak
    Member

    I can't tell from the above if this is still an issue. I would guess not, so I'll close, but feel free to request a re-open with the current state of things.

  20. pllim commented on Oct 8, 2023

    @pllim

    We still have the hack in the code but no time to revisit.

  21. jklymak commented on Oct 8, 2023

    @jklymak
    Member

    Please open a new issue(s) if you still need help narrowing down the scope.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions