USEPA / e-manifest

API services documentation and reference material for the e-Manifest hazardous waste tracking system
https://www.epa.gov/e-manifest
Creative Commons Zero v1.0 Universal
26 stars 22 forks source link

Python type annotations and patch `Content-Type` fixes #1619

Closed dpgraham4401 closed 3 months ago

dpgraham4401 commented 3 months ago

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 commented 3 months ago

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 commented 3 months ago

@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 commented 3 months ago

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 commented 3 months ago

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