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

Enable mypy for ngclient #1489

Merged
merged 9 commits into from
Aug 30, 2021
Merged

Commits on Aug 27, 2021

  1. Add ngclient to mypy

    Extend mypy to include all files under ngclient.
    
    Signed-off-by: Teodora Sechkova <tsechkova@vmware.com>
    sechkova committed Aug 27, 2021
    Configuration menu
    Copy the full SHA
    38b85cb View commit details
    Browse the repository at this point in the history
  2. Add type annotations to download.py and fetcher.py

    Add the stub for the requests package (types-requests)
    to requirements-tests.txt.
    
    Add urllib3 to the ignored imports. The project seems
    to have added type annotations already but has not
    released a version including them yet.
    
    Signed-off-by: Teodora Sechkova <tsechkova@vmware.com>
    sechkova committed Aug 27, 2021
    Configuration menu
    Copy the full SHA
    191a1e5 View commit details
    Browse the repository at this point in the history
  3. Replace BinaryIO with IO[bytes] in metadata.py

    Needed in order to be compatible with the return type of
    download_file (TemporaryFile is typed as IO[bytes]).
    BinaryIO is a subclass of IO[bytes].
    
    Signed-off-by: Teodora Sechkova <tsechkova@vmware.com>
    sechkova committed Aug 27, 2021
    Configuration menu
    Copy the full SHA
    b6e02bd View commit details
    Browse the repository at this point in the history
  4. Add missing type annotations to updater

    Add missing annotations and partially resolve mypy
    errors in updater.py and trusted_metadata_set.py
    
    Signed-off-by: Teodora Sechkova <tsechkova@vmware.com>
    sechkova committed Aug 27, 2021
    Configuration menu
    Copy the full SHA
    ea76a30 View commit details
    Browse the repository at this point in the history
  5. Use assert to check for None values

    This is done only for hinting 'mypy' that we have
    ensured these values cannot be None.
    
    'Bandit' raises warnings for assert usage in the code
    but we are disabling them since we do not rely upon
    'asserts' for any runtime checks but only for type checking.
    
    Signed-off-by: Teodora Sechkova <tsechkova@vmware.com>
    sechkova committed Aug 27, 2021
    Configuration menu
    Copy the full SHA
    018364d View commit details
    Browse the repository at this point in the history
  6. Make TrustedMetadataSet.root non-optional

    The 'root' property is guaranteed to be set after init.
    
    Signed-off-by: Teodora Sechkova <tsechkova@vmware.com>
    sechkova committed Aug 27, 2021
    Configuration menu
    Copy the full SHA
    8c9534b View commit details
    Browse the repository at this point in the history
  7. Make SlowRetrievalError parameter optional

    SlowRetrievalError is raised from RequestsFetcher where
    average_download_speed is not calculated.
    
    Signed-off-by: Teodora Sechkova <tsechkova@vmware.com>
    sechkova committed Aug 27, 2021
    Configuration menu
    Copy the full SHA
    cd096ba View commit details
    Browse the repository at this point in the history
  8. Denote expected type of Metadata.signed

    By explicitly denoting the expected type of Metadata.signed
    we help mypy understand our intentions and correctly figure
    out types. This is entirely a typing feature and has no
    runtime effect.
    
    Modify the return type of Metadata.from_dict to match the
    other factory methods (from_*).
    
    Signed-off-by: Teodora Sechkova <tsechkova@vmware.com>
    sechkova committed Aug 27, 2021
    Configuration menu
    Copy the full SHA
    4f57ae4 View commit details
    Browse the repository at this point in the history
  9. Load trusted root in a separate private method

    Add an additional private method for loading the initial
    trusted root metadata. The public method update_root() is
    now used only externally for updating the intiial root.
    The 'root' property is used only after its initialization
    in the constructor and is not longer optional which makes
    mypy happy.
    
    This split results in cleaner code and the ability to annotate
    the 'root' property as non-optional at the cost of some code
    duplication.
    
    Signed-off-by: Teodora Sechkova <tsechkova@vmware.com>
    sechkova committed Aug 27, 2021
    Configuration menu
    Copy the full SHA
    6ada96c View commit details
    Browse the repository at this point in the history