-
Notifications
You must be signed in to change notification settings - Fork 0
Sourcery refactored master branch #1
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
base: master
Are you sure you want to change the base?
Conversation
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.
Due to GitHub API limits, only the first 60 comments can be shown.
|
|
||
| def t_error(t): | ||
| console.Out.Verbose("Illegal character '%s'" % t.value[0], t.lexer.lineno) | ||
| console.Out.Verbose(f"Illegal character '{t.value[0]}'", t.lexer.lineno) |
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.
Function t_error refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring)
| console.Out.Ci("[ERROR] UnicodeDecodeError in CppLexerNavigator: " + str(ex)) | ||
| console.Out.Ci(f"[ERROR] UnicodeDecodeError in CppLexerNavigator: {str(ex)}") | ||
| console.Out.Ci( | ||
| "[ERROR] Exception occurred reading file '%s', convert from UTF16LE to UTF8" % (filename), | ||
| f"[ERROR] Exception occurred reading file '{filename}', convert from UTF16LE to UTF8" |
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.
Function CppLexerNavigator.__init__ refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation) - Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring)
| elif Match(r"^#\s*endif$", token.value) and len(self.ifdefstack) != 0: | ||
| self.ifdefstack.pop() | ||
| return any(not ifdef for ifdef in self.ifdefstack) | ||
| return not all(self.ifdefstack) |
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.
Function CppLexerNavigator.ProcessIfdef refactored with the following changes:
- Invert any/all and simplify generator expression (
invert-any-all-body)
| if curToken is not None: | ||
| return self.lines[curToken.lineno - 1] | ||
| return None | ||
| return self.lines[curToken.lineno - 1] if curToken is not None else None |
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.
Function CppLexerNavigator.GetCurTokenLine 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)
| if column == 0: | ||
| return 1 | ||
| return column | ||
| return 1 if column == 0 else column |
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.
Function CppLexerNavigator._GetColumn 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)
| if token_id2 is not None and token_id2.lexpos < token_id3.lexpos: | ||
| return True | ||
| return False | ||
| return token_id2 is not None and token_id2.lexpos < token_id3.lexpos |
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.
Function CppLexerNavigator.HasBody 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 boolean if expression (
boolean-if-exp-identity) - Remove unnecessary casts to int, str, float or bool (
remove-unnecessary-cast)
| return ", ".join([self.type, "'" + self.name + "'", str(self.startToken), str(self.endToken)]) | ||
| return ", ".join( | ||
| [self.type, f"'{self.name}'", str(self.startToken), str(self.endToken)] | ||
| ) |
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.
Function Context.__str__ refactored with the following changes:
- Use f-string instead of string concatenation [×2] (
use-fstring-for-concatenation)
| if token.lexpos >= self.startToken.lexpos and token.lexpos <= self.endToken.lexpos: | ||
| return True | ||
| return False | ||
| return ( | ||
| token.lexpos >= self.startToken.lexpos | ||
| and token.lexpos <= self.endToken.lexpos | ||
| ) |
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.
Function Context.InScope 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 boolean if expression (
boolean-if-exp-identity) - Remove unnecessary casts to int, str, float or bool (
remove-unnecessary-cast)
| if self.Size() == 0: | ||
| return None | ||
| return self.contextstack.pop() | ||
| return None if self.Size() == 0 else self.contextstack.pop() |
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.
Function ContextStack.Pop 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)
| if self.Size() == 0: | ||
| return None | ||
| return self.contextstack[-1] | ||
| return None if self.Size() == 0 else self.contextstack[-1] |
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.
Function ContextStack.Peek 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)
| a = "" | ||
| for eachContext in self.contextstack: | ||
| a += eachContext.__str__() + " >> " | ||
| return a | ||
| return "".join( | ||
| f"{eachContext.__str__()} >> " for eachContext in self.contextstack | ||
| ) |
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.
Function ContextStack.__str__ refactored with the following changes:
- Use str.join() instead of for loop (
use-join) - Use f-string instead of string concatenation (
use-fstring-for-concatenation) - Inline variable that is immediately returned (
inline-immediately-returned-variable)
| if len(self.contextstackstack) == 0: | ||
| return None | ||
| return self.contextstackstack[-1] | ||
| return None if len(self.contextstackstack) == 0 else self.contextstackstack[-1] |
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.
Function _ContextStackStack.Peek 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)
|
|
||
| ########################################################################## | ||
| title = "nsiqcppstyle: N'SIQ Cpp Style ver " + version + "\n" | ||
| title = f"nsiqcppstyle: N'SIQ Cpp Style ver {version}" + "\n" |
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.
Lines 43-43 refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation)
| parser.add_argument("--version", action="version", version="%(prog)s " + version) | ||
| parser.add_argument( | ||
| "--version", action="version", version=f"%(prog)s {version}" | ||
| ) |
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.
Function get_parser refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation)
| console.Out.Ci("= Analyzing %s " % targetName) | ||
| console.Out.Ci(f"= Analyzing {targetName} ") |
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.
Function main refactored with the following changes:
- Replace interpolated string formatting with f-string [×3] (
replace-interpolation-with-fstring) - Replace call to format with f-string (
use-fstring-for-formatting)
| if object: | ||
| newtab = {} | ||
| for key, ritem in self.lexstatere.items(): | ||
| newre = [] |
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.
Function Lexer.clone refactored with the following changes:
- Move assignment closer to its usage within a block (
move-assign-in-block) - Merge append into list declaration (
merge-list-append)
| for f in part[1]: | ||
| if f and f[0]: | ||
| initialfuncs.append(f) | ||
|
|
||
| initialfuncs.extend(f for f in part[1] if f and f[0]) | ||
| for key, lre in self.lexstatere.items(): | ||
| titem = [] | ||
| for i in range(len(lre)): | ||
| titem.append((self.lexstateretext[key][i], _funcs_to_names(lre[i][1], self.lexstaterenames[key][i]))) | ||
| titem = [ | ||
| ( | ||
| self.lexstateretext[key][i], | ||
| _funcs_to_names(lre[i][1], self.lexstaterenames[key][i]), | ||
| ) | ||
| for i in range(len(lre)) | ||
| ] | ||
| tabre[key] = titem | ||
|
|
||
| tf.write("_lexstatere = %s\n" % repr(tabre)) | ||
| tf.write("_lexstateignore = %s\n" % repr(self.lexstateignore)) | ||
|
|
||
| taberr = {} | ||
| for key, ef in self.lexstateerrorf.items(): | ||
| if ef: | ||
| taberr[key] = ef.__name__ | ||
| else: | ||
| taberr[key] = None | ||
| taberr = { | ||
| key: ef.__name__ if ef else None | ||
| for key, ef in self.lexstateerrorf.items() | ||
| } |
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.
Function Lexer._writetab_impl refactored with the following changes:
- Convert for loop into dictionary comprehension (
dict-comprehension) - Replace if statement with if expression (
assign-if-exp) - Convert for loop into list comprehension (
list-comprehension) - Replace a for append loop with list extend (
for-append-to-extend)
| filename = os.path.join(outputdir, basetabfilename) + ".py" | ||
| filename = f"{os.path.join(outputdir, basetabfilename)}.py" |
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.
Function Lexer.writetab refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation)
| elif sys.version_info[0] < 3: | ||
| exec(f"import {tabfile} as lextab") | ||
| else: | ||
| if sys.version_info[0] < 3: | ||
| exec("import %s as lextab" % tabfile) | ||
| else: | ||
| env = {} | ||
| exec("import %s as lextab" % tabfile, env, env) | ||
| lextab = env["lextab"] | ||
| env = {} | ||
| exec(f"import {tabfile} as lextab", env, env) | ||
| lextab = env["lextab"] |
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.
Function Lexer.readtab refactored with the following changes:
- Merge else clause's nested if statement into elif (
merge-else-if-into-elif) - Replace interpolated string formatting with f-string [×2] (
replace-interpolation-with-fstring)
| raise LexError( | ||
| f"Scanning error. Illegal character '{lexdata[lexpos]}'", | ||
| lexdata[lexpos:], | ||
| ) |
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.
Function Lexer.token refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring)
| return [(lexre, lexindexfunc)], [regex], [lexindexnames] | ||
| except Exception: | ||
| m = int(len(relist) / 2) | ||
| m = len(relist) // 2 |
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.
Function _form_master_re refactored with the following changes:
- Simplify division expressions (
simplify-division)
| self.log = PlyLogger(sys.stderr) | ||
| else: | ||
| self.log = log | ||
| self.log = PlyLogger(sys.stderr) if log is None else log |
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.
Function LexerReflect.__init__ refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp)
| if not (statetype == "inclusive" or statetype == "exclusive"): | ||
| if statetype not in ["inclusive", "exclusive"]: |
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.
Function LexerReflect.get_states refactored with the following changes:
- Simplify logical expression using De Morgan identities (
de-morgan) - Replace multiple comparisons of same variable with
inoperator (merge-comparisons)
| if len(tsymbols) == 0: | ||
| if not tsymbols: |
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.
Function LexerReflect.get_rules refactored with the following changes:
- Simplify sequence length comparison (
simplify-len-comparison)
| # Validate the error function | ||
| efunc = self.errorf.get(state, None) | ||
| if efunc: | ||
| if efunc := self.errorf.get(state, None): |
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.
Function LexerReflect.validate_rules refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression)
This removes the following comments ( why? ):
# Validate the error function
| if value is not None and value == "operator": | ||
| return True | ||
| return False | ||
| return value is not None and value == "operator" |
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.
Function IsOperator 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 boolean if expression (
boolean-if-exp-identity) - Remove unnecessary casts to int, str, float or bool (
remove-unnecessary-cast)
| console.Out.Error("%s does not exist or incompatible." % ruleName) | ||
| console.Out.Error(f"{ruleName} does not exist or incompatible.") | ||
| continue | ||
| else: | ||
| console.Out.Info(" - ", ruleName, "is applied.") | ||
| ruleModule = __import__("rules." + ruleName) | ||
| ruleModule = __import__(f"rules.{ruleName}") |
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.
Function RuleManager.LoadRules refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring) - Use f-string instead of string concatenation (
use-fstring-for-concatenation)
| runtimePath = ModulePath() | ||
| else: | ||
| modename = globals()["__name__"] | ||
| module = sys.modules[modename] | ||
| runtimePath = os.path.dirname(module.__file__) | ||
| return runtimePath | ||
| return ModulePath() | ||
| modename = globals()["__name__"] | ||
| module = sys.modules[modename] | ||
| return os.path.dirname(module.__file__) |
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.
Function GetRuntimePath refactored with the following changes:
- Lift return into if (
lift-return-into-if) - Remove unnecessary else after guard condition (
remove-unnecessary-else)
| if sys.platform == "win32": | ||
| return "window" | ||
| else: | ||
| return "linux" | ||
| return "window" if sys.platform == "win32" else "linux" |
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.
Function GetSystemKey refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp)
| self.__expectTokenTypes("void FunctionName() " + specifier + ";", expectedTokenTypes) | ||
| self.__expectTokenTypes( | ||
| f"void FunctionName() {specifier};", expectedTokenTypes | ||
| ) |
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.
Function unitTest.__testFunctionSpecifier refactored with the following changes:
- Use f-string instead of string concatenation [×2] (
use-fstring-for-concatenation)
Branch
masterrefactored 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
masterbranch, then run:Help us improve this pull request!