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

Use Optional[T] for values that may not be present #163

Closed
InAnYan opened this issue Jun 20, 2024 · 0 comments · Fixed by #168
Closed

Use Optional[T] for values that may not be present #163

InAnYan opened this issue Jun 20, 2024 · 0 comments · Fixed by #168
Assignees
Labels
enhancement Requests for new features or improvements.

Comments

@InAnYan
Copy link

InAnYan commented Jun 20, 2024

Motivation

Types assigned to fields like journal_ref or doi of class Result doesn't represent them correctly.

"... if present" comment is typically present. But the type is just str.

What does "if present" exactly means? Initially, I thought it would be just empty string, because the type is str, but in reality it is None.

Solution

Replace the type annotation for fields that may not be present using Optional.

Considered alternatives

Well, you can instead return empty string instead of None to be complaint with the type, but, Optional is much cleaner approach.

@InAnYan InAnYan added the enhancement Requests for new features or improvements. label Jun 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Requests for new features or improvements.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants