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

py domain: Ignore aliases for resolving :any: cross-references #10089

Merged
merged 4 commits into from Jun 26, 2022

Conversation

ewjoachim
Copy link
Contributor

@ewjoachim ewjoachim commented Jan 11, 2022

Subject: closes #10088 (EDIT: already closed as duplicate) and also closes #9577 I believe, since they are duplicates.
With this PR, we can use :any: again in Sphinx v4.x with autodoc & python aliases.
I believe that everything that used to work will still work

Feature or Bugfix

  • Bugfix

Purpose

See #10088
The issue is that that autodoc adds canonical (which is a good thing), and any doesn't play well with aliased objects (which is the bad thing we're solving here)

Detail

What I did, it's all in the python domain code:

  • If there are more than one matches when resolving any, we remove aliased nodes from matches.
    • either this brings the number of matches to 1 and it's all fine
    • or there's still more than one match and it means the issue is real.
  • In the tests with the canonical option, I've added multiple any lookups, and the test checks that there is no warning.

Just to be sure, I've run the test before the fix and it's red, and after the fix, it's green.

I don't know if this qualifies for a "hotfix" (not sure).

Relates

@ewjoachim ewjoachim changed the title :any: xref searches ignore aliases py-domain: :any: xref searches ignore aliases Jan 11, 2022
@ewjoachim ewjoachim force-pushed the py-domain-canonical-any-10088 branch 8 times, most recently from e9eb629 to 8b8ec94 Compare January 17, 2022 08:58
@ewjoachim ewjoachim force-pushed the py-domain-canonical-any-10088 branch from 8b8ec94 to 29de8ab Compare January 17, 2022 18:15
@ewjoachim
Copy link
Contributor Author

Hm, hey, anyone ?

@ewjoachim
Copy link
Contributor Author

@tk0miya if you have any lead as to what I can do to help this PR go forward ?

Comment on lines 1417 to 1376
if len(matches) > 1:
# Remove all duplicated matches
matches = [(name, obj) for name, obj in matches if not obj.aliased]

for name, obj in matches:
if obj[2] == 'module':
Copy link
Member

@AA-Turner AA-Turner May 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Skips a list comprehension step

Suggested change
if len(matches) > 1:
# Remove all duplicated matches
matches = [(name, obj) for name, obj in matches if not obj.aliased]
for name, obj in matches:
if obj[2] == 'module':
for name, obj in matches:
if len(matches) > 1 and obj.aliased:
# Skip duplicated matches
continue
if obj[2] == 'module':

A

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done (I've stored len(matches) > 1 in a variable)

@AA-Turner
Copy link
Member

Please update CHANGES for 5.x

A

@AA-Turner AA-Turner added this to the 5.x milestone May 27, 2022
@ewjoachim ewjoachim force-pushed the py-domain-canonical-any-10088 branch 4 times, most recently from 1d27518 to 8459887 Compare May 29, 2022 00:57
@ewjoachim
Copy link
Contributor Author

We should be all good now :)

@ewjoachim ewjoachim force-pushed the py-domain-canonical-any-10088 branch from 8459887 to 85616e5 Compare May 30, 2022 21:31
@ewjoachim
Copy link
Contributor Author

Rebased after 5.0 release :)

@ewjoachim
Copy link
Contributor Author

(is it expected that the bug label has not been set on the PR ?)

@ewjoachim ewjoachim force-pushed the py-domain-canonical-any-10088 branch from 85616e5 to 4883907 Compare June 3, 2022 08:03
@ewjoachim
Copy link
Contributor Author

Rebased after 5.0.1. Also, see #10515

@AA-Turner AA-Turner modified the milestones: 5.x, 5.1.0 Jun 5, 2022
@ewjoachim ewjoachim force-pushed the py-domain-canonical-any-10088 branch from 4883907 to 4245632 Compare June 25, 2022 21:49
@ewjoachim
Copy link
Contributor Author

Oh, I see you added this to the 5.1.0 milestone, I'll update CHANGES so that it appears in the 5.1.0 section :)

@ewjoachim ewjoachim force-pushed the py-domain-canonical-any-10088 branch from 4245632 to 86b89b6 Compare June 25, 2022 21:52
CHANGES Outdated Show resolved Hide resolved
CHANGES Outdated Show resolved Hide resolved
@AA-Turner AA-Turner changed the title py-domain: :any: xref searches ignore aliases py domain: Ignore aliases for resolving :any: cross-references Jun 26, 2022
@AA-Turner AA-Turner merged commit 663a5b7 into sphinx-doc:5.x Jun 26, 2022
@AA-Turner
Copy link
Member

Thanks @ewjoachim!

A

@ewjoachim ewjoachim deleted the py-domain-canonical-any-10088 branch June 26, 2022 21:09
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 27, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
3 participants