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

Python type annotations and patch Content-Type fixes #1619

Merged
merged 3 commits into from
Jul 17, 2024

Conversation

dpgraham4401
Copy link
Member

@dpgraham4401 dpgraham4401 commented Jul 15, 2024

this PR adds type annotations, which largely make use of TypedDicts, and Literals, to add static type checking to our client methods. It's particularly useful for **kwarg heavy methods since it reduces redundant inline documentation (e.g., writing the possible SubmissionTypes in each method), creates a more pleasant developer experience (possible auto completion) for previously unknown dicts, and allows users of the library to statically type check their usage.

It also makes another quick fix to the patch methods, previously adjusted in #1618, which require the header Content-Type: application/json-patch+json which I've honestly never seen before but it's what the RCRAInfo/e-Manifest API requires.

One last thing, this PR removed references to datetime.utcnow() classmethod which is deprecated and will be removed in a future release.

@dpgraham4401 dpgraham4401 added the python Pull requests that update Python code label Jul 15, 2024
@dpgraham4401 dpgraham4401 removed the request for review from wiljnichepa July 15, 2024 20:50
@dpgraham4401
Copy link
Member Author

yay for CI. Evidently Required and Unpack were introduced in python 3.11. So I either need to remove those type annotations to remain backwards compatible with 3.10 or we say that we only support python >= 3.11.

@wiljnichepa
Copy link
Collaborator

@dpgraham4401 I am fine either way - you've done a lot of good work and I think the package is much improved by it, so I lean towards 3.11+ compatability. PR looks good. I am comfortable merging (with update to requirements files) if you want to go forward as-is.

@dpgraham4401
Copy link
Member Author

I've found the PSF backports of typing features for versions < 3.10 here https://github.com/python/typing_extensions.

@wiljnichepa I would appreciate it if you could take a look at this. It should e ready for review now. Thanks!

@wiljnichepa wiljnichepa added the emanpy issues related to the emanifest python package label Jul 17, 2024
@wiljnichepa
Copy link
Collaborator

@dpgraham4401 I've had a chance to review and feel good about it. Thanks for all your work, especially to ensure additional compatability!

    correction version search parameters
    MTN search parameter type annotations
    type annotations for site and user search services
    typed responses for check_site_exists and get_entry_ports
    finish adding return types for DOT/RCRA lookups
    make RcraResponse accept Generic type and add generic types to select DOT lookup calls as well as a RcraSite TypedDict
    add mypy to requirements
…Manifest/RCRAInfo services.

    clean up and finalize type doc strings
    implement generic response types that return Manifest types
    fix test that allow new_client to be created without a RCRAInfo environment
    Waste type definition
    move types to separate module to eliminate the massive file
    add Manifest Type Definition
    rename types for consistency and export public types at package level
    shorten doc strings to below 99 characters where possible
    lint with mypy and fix type annotations for possibly None types
    use the python/type_checking package to for backward compatible API types. Add type stubs for requirements_dev.txt
    remove 'Required' type annotation on SignManifestArgs to remain backwards compatible with python 3.10
    see documentation on Required https://docs.python.org/3/library/typing.html\#typing.Required
    increment version and remove deprecated datetime.utcnow() calls
    UI Link service type annotations
    type annotations for sign_manifest method
@dpgraham4401 dpgraham4401 merged commit d7ec7cf into USEPA:master Jul 17, 2024
3 checks passed
@dpgraham4401 dpgraham4401 deleted the python_type_annotations branch July 17, 2024 15:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
emanpy issues related to the emanifest python package python Pull requests that update Python code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants