Skip to content

Commit 3eb02e2

Browse files
committed
runtime: Fix bugs found by static typing
1 parent f3a629f commit 3eb02e2

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

fluent.runtime/fluent/runtime/fallback.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ def __init__(self, roots: Union[str, List[str]]):
107107
location on disk, or a list of strings.
108108
"""
109109
self.roots = [roots] if isinstance(roots, str) else roots
110-
self.Resource = FluentResource
111110

112111
def resources(self, locale: str, resource_ids: List[str]) -> Generator[List['Resource'], None, None]:
113112
for root in self.roots:

fluent.runtime/fluent/runtime/resolver.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,10 @@ def resolveEntryReference(
229229
ref_id = reference_to_id(ref)
230230
env.errors.append(unknown_reference_error_obj(ref_id))
231231
return FluentNone(f'{{{ref_id}}}')
232+
except TypeError:
233+
ref_id = reference_to_id(ref)
234+
env.errors.append(FluentReferenceError(f"No pattern: {ref_id}"))
235+
return FluentNone(ref_id)
232236

233237

234238
class MessageReference(FTL.MessageReference, BaseResolver):
@@ -298,6 +302,9 @@ def __call__(self, env: ResolverEnvironment) -> Union[str, FluentNone]:
298302
break
299303

300304
if found is None:
305+
if default is None:
306+
env.errors.append(FluentFormatError("No default"))
307+
return FluentNone()
301308
found = default
302309
return found.value(env)
303310

fluent.runtime/fluent/runtime/types.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ def format(self, locale: Locale) -> str:
118118
base_pattern = locale.currency_formats['standard']
119119
pattern = self._apply_options(base_pattern)
120120
return pattern.apply(selfnum, locale, currency=self.options.currency) # type: ignore
121+
# never happens
122+
return '???'
121123

122124
def _apply_options(self, pattern: NumberPattern) -> NumberPattern:
123125
# We are essentially trying to copy the
@@ -339,8 +341,6 @@ def _ensure_datetime_tzinfo(dt: datetime, tzinfo: Union[str, None] = None) -> da
339341
dt = dt.replace(tzinfo=pytz.UTC)
340342
if tzinfo is not None:
341343
dt = dt.astimezone(get_timezone(tzinfo))
342-
if hasattr(tzinfo, 'normalize'): # pytz
343-
dt = tzinfo.normalize(datetime)
344344
return dt
345345

346346

0 commit comments

Comments
 (0)