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

Turn attributes on HTMLPage into local variables and standalone functions #5826

Merged
merged 9 commits into from
Sep 29, 2018

Conversation

uranusjr
Copy link
Member

@uranusjr uranusjr commented Sep 28, 2018

#5800 part 1a (part a of #5822).

I also rewrote parse_base_url as mentioned in #5822 (comment).

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.
@@ -706,24 +706,40 @@ def egg_info_matches(
return None


def _parse_base_url(document, page_url):
Copy link
Member

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.)

Copy link
Member Author

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 :)

Copy link
Member

@cjerdonek cjerdonek left a 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.

return bases[0].get("href")
else:
return self.url

@property
def links(self):
Copy link
Member

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.)

Copy link
Member Author

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.

Copy link
Member Author

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.

@pradyunsg pradyunsg merged commit a5d4f88 into pypa:master Sep 29, 2018
@pradyunsg
Copy link
Member

Thanks! :)

@uranusjr uranusjr deleted the htmlpage-extract-localize branch September 29, 2018 17:43
@cjerdonek cjerdonek added the C: finder PackageFinder and index related code label Oct 1, 2018
@lock
Copy link

lock bot commented Jun 1, 2019

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.

@lock lock bot added the auto-locked Outdated issues that have been locked by automation label Jun 1, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Jun 1, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
auto-locked Outdated issues that have been locked by automation C: finder PackageFinder and index related code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants