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

Add type annotations #15

Merged
merged 1 commit into from Oct 22, 2020
Merged

Add type annotations #15

merged 1 commit into from Oct 22, 2020

Conversation

mdellweg
Copy link
Member

Started to add type annotations.

This already revealed small inconsistencies (mostly around str vs bytes) and one actual bug (the super call).

@pulpbot
Copy link
Member

pulpbot commented Oct 18, 2020

WARNING!!! This PR is not attached to an issue. In most cases this is not advisable. Please see our PR docs for more information about how to attach this PR to an issue.

@daviddavis
Copy link
Contributor

I was just thinking about doing this.

@mdellweg
Copy link
Member Author

It's incompatible with python2. Is that a problem?

Well, it could be done with py2, but it's a mess.

if isinstance(obj, datetime.datetime):
return obj.isoformat()
else:
super(json.JSONEncoder).default(obj)
return super().default(obj)
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice that you were able to catch this using typing hints.

@daviddavis
Copy link
Contributor

It's incompatible with python2. Is that a problem?

That's a good question. I don't think it is but let me confirm.

@mdellweg mdellweg force-pushed the type_annotations branch 3 times, most recently from 4c09dd1 to 32a23a5 Compare October 18, 2020 14:33
@mdellweg
Copy link
Member Author

now with --strict. 😀

@mdellweg mdellweg marked this pull request as ready for review October 18, 2020 14:33
@mdellweg
Copy link
Member Author

It's incompatible with python2. Is that a problem?

That's a good question. I don't think it is but let me confirm.

FWIW We don't support py2 anyway to this point:

@mdellweg mdellweg force-pushed the type_annotations branch 3 times, most recently from 2bf59ba to fc7f608 Compare October 21, 2020 09:16
@mdellweg mdellweg changed the title WIP Add type annotations Add type annotations Oct 21, 2020
@mdellweg mdellweg force-pushed the type_annotations branch 4 times, most recently from 28092af to 40c2789 Compare October 21, 2020 14:16
@@ -15,7 +15,7 @@ options include:
## Configuration

The CLI can be configured by using a toml file.
By default the location of this file is `~/.config/pulp/settings.toml`.
By default the location of this file is `~/.config/pulp/settings.toml`.
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@click.option("--chunk-size", default=1000000, help="Chunk size in bytes (default is 1 MB)")
@click.option(
"--chunk-size", default=1000000, type=int, help="Chunk size in bytes (default is 1 MB)"
)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why the change here?

Copy link
Member Author

Choose a reason for hiding this comment

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

It is adding type=int and i hope that will add input validation on the click side.
Not sure if the decorator will add type annotations to the variable passed to the command, but that would be super cool.

def status(ctx: click.Context) -> None:
pulp_ctx: PulpContext = ctx.find_object(PulpContext)
result = pulp_ctx.call("status_read")
pulp_ctx.output_result(result)
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm curious why this changed as compared to say orphans_delete()?

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 didn't know about find_object but it looks like you can embed more than one object in the context that way.
I think, this is more explicit and forgot about orphan_delete it seems.

click.echo(".", nl=False, err=True)
raise click.ClickException("Task timed out")


def _config_callback(ctx, param, value):
def _config_callback(ctx: click.Context, param: Any, value: str) -> None:
Copy link
Contributor

Choose a reason for hiding this comment

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

I think param could maybe be a str but I guess it doesn't make a huge difference since we're not using it.

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 think, str didn't work...

@mdellweg mdellweg merged commit 4405c21 into pulp:develop Oct 22, 2020
@mdellweg mdellweg deleted the type_annotations branch October 23, 2020 09:09
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

3 participants