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

Replace ParsedUri class with functions, cleanup internal argument parsing #191

Merged
merged 2 commits into from Apr 23, 2018

Conversation

mpenkov
Copy link
Collaborator

@mpenkov mpenkov commented Apr 22, 2018

This is better than what we previously had for two reasons.

First, we now know what options we parse from a URI up front. Previously, this was only possible by reading the relatively long ParsedUri constructor. Now, we just look at the fields of the namedtuple. This makes the code easier to understand, debug and improve. For example, it now becomes obvious that we don't actually use the ordinary_calling_format option anywhere: we just parse it.

Second, we make the code easier to understand by replacing a class with a data structure (namedtuple) and a parsing function. The previous ParsedUri class was really a function masquerading as a function - this is considered un-Pythonic. If a class is being used as a function, it should really just be a function.

Copy link
Contributor

@menshikh-iv menshikh-iv left a comment

Choose a reason for hiding this comment

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

Good work @mpenkov, please update PR description: add motivation part (why this important/needed/better).



def _parse_uri_hdfs(parsed_uri):
assert parsed_uri.scheme == 'hdfs'
Copy link
Contributor

Choose a reason for hiding this comment

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

Why asserts needed (you check exact same conditions before in if/elif), here and everywhere? Sanity-check only?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, it's a sanity check only.


Some of the above options only make sense for certain protocols, e.g.
bucket_id is only for S3."""
Uri.__new__.__defaults__ = (None,) * len(Uri._fields)
Copy link
Contributor

Choose a reason for hiding this comment

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

definitely need a comment here, too hacky

@menshikh-iv menshikh-iv changed the title replace ParsedUri function masquerading as a class with a function Replace ParsedUri class with functions, cleanup internal argument parsing Apr 23, 2018
@menshikh-iv menshikh-iv merged commit 34b3f90 into master Apr 23, 2018
@menshikh-iv menshikh-iv deleted the parseuri branch June 29, 2018 13:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants