lukasschwab / arxiv.py

Python wrapper for the arXiv API
MIT License
1.11k stars 123 forks source link

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

Closed InAnYan closed 4 months ago

InAnYan commented 4 months ago

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.