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

Use debug log level for AttributeErrors in viewcode #13016

Merged
merged 1 commit into from
Nov 22, 2024

Conversation

jenshnielsen
Copy link
Contributor

Subject: Log AttributeError in viewcode as debug

Feature or Bugfix

  • Bugfix

Purpose

This message is very common and part of normal operation.
This makes it dominate verbose output without adding value.
In my code this message is something like ~90 % of the output in
verbose mode.

Relates

  • N/A

This message is very common and part of normal operation

This makes it dominate verbose output without adding value
@jayaddison
Copy link
Contributor

Hi @jenshnielsen - we may be able to consider this change, but also: have you opened any discussions related to this, and/or attempted to trace the source of the AttributeError messages that are appearing? (perhaps there are some problems that we could resolve here, rather than reducing the visibility of those messages)

@jenshnielsen
Copy link
Contributor Author

@jayaddison As I understand it this Attribute Error is completely by design and expected. This happens when viewsource is trying to look up instance attributes, I assume this is such that a link could be provided directly to the definition of the attribute. It is expected that instance attributes cannot be looked up since the class is not instantiated by viewsource. I suppose that some of the logic from autodoc could be lifted to try to do this but it does not seem like a feature that would add any value.

In summary:

  • This warning is triggered for each instance attribute on a Class passed by view source.
  • It is documented inline that this is expected to fail and the code as is in sphinx master expects this to fail

I therefor don't think it makes sense to log this at verbose level

@jayaddison
Copy link
Contributor

Thanks @jenshnielsen - I've been reading through the verbose output logs of Sphinx during a self-build to HTML, and initially I'm finding some value in these messages.

For example, supported_linkcode is an attribute that viewcode reads from -- but it isn't declared on the Builder class in Sphinx, because it's an attribute that is only (currently, at least) respected by that particular extension. An AttributeError appears because we reference it in some of our changelogs -- meaning that those cross-references are dropped. That's something that I'd argue is useful, when building with verbosity.

If something is annotated as a reference in markup, then I think that indicates that someone intended it to be navigable to some other expanded-or-more-precise information source. Dropping those if they're not found, and omitting log output about those cases seems OK by default, but to also omit them during verbose builds seems questionable to me.

Can you provide a hyperlink to an existing open source project codebase where these AttributeError messages are particularly excessive, or perhaps provide a minimal self-contained project example instead that demonstrates the problem?

@jenshnielsen
Copy link
Contributor Author

Ok if I understand it correctly I guess what you are saying is that this message is useful if it fails to look up a class attribute and what I am saying is that the message is misleading when looking up an instance attribute.

I suppose one thing that would help would be if the message was a bit more clear. E.g. clarify that its viewcode specific and that its most likely harmless..

In QCoDeS for example [here] (https://github.com/microsoft/Qcodes/actions/runs/11512553542/job/32047752164) This line accounts for 2544 lines out of the 2573 lines logged during the reading step. I guess this is somewhat unusual since we have many subclasses of the same class which has a number of instance attributes such that the same warning is raised for each submodule.

@AA-Turner AA-Turner changed the title Log AttributeError in viewcode as debug Use debug log level for AttributeErrors in viewcode Nov 22, 2024
@AA-Turner AA-Turner merged commit 92210f5 into sphinx-doc:master Nov 22, 2024
23 checks passed
@AA-Turner AA-Turner added this to the 8.2.0 milestone Nov 22, 2024
@jenshnielsen jenshnielsen deleted the logging_to_debug branch November 22, 2024 18:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants