Refactor formatter to avoid nullable type bugs
mypy still complains about Optional.
arrow/formatter.py:125: error: Incompatible return value type (got "Optional[str]", expected "str")
arrow/formatter.py:142: error: Incompatible return value type (got "Optional[str]", expected "str")
First one is return dt.tzname() case.
I know that Arrow always store non naive datetime now. but because DateTimeFormatter is public, someone could pass naive datetime object to DateTimeFormatter.format() and in that case DateTimeFormatter._format_token() will return None.
Second one is return self.locale.meridian(dt.hour, token).
But because those issues are known issue (I only annotate type for those cases), I think we can just leave FIXME comment and cast it as str for now. I want to minimize behavior changing in this PR.
Originally posted by @isac322 in https://github.com/arrow-py/arrow/pull/883#discussion_r577341387
https://github.com/isac322/arrow/blob/6aba5ed7626bfae2e1979354bd199aa526752cac/arrow/formatter.py#L128
return dt.tzname()
https://github.com/isac322/arrow/blob/6aba5ed7626bfae2e1979354bd199aa526752cac/arrow/formatter.py#L145
return self.locale.meridian(dt.hour, token)