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

Improve docstrings language in Metadata API #1815

Merged
merged 4 commits into from
Feb 8, 2022

Conversation

ivanayov
Copy link
Collaborator

@ivanayov ivanayov commented Feb 1, 2022

This change updates some obvious and unnecessary fields docs in the
Metadata API with more despriptive details, as well as unifies
syntax between different classes and methods

Addresses #1600

  • The code follows the Code Style Guidelines
  • [n/a] Tests have been added for the bug fix or new feature
  • [n/a] Docs have been added for the bug fix or new feature

fields. It guarantees that input containing unknown fields will
not break serialization from and deserialisation into a Metadta
object and thus aligns with the TUF specification implication that
unrecognized attribute-value fields should be supported
snapshot_meta: Meta information for snapshot metadata.
Copy link
Collaborator Author

@ivanayov ivanayov Feb 1, 2022

Choose a reason for hiding this comment

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

This is one I wondered whether to edit or not. It relates to obvious and unnecessary information, but on the other side it's simple and correct. I wondered what's your opinion about explaining why it's available in the API - do you find such clarification good or rather unnecessary?

Copy link
Member

@jku jku Feb 2, 2022

Choose a reason for hiding this comment

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

(reply to another comment)
Yeah documenting meta in a comprehensive manner requires a lot of specification context so maybe we leave it as is... The MetaFile type does clearly document its content after all.

@coveralls
Copy link

coveralls commented Feb 1, 2022

Pull Request Test Coverage Report for Build 1811764274

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 98.343%

Totals Coverage Status
Change from base Build 1811698342: 0.0%
Covered Lines: 1118
Relevant Lines: 1134

💛 - Coveralls

Copy link
Member

@jku jku left a comment

Choose a reason for hiding this comment

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

I wish this was in multiple commits so we could easily decide to only take some changes now and leave others for discussion... This issue should maybe have been split by change type to make that clearer that things like consistent double-backticks are easier to find a solution to than other issues (like consistent use of article where we need to decide what we want). The changes do conflict with each other so I can see why you did them all at once.

Anyway, I'll review but let's discuss if it makes sense to split this or to continue tweaking this PR.


There's a lot of good changes here, just commenting on potential issues.

I'm not sold on the use of indefinite article everywhere. It's fine in some places but looks quite bad in others:
threshold: A number of keys required to...
length: A length of the target file in bytes
those do not look right

Also the use of indefinite article is not consistent: there are still places that use definite article instead and the commit even adds a few new definite articles (see TargetFile methods for examples). I don't think 100% consistency is required but I don't understand how the article is chosen...

Overall, I think the indefinite article does not work in many places: In my opinion we should not standardize on it. I would maybe suggest a default choice of no article (since it makes docstrings shorter) and diverging from that if the context requires it.

@@ -118,14 +118,14 @@ def __init__(self, signed: T, signatures: Dict[str, Signature]):

@classmethod
def from_dict(cls, metadata: Dict[str, Any]) -> "Metadata[T]":
"""Creates Metadata object from its dict representation.
"""Creates ``Metadata`` object from its dict representation.
Copy link
Member

Choose a reason for hiding this comment

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

We say "dict representation" a lot as if it's obvious what that means :)

I don't have a great alternative suggestion, just commenting.

Copy link
Member

Choose a reason for hiding this comment

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

Would it be better non-abbreviated, i.e. "dictionary representation"? I think I used dict to keep it on one line.
Or would "json/dict representation" help people better associate it with the format described in the spec?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think "json/dict representation" is good. "dict" vs. "dictionary" is quite similar, while "json representation" should be obvious for everyone.

tuf/api/metadata.py Outdated Show resolved Hide resolved
tuf/api/metadata.py Outdated Show resolved Hide resolved
tuf/api/metadata.py Outdated Show resolved Hide resolved
tuf/api/metadata.py Outdated Show resolved Hide resolved
fields. It guarantees that input containing unknown fields will
not break serialization from and deserialisation into a Metadta
object and thus aligns with the TUF specification implication that
unrecognized attribute-value fields should be supported
snapshot_meta: Meta information for snapshot metadata.
Copy link
Member

@jku jku Feb 2, 2022

Choose a reason for hiding this comment

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

(reply to another comment)
Yeah documenting meta in a comprehensive manner requires a lot of specification context so maybe we leave it as is... The MetaFile type does clearly document its content after all.

tuf/api/metadata.py Outdated Show resolved Hide resolved
@ivanayov
Copy link
Collaborator Author

ivanayov commented Feb 2, 2022

@jku Thank you for the review! I've split to several commits, as you advice. It's a bit harder to address feedback, as it should go to a specific commit in a single-file update, but I agree it's a better history at the end.

tuf/api/metadata.py Outdated Show resolved Hide resolved
tuf/api/metadata.py Outdated Show resolved Hide resolved
@ivanayov
Copy link
Collaborator Author

ivanayov commented Feb 3, 2022

Python setup failed on windows.

@jku jku self-requested a review February 7, 2022 10:22
Copy link
Member

@jku jku left a comment

Choose a reason for hiding this comment

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

thanks for the nice commits: I was expecting to suggest moving some commits to a later PR... but I think I actually agree with all of these, they seem to be clear improvements. Only thing that is a required fix is a rebase (merge is not currently clean)

There are things to improve in the docs but this is a big PR already and there's no need to fix everything at once, just leaving some comments:

  • I noticed some docstring errors and left comments: none of them seem to be your fault so feel free to either fix here or leave to next PR
  • The unrecognised_fields docstring feels about the right amount of detail to me -- maybe we 'd like to explain general concept in one place somewhere but individual docstrings look ok
  • Many arguments still explain "what" the argument is, not "why" it is: as an example we document signer argument with securesystemslib.signer.Signer implementation which does not explain why signer is an argument (what is it used for).

... but all of these can be handled in future improvements. I've re-run the tests after setup-python fixed itself: they look good.

tuf/api/metadata.py Outdated Show resolved Hide resolved
tuf/api/metadata.py Outdated Show resolved Hide resolved
tuf/api/metadata.py Outdated Show resolved Hide resolved
@lukpueh
Copy link
Member

lukpueh commented Feb 7, 2022

Thanks for working on this, @ivanayov and for reviewing, @jku! Let me know if you want more eyes.

tuf/api/metadata.py Outdated Show resolved Hide resolved
@ivanayov ivanayov force-pushed the metadata_docstrings_imprv branch 2 times, most recently from a2893bd to 8b54971 Compare February 7, 2022 17:44
@ivanayov
Copy link
Collaborator Author

ivanayov commented Feb 7, 2022

Thank you @jku ! I addressed your comments here, as they are related to the changes anyway.
Changed

signer: ``securesystemslib.signer.Signer`` implementation

to

signer: ``securesystemslib.signer.Signer`` implementation containing a
signature and a keyid of the key that signature was generated with.

The other changes are just the fixes that you proposed + moving some of the existing changes to the right commit (I was a bit lazy to do that before addressing the comments 😁).

There are still some

data: Metadata content.
...
filename: Path to write the file to.
etc.

but I think there's enough context around them and adding explanations could make the docs too verbose and might rather confuse the user by creating expectations of some deeper meaning behind. Do you think that those should be better explained? @lukpueh do you have some preference, too?

Copy link
Member

@jku jku left a comment

Choose a reason for hiding this comment

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

Thank you. I think I would like to leave the signer argument improvements for later: It is significantly more difficult to explain "why" than "what" -- and this PR is long enough.

In practice:

signer: ``securesystemslib.signer.Signer`` implementation containing a
signature and a keyid of the key that signature was generated with.

this is slightly incorrect (signer does not contain a signature, it produces signatures) and still doesn't explain why there is a signer argument. Could you just leave the original description in and then we can continue tweaking these later?

This change unifies quotes to double backtick across docs in the
Metadata API in order to provide better visualisation

Signed-off-by: Ivana Atanasova <[email protected]>
This change unifies wording across docs in the Metadata API, like
Args vs. Arguments and same repetitive descriptions written
differently in different classes/methods

Signed-off-by: Ivana Atanasova <[email protected]>
This change unifies as mush as the context allows and improves the
use of definite vs. indefinite vs. no article across docs in the
Metadata API. It sticks to no article in most cases for simplisity
and readability, but leaves definite article where it's strictly
necessary

Signed-off-by: Ivana Atanasova <[email protected]>
@lukpueh
Copy link
Member

lukpueh commented Feb 8, 2022

There are still some

data: Metadata content.
...
filename: Path to write the file to.
etc.

but I think there's enough context around them and adding explanations could make the docs too verbose and might rather confuse the user by creating expectations of some deeper meaning behind. Do you think that those should be better explained? @lukpueh do you have some preference, too?

I think both are okay. Especially the latter is actually adds useful information not provided by the arg name alone.

This change updates some obvious and unnecessary fields docs in the
Metadata API with more despriptive details

Signed-off-by: Ivana Atanasova <[email protected]>
@ivanayov
Copy link
Collaborator Author

ivanayov commented Feb 8, 2022

@jku I removed the change.

@jku
Copy link
Member

jku commented Feb 8, 2022

Thanks!

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.

5 participants