Repository navigation
Sourcery refactored master branch - #1
sourcery-ai[bot] wants to merge 1 commit into
Conversation
| write( " static const char " + self.master_table + | ||
| "[" + repr( self.total ) + "] =\n" ) | ||
| write((f" static const char {self.master_table}[{repr(self.total)}" + | ||
| "] =\n")) |
There was a problem hiding this comment.
Function StringTable.dump refactored with the following changes:
- Use f-string instead of string concatenation [×3] (
use-fstring-for-concatenation)
| write( "#define " + macro_name + " " + repr( len( sublist ) ) + "\n\n" ) | ||
| write(f"#define {macro_name} {repr(len(sublist))}" + "\n\n") | ||
|
|
||
| write( " /* Values are offsets into the `" + | ||
| self.master_table + "' table */\n\n" ) | ||
| write( " static const short " + table_name + | ||
| "[" + macro_name + "] =\n" ) | ||
| write(f" /* Values are offsets into the `{self.master_table}" + | ||
| "' table */\n\n") | ||
| write(f" static const short {table_name}[{macro_name}" + "] =\n") | ||
| write( " {\n" ) | ||
|
|
||
| line = " " | ||
| comma = "" | ||
| col = 0 | ||
|
|
||
| line = " " |
There was a problem hiding this comment.
Function StringTable.dump_sublist refactored with the following changes:
- Use f-string instead of string concatenation [×7] (
use-fstring-for-concatenation) - Move assignment closer to its usage within a block (
move-assign-in-block)
| line = margin + "+-" | ||
| if len( self.letter ) == 0: | ||
| line += "<NOLETTER>" | ||
| else: | ||
| line += self.letter | ||
|
|
||
| line = f"{margin}+-" | ||
| line += "<NOLETTER>" if len( self.letter ) == 0 else self.letter | ||
| if self.value: | ||
| line += " => " + repr( self.value ) | ||
| line += f" => {repr(self.value)}" |
There was a problem hiding this comment.
Function StringNode.dump_debug refactored with the following changes:
- Use f-string instead of string concatenation [×2] (
use-fstring-for-concatenation) - Replace if statement with if expression (
assign-if-exp)
| if len( self.letter ) > 0: | ||
| index += len( self.letter ) + 1 | ||
| else: | ||
| index += 2 | ||
|
|
||
| index += len( self.letter ) + 1 if len( self.letter ) > 0 else 2 |
There was a problem hiding this comment.
Function StringNode.locate refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp)
| write( " static const unsigned short " + encoding_name + | ||
| "[" + repr( len( encoding_list ) ) + "] =\n" ) | ||
| write(( | ||
| f" static const unsigned short {encoding_name}[{repr(len(encoding_list))}" | ||
| + "] =\n")) |
There was a problem hiding this comment.
Function dump_encoding refactored with the following changes:
- Use f-string instead of string concatenation [×3] (
use-fstring-for-concatenation)
| def get_markup( self, tag_name ): | ||
| def get_markup( self, tag_name ): | ||
| """return the DocMarkup corresponding to a given tag in a block""" | ||
| for m in self.markups: | ||
| if m.tag == string.lower( tag_name ): | ||
| return m | ||
| return None | ||
| return next( | ||
| (m for m in self.markups if m.tag == string.lower(tag_name)), None | ||
| ) |
There was a problem hiding this comment.
Function DocBlock.get_markup refactored with the following changes:
- Use the built-in function
nextinstead of a for-loop (use-next)
| def beautify_block( block ): | ||
| if block.content: | ||
| content_processor.reset() | ||
| def beautify_block( block ): | ||
| if not block.content: | ||
| return | ||
| content_processor.reset() | ||
|
|
||
| markups = content_processor.process_content( block.content ) | ||
| text = [] | ||
| first = 1 | ||
| markups = content_processor.process_content( block.content ) | ||
| text = [] | ||
| first = 1 | ||
|
|
||
| for markup in markups: | ||
| text.extend( markup.beautify( first ) ) | ||
| first = 0 | ||
| for markup in markups: | ||
| text.extend( markup.beautify( first ) ) | ||
| first = 0 | ||
|
|
||
| # now beautify the documentation "borders" themselves | ||
| lines = [" /*************************************************************************"] | ||
| for l in text: | ||
| lines.append( " *" + l ) | ||
| lines.append( " */" ) | ||
| # now beautify the documentation "borders" themselves | ||
| lines = [" /*************************************************************************"] | ||
| lines.extend(f" *{l}" for l in text) | ||
| lines.append( " */" ) | ||
|
|
||
| block.lines = lines | ||
| block.lines = lines |
There was a problem hiding this comment.
Function beautify_block refactored with the following changes:
- Add guard clause (
last-if-guard) - Replace a for append loop with list extend (
for-append-to-extend) - Use f-string instead of string concatenation (
use-fstring-for-concatenation)
|
|
||
|
|
||
| def main( argv ): | ||
| def main( argv ): |
There was a problem hiding this comment.
Function main refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation) - Use
withwhen opening file to ensure closure (ensure-file-closed)
| def add_identifier( self, name, block ): | ||
| def add_identifier( self, name, block ): | ||
| if self.identifiers.has_key( name ): | ||
| # duplicate name! | ||
| sys.stderr.write( \ | ||
| "WARNING: duplicate definition for '" + name + "' in " + \ | ||
| block.location() + ", previous definition in " + \ | ||
| self.identifiers[name].location() + "\n" ) | ||
| sys.stderr.write( | ||
| ( | ||
| f"WARNING: duplicate definition for '{name}' in {block.location()}, previous definition in {self.identifiers[name].location()}" | ||
| + "\n" | ||
| ) | ||
| ) |
There was a problem hiding this comment.
Function Formatter.add_identifier refactored with the following changes:
- Use f-string instead of string concatenation [×5] (
use-fstring-for-concatenation)
| def toc_dump( self, toc_filename = None, index_filename = None ): | ||
| output = None | ||
| if toc_filename: | ||
| output = open_output( toc_filename ) | ||
|
|
||
| def toc_dump( self, toc_filename = None, index_filename = None ): | ||
| output = open_output( toc_filename ) if toc_filename else None |
There was a problem hiding this comment.
Function Formatter.toc_dump refactored with the following changes:
- Move setting of default value for variable into
elsebranch (introduce-default-else) - Replace if statement with if expression (
assign-if-exp)
| output = open_output( index_filename ) | ||
|
|
||
| def index_dump( self, index_filename = None ): | ||
| output = open_output( index_filename ) if index_filename else None |
There was a problem hiding this comment.
Function Formatter.index_dump refactored with the following changes:
- Move setting of default value for variable into
elsebranch (introduce-default-else) - Replace if statement with if expression (
assign-if-exp)
| def section_dump( self, section, section_filename = None ): | ||
| output = None | ||
| if section_filename: | ||
| output = open_output( section_filename ) | ||
|
|
||
| def section_dump( self, section, section_filename = None ): | ||
| output = open_output( section_filename ) if section_filename else None |
There was a problem hiding this comment.
Function Formatter.section_dump refactored with the following changes:
- Move setting of default value for variable into
elsebranch (introduce-default-else) - Replace if statement with if expression (
assign-if-exp)
| class SourceBlock: | ||
|
|
||
| def __init__( self, processor, filename, lineno, lines ): | ||
| def __init__( self, processor, filename, lineno, lines ): |
There was a problem hiding this comment.
Function SourceBlock.__init__ refactored with the following changes:
- Use x is None rather than x == None (
none-compare) - Use named expression to simplify assignment and conditional (
use-named-expression)
| def location( self ): | ||
| return "(" + self.filename + ":" + repr( self.lineno ) + ")" | ||
| def location( self ): | ||
| return f"({self.filename}:{repr(self.lineno)})" |
There was a problem hiding this comment.
Function SourceBlock.location refactored with the following changes:
- Use f-string instead of string concatenation [×4] (
use-fstring-for-concatenation)
| def parse_file( self, filename ): | ||
| def parse_file( self, filename ): |
There was a problem hiding this comment.
Function SourceProcessor.parse_file refactored with the following changes:
- Replace a[0:x] with a[:x] and a[x:len(a)] with a[x:] (
remove-redundant-slice-index) - Merge else clause's nested if statement into elif (
merge-else-if-into-elif) - Use x is None rather than x == None (
none-compare)
| new_list = order_list[:] | ||
| for id in input_list: | ||
| if not id in order_list: | ||
| if id not in order_list: |
There was a problem hiding this comment.
Function sort_order_list refactored with the following changes:
- Simplify logical expression using De Morgan identities (
de-morgan)
| def check_output(): | ||
| def check_output(): | ||
| global output_dir | ||
| if output_dir: | ||
| if output_dir != "": | ||
| if not os.path.isdir( output_dir ): | ||
| sys.stderr.write( "argument" + " '" + output_dir + "' " + \ | ||
| "is not a valid directory" ) | ||
| sys.exit( 2 ) | ||
| else: | ||
| if output_dir == "": | ||
| output_dir = None | ||
|
|
||
| elif not os.path.isdir( output_dir ): | ||
| sys.stderr.write( "argument" + " '" + output_dir + "' " + \ | ||
| "is not a valid directory" ) | ||
| sys.exit( 2 ) |
There was a problem hiding this comment.
Function check_output refactored with the following changes:
- Swap if/else branches (
swap-if-else-branches) - Merge else clause's nested if statement into elif (
merge-else-if-into-elif)
| def make_file_list( args = None ): | ||
| def make_file_list( args = None ): |
There was a problem hiding this comment.
Function make_file_list refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp) - Simplify sequence length comparison (
simplify-len-comparison) - Inline variable that is immediately returned (
inline-immediately-returned-variable)
This removes the following comments ( why? ):
# now filter the file list to remove non-existing ones
|
|
||
| regs = [ ] | ||
| for i in range(0, n): | ||
| for _ in range(0, n): |
There was a problem hiding this comment.
Function alloc_regs refactored with the following changes:
- Replace unused for index with underscore (
for-index-underscore)
| l = [ ] | ||
| for i in range(0,8): | ||
| l.append(matrix[i*4+col]) | ||
| l = [matrix[i*4+col] for i in range(0,8)] |
There was a problem hiding this comment.
Function shuffle_column refactored with the following changes:
- Convert for loop into list comprehension (
list-comprehension)
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!