Conversation
| else: | ||
| print(f"Request failed with status code {response.status_code}") | ||
| return None | ||
| print(f"Request failed with status code {response.status_code}") | ||
| return None |
There was a problem hiding this comment.
Function make_request refactored with the following changes:
- Remove unnecessary else after guard condition (
remove-unnecessary-else)
| if len(model_list) == 0: | ||
| if not model_list: |
There was a problem hiding this comment.
Function main refactored with the following changes:
- Simplify sequence length comparison (
simplify-len-comparison)
| if (env in os.environ): | ||
| return os.environ[env] | ||
| return default | ||
| return os.environ.get(env, default) |
There was a problem hiding this comment.
Function env_or_def refactored with the following changes:
- Lift code into else after jump in control flow (
reintroduce-else) - Replace if statement with if expression (
assign-if-exp) - Simplify dictionary access using default get (
default-get)
| today = datetime.datetime.today() | ||
| today = datetime.datetime.now() |
There was a problem hiding this comment.
Lines 17-17 refactored with the following changes:
- Replace datetime.datetime.today() with datetime.datetime.now() (
use-datetime-now-not-today)
| if (env in os.environ): | ||
| return os.environ[env] | ||
| return default | ||
| return os.environ.get(env, default) |
There was a problem hiding this comment.
Function env_or_def refactored with the following changes:
- Lift code into else after jump in control flow (
reintroduce-else) - Replace if statement with if expression (
assign-if-exp) - Simplify dictionary access using default get (
default-get)
| try: | ||
| with open(file) as f: | ||
| grammar = f.read() | ||
| grammar = Path(file).read_text() |
There was a problem hiding this comment.
Function LlamaGrammar.from_file refactored with the following changes:
- Simplify basic file reads with
pathlib(path-read)
| self[key] = value | ||
| return self.iterator(self, key), True | ||
| self[key] = value | ||
| return self.iterator(self, key), True |
There was a problem hiding this comment.
Function std.map.insert refactored with the following changes:
- Remove unnecessary else after guard condition (
remove-unnecessary-else)
| if key in self: | ||
| return self.iterator(self, key) | ||
| else: | ||
| return self.end() | ||
| return self.iterator(self, key) if key in self else self.end() |
There was a problem hiding this comment.
Function std.map.find refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp)
| state.symbol_ids[base_name + "_" + str(next_id)] = next_id | ||
| state.symbol_ids[f"{base_name}_{str(next_id)}"] = next_id |
There was a problem hiding this comment.
Function generate_symbol_id refactored with the following changes:
- Use f-string instead of string concatenation [×2] (
use-fstring-for-concatenation)
| raise RuntimeError("expecting " + str(size) + " hex chars at " + str(src)) | ||
| raise RuntimeError(f"expecting {size} hex chars at {str(src)}") |
There was a problem hiding this comment.
Function parse_hex refactored with the following changes:
- Use f-string instead of string concatenation [×3] (
use-fstring-for-concatenation) - Remove unnecessary calls to
str()from formatted values in f-strings (remove-str-from-fstring)
| raise RuntimeError("unknown escape at " + str(src)) | ||
| raise RuntimeError(f"unknown escape at {str(src)}") |
There was a problem hiding this comment.
Function parse_char refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation)
| raise RuntimeError("expecting name at " + str(src)) | ||
| raise RuntimeError(f"expecting name at {str(src)}") |
There was a problem hiding this comment.
Function parse_name refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation)
| # } else if (*pos == '[') { // char range(s) | ||
| # pos++; | ||
| # enum llama_gretype start_type = LLAMA_GRETYPE_CHAR; |
There was a problem hiding this comment.
Function parse_sequence refactored with the following changes:
- Use f-string instead of string concatenation [×2] (
use-fstring-for-concatenation)
This removes the following comments ( why? ):
# }
# } else if (*pos == '(') { // grouping
# const char * name_end = parse_name(pos);
# last_sym_start = out_elements.size();
# } else if (*pos == '[') { // char range(s)
# break;
# enum llama_gretype start_type = LLAMA_GRETYPE_CHAR;
# out_elements.push_back({LLAMA_GRETYPE_RULE_REF, ref_rule_id});
# } else if (is_word_char(*pos)) { // rule reference
# pos = parse_space(pos + 1, is_nested);
# } else {
# // output reference to synthesized rule
# uint32_t sub_rule_id = generate_symbol_id(state, rule_name);
# if (last_sym_start == out_elements.size()) {
# throw std::runtime_error(std::string("expecting preceeding item to */+/? at ") + pos);
# throw std::runtime_error(std::string("expecting ')' at ") + pos);
# out_elements.push_back({LLAMA_GRETYPE_RULE_REF, sub_rule_id});
# if (*pos != ')') {
# uint32_t ref_rule_id = get_symbol_id(state, pos, name_end - pos);
# pos++;
# } else if (*pos == '*' || *pos == '+' || *pos == '?') { // repetition operator
# pos = parse_space(name_end, is_nested);
# pos = parse_space(pos + 1, true);
# }
# // parse nested alternates into synthesized rule
# pos = parse_alternates(state, pos, rule_name, sub_rule_id, true);
| if not (pos[0] == ":" and pos[1] == ":" and pos[2] == "="): | ||
| raise RuntimeError("expecting ::= at " + str(pos)) | ||
| if pos[0] != ":" or pos[1] != ":" or pos[2] != "=": | ||
| raise RuntimeError(f"expecting ::= at {str(pos)}") |
There was a problem hiding this comment.
Function parse_rule refactored with the following changes:
- Simplify logical expression using De Morgan identities (
de-morgan) - Use f-string instead of string concatenation [×2] (
use-fstring-for-concatenation)
| if 0x20 <= c and c <= 0x7F: | ||
| if 0x20 <= c <= 0x7F: |
There was a problem hiding this comment.
Function print_grammar_char refactored with the following changes:
- Combine two compares on same value into a chained compare (
chain-compares)
| "malformed rule, does not end with LLAMA_GRETYPE_END: " + str(rule_id) | ||
| f"malformed rule, does not end with LLAMA_GRETYPE_END: {rule_id}" |
There was a problem hiding this comment.
Function print_rule refactored with the following changes:
- Use f-string instead of string concatenation [×4] (
use-fstring-for-concatenation) - Swap if/else to remove empty if body (
remove-pass-body) - Remove unnecessary calls to
str()from formatted values in f-strings [×2] (remove-str-from-fstring)
Branch
mainrefactored by Sourcery.If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.
See our documentation here.
Run Sourcery locally
Reduce the feedback loop during development by using the Sourcery editor plugin:
Review changes via command line
To manually merge these changes, make sure you're on the
mainbranch, then run:Help us improve this pull request!