add types to some more Fluent variables
This commit is contained in:
parent
8cc6758eb1
commit
3d366d5264
@ -13,7 +13,7 @@ modules = json.load(open(strings_json))
|
||||
|
||||
class Variable(TypedDict):
|
||||
name: str
|
||||
kind: Literal["Any", "Int"]
|
||||
kind: Literal["Any", "Int", "String", "Float"]
|
||||
|
||||
|
||||
def legacy_enum() -> str:
|
||||
@ -60,8 +60,12 @@ def get_arg_types(args: List[Variable]) -> str:
|
||||
def arg_kind(arg: Variable) -> str:
|
||||
if arg["kind"] == "Int":
|
||||
return "int"
|
||||
else:
|
||||
elif arg["kind"] == "Any":
|
||||
return "FluentVariable"
|
||||
elif arg["kind"] == "Float":
|
||||
return "float"
|
||||
else:
|
||||
return "str"
|
||||
|
||||
|
||||
def get_args(args: List[Variable]) -> str:
|
||||
|
@ -1090,7 +1090,7 @@ class DownloaderInstaller(QObject):
|
||||
label=tr.addons_downloading_adbd_kb02fkb(
|
||||
part=len(self.log) + 1,
|
||||
total=len(self.ids),
|
||||
kilobytes=self.dl_bytes / 1024,
|
||||
kilobytes=self.dl_bytes // 1024,
|
||||
)
|
||||
)
|
||||
|
||||
|
@ -30,9 +30,8 @@ pub struct Variable {
|
||||
#[derive(Debug, PartialOrd, Ord, PartialEq, Eq, Serialize)]
|
||||
enum VariableKind {
|
||||
Int,
|
||||
// Float,
|
||||
// Number,
|
||||
// String,
|
||||
Float,
|
||||
String,
|
||||
Any,
|
||||
}
|
||||
|
||||
@ -110,10 +109,12 @@ impl Visitor {
|
||||
}
|
||||
}
|
||||
|
||||
fn visit_inline_expression(&mut self, expr: &InlineExpression<&str>) {
|
||||
fn visit_inline_expression(&mut self, expr: &InlineExpression<&str>, in_select: bool) {
|
||||
match expr {
|
||||
InlineExpression::VariableReference { id } => {
|
||||
write!(self.text, "{{${}}}", id.name).unwrap();
|
||||
if !in_select {
|
||||
write!(self.text, "{{${}}}", id.name).unwrap();
|
||||
}
|
||||
self.variables.insert(id.name.to_string());
|
||||
}
|
||||
InlineExpression::Placeable { expression } => {
|
||||
@ -126,19 +127,24 @@ impl Visitor {
|
||||
fn visit_expression(&mut self, expression: &Expression<&str>) {
|
||||
match expression {
|
||||
Expression::SelectExpression { selector, variants } => {
|
||||
self.visit_inline_expression(&selector);
|
||||
self.visit_inline_expression(&selector, true);
|
||||
self.visit_pattern(&variants.last().unwrap().value)
|
||||
}
|
||||
Expression::InlineExpression(expr) => self.visit_inline_expression(expr),
|
||||
Expression::InlineExpression(expr) => self.visit_inline_expression(expr, false),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<String> for Variable {
|
||||
fn from(name: String) -> Self {
|
||||
// rather than adding more items here as we add new strings, we should probably
|
||||
// try to either reuse existing ones, or consider some sort of Hungarian notation
|
||||
let kind = match name.as_str() {
|
||||
"cards" | "notes" | "count" | "amount" => VariableKind::Int,
|
||||
_ => VariableKind::Any,
|
||||
"cards" | "notes" | "count" | "amount" | "reviews" | "total" | "selected"
|
||||
| "kilobytes" => VariableKind::Int,
|
||||
"average-seconds" => VariableKind::Float,
|
||||
"val" | "found" | "expected" | "part" => VariableKind::Any,
|
||||
_ => VariableKind::String,
|
||||
};
|
||||
Variable { name, kind }
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user