-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Turn attributes on HTMLPage into local variables and standalone functions #5826
Conversation
This property is only used in HTMLPage.links, which is only called once per instance in PackageFinder.find_all_candidates(). This would not affect performance or behavior, but improves data locality. The unit test of this property is and modified to test the underlying function instead.
This attribute is only used by HTMLPage.links, which is only used once per instance in PackageFinder.find_all_candidates(), so this change does not affect performance or behavior, but improves data locality.
src/pip/_internal/index.py
Outdated
@@ -706,24 +706,40 @@ def egg_info_matches( | |||
return None | |||
|
|||
|
|||
def _parse_base_url(document, page_url): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a nit, but I mention it because it will probably come up a bunch more times. For functions that accept parsed html, it might be better not to call the function "parse" because it has already been parsed by the time it receives it. So maybe something like _get_base_url()
or _determine_base_url()
. (I know I said parse_anchor()
as an off-hand example in an earlier comment, so I'm arguing against that.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_determine_base_url()
sounds good to me :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks okay to me. Just a couple minor suggestions.
src/pip/_internal/index.py
Outdated
return bases[0].get("href") | ||
else: | ||
return self.url | ||
|
||
@property | ||
def links(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see the responsibility of the property is being expanded also to parse. Since normally, properties should "do" very little, you might want to add a comment saying the property should only be called once. (I'm assuming this is just a temporary intermediate step, so I'm okay with leaving it with an expanded scope.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I totally agree. This property is only left as-is to reduce unnecessary diff, since the property is going to be removed in the next patch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On second thought, I’m going to rename the property (and turn it into a generator function) to clarify its purpose. I hate properties anyway, personally.
868c21c
to
47ba191
Compare
Thanks! :) |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
#5800 part 1a (part a of #5822).
I also rewrote
parse_base_url
as mentioned in #5822 (comment).