-
Notifications
You must be signed in to change notification settings - Fork 27
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
Add type hints to fluent.syntax & fluent.runtime #180
Conversation
b2f8bb4
to
c498d15
Compare
Are you planning on bumping to 0.19 after this? |
Yes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just random nits/comments that should be taken as suggestions at most.
elif is_number(val2): | ||
return match(val2, val1, env) | ||
|
||
return val1 == val2 | ||
return cast(bool, val1 == val2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
out of interest, why do we have to cast
an equality expression to bool
? Isn't an equality expression implicitly a boolean?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's because the inputs are Any
, and that at least technically allows for an __eq__(self, other)
overload that returns something other than a bool
.
maximumFractionDigits = attr.ib(default=None) | ||
minimumSignificantDigits = attr.ib(default=None) | ||
maximumSignificantDigits = attr.ib(default=None) | ||
style: Literal['decimal', 'currency', 'percent'] = attr.ib( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we use the FORMAT_STYLE_DECIMAL
etc constants here instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think that's possible with Literal[]
, or at least I'm not aware of a way of an alternative type expression that would resolve to this.
Co-authored-by: Andrew Williamson <awilliamson@mozilla.com>
Fixes #165
The work here is split into commits that may be easier to review separately. The internal hints for the runtime resolver and compiler are pretty weak, as the base implementation is making explicit use of the language being fundamentally untyped.
The bugs that are fixed are all various sorts of corner cases that the code didn't account for previously; the errors tend to follow similar cases in fluent.js.
While adding the types I used both mypy and pylance; the added CI tests only apply
mypy --strict
as the strict-mode pylance checks don't all pass (mostly due to usingUnknown
values in places that acceptAny
).