Skip to content

Conversation

@sourcery-ai
Copy link

@sourcery-ai sourcery-ai bot commented Nov 14, 2023

Branch master refactored 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 master branch, then run:

git fetch origin sourcery/master
git merge --ff-only FETCH_HEAD
git reset HEAD^

Help us improve this pull request!

@sourcery-ai sourcery-ai bot requested a review from machinekoder November 14, 2023 11:10
Copy link
Author

@sourcery-ai sourcery-ai bot left a 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)
Copy link
Author

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:

Comment on lines -406 to +408
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"
Copy link
Author

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:

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)
Copy link
Author

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:

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
Copy link
Author

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:

Comment on lines -491 to +489
if column == 0:
return 1
return column
return 1 if column == 0 else column
Copy link
Author

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:

Comment on lines -921 to +911
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
Copy link
Author

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:

Comment on lines -936 to +926
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)]
)
Copy link
Author

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:

Comment on lines -945 to +938
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
)
Copy link
Author

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:

Comment on lines -958 to +949
if self.Size() == 0:
return None
return self.contextstack.pop()
return None if self.Size() == 0 else self.contextstack.pop()
Copy link
Author

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:

Comment on lines -963 to +952
if self.Size() == 0:
return None
return self.contextstack[-1]
return None if self.Size() == 0 else self.contextstack[-1]
Copy link
Author

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:

Comment on lines -994 to +983
a = ""
for eachContext in self.contextstack:
a += eachContext.__str__() + " >> "
return a
return "".join(
f"{eachContext.__str__()} >> " for eachContext in self.contextstack
)
Copy link
Author

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:

Comment on lines -1018 to +1004
if len(self.contextstackstack) == 0:
return None
return self.contextstackstack[-1]
return None if len(self.contextstackstack) == 0 else self.contextstackstack[-1]
Copy link
Author

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:


##########################################################################
title = "nsiqcppstyle: N'SIQ Cpp Style ver " + version + "\n"
title = f"nsiqcppstyle: N'SIQ Cpp Style ver {version}" + "\n"
Copy link
Author

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:

Comment on lines -123 to +125
parser.add_argument("--version", action="version", version="%(prog)s " + version)
parser.add_argument(
"--version", action="version", version=f"%(prog)s {version}"
)
Copy link
Author

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:

Comment on lines -243 to +245
console.Out.Ci("= Analyzing %s " % targetName)
console.Out.Ci(f"= Analyzing {targetName} ")
Copy link
Author

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:

if object:
newtab = {}
for key, ritem in self.lexstatere.items():
newre = []
Copy link
Author

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:

Comment on lines -200 to +216
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()
}
Copy link
Author

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:

Comment on lines -228 to +226
filename = os.path.join(outputdir, basetabfilename) + ".py"
filename = f"{os.path.join(outputdir, basetabfilename)}.py"
Copy link
Author

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:

Comment on lines +236 to +241
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"]
Copy link
Author

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:

raise LexError(
f"Scanning error. Illegal character '{lexdata[lexpos]}'",
lexdata[lexpos:],
)
Copy link
Author

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:

return [(lexre, lexindexfunc)], [regex], [lexindexnames]
except Exception:
m = int(len(relist) / 2)
m = len(relist) // 2
Copy link
Author

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:

self.log = PlyLogger(sys.stderr)
else:
self.log = log
self.log = PlyLogger(sys.stderr) if log is None else log
Copy link
Author

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:

Comment on lines -685 to +682
if not (statetype == "inclusive" or statetype == "exclusive"):
if statetype not in ["inclusive", "exclusive"]:
Copy link
Author

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 in operator (merge-comparisons)

Comment on lines -713 to +710
if len(tsymbols) == 0:
if not tsymbols:
Copy link
Author

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:

Comment on lines -847 to +844
# Validate the error function
efunc = self.errorf.get(state, None)
if efunc:
if efunc := self.errorf.get(state, None):
Copy link
Author

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:

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"
Copy link
Author

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:

Comment on lines -88 to +92
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}")
Copy link
Author

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:

Comment on lines -48 to +51
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__)
Copy link
Author

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:

Comment on lines -57 to +55
if sys.platform == "win32":
return "window"
else:
return "linux"
return "window" if sys.platform == "win32" else "linux"
Copy link
Author

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:

Comment on lines -55 to +57
self.__expectTokenTypes("void FunctionName() " + specifier + ";", expectedTokenTypes)
self.__expectTokenTypes(
f"void FunctionName() {specifier};", expectedTokenTypes
)
Copy link
Author

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:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant