-
Notifications
You must be signed in to change notification settings - Fork 85
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
Incorrect types passed by end-users at runtime are not caught until our code tries to do incompatible things with those objects (e.g. .upper()
on an Auth
instance)
#420
Comments
Thanks for the report! I think we need to think more about how this (and other) APIs in earthaccess could catch runtime type errors before they become confusing messages later. Failing early with "Unexpected type ( For reference, this is the change that introduced the new call to |
upper()
) unavailable for auth object in api.py.upper()
on an Auth
instance)
Does this new description of the problem work for everyone? |
We were supplying a valid
Thanks for linking to the docs page - since we're already providing a That said, I'll keep my eye on this for catching runtime type errors. : ) |
Ahh, that makes sense. Thanks! :) |
Thanks to you both for investigating this error! This feels like an issue of Python as a language not enforcing types. I see earthaccess already provides type hints (🎉). One library I've used on past projects to enforce the hints is pydantic, which worked well and has some nice features like coercing types. A brief google search shows this isn't the only option (Ex. typeguard). These could be ways to automatically raise errors when arguments don't match the specified types. |
I love Pydantic! Haven't use typeguard before though. I love the simplicity of adding |
Here's the pydantic feature I think we'd use: https://docs.pydantic.dev/latest/api/validate_call/ |
This validation could help with #279 as well! Especially if our runtime validation tool can also coerce types. |
Looks like Pydantic will do this. We may only want this at the API level, because I feel it could be confusing to debug the code with multiple levels of validation. https://docs.pydantic.dev/latest/concepts/validation_decorator/#argument-types
|
Given If you do want to leverage other capabilities of |
Given the major speed advantage of |
In testing for implementing cloud read-in in icepyx using CryoCloud, @rwegener2 and I discovered something changed between 0.6.2 and 0.8.2 that causes a failure where code ran successfully previously. In particular, the line:
s3 = earthaccess.get_s3fs_session(daac="NSIDC", provider=auth)
, where auth is an Auth instance, fails with an AttributeError when it tries to run the string operationupper()
on the auth object (see full traceback here). I haven't dug into recent changes but wanted to report here in case it's already known/being resolved.The text was updated successfully, but these errors were encountered: