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.
mypy still complains about
Optional
.First one is
return dt.tzname()
case. I know thatArrow
always store non naivedatetime
now. but becauseDateTimeFormatter
is public, someone could pass naivedatetime
object toDateTimeFormatter.format()
and in that caseDateTimeFormatter._format_token()
will returnNone
.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
https://github.com/isac322/arrow/blob/6aba5ed7626bfae2e1979354bd199aa526752cac/arrow/formatter.py#L145