Sourcery refactored master branch - #1
Conversation
|
|
||
| def __repr__(self): | ||
| return '<{}>'.format(getattr(self, '__name__', self.__class__.__name__)) | ||
| return f"<{getattr(self, '__name__', self.__class__.__name__)}>" |
There was a problem hiding this comment.
Function Thing.__repr__ refactored with the following changes:
- Replace call to format with f-string. (
use-fstring-for-formatting)
|
|
||
| def program(percept): | ||
| return eval(input('Percept={}; action? '.format(percept))) | ||
| return eval(input(f'Percept={percept}; action? ')) |
There was a problem hiding this comment.
Function Agent.__init__.program refactored with the following changes:
- Replace call to format with f-string. (
use-fstring-for-formatting)
| def new_program(percept): | ||
| action = old_program(percept) | ||
| print('{} perceives {} and does {}'.format(agent, percept, action)) | ||
| print(f'{agent} perceives {percept} and does {action}') |
There was a problem hiding this comment.
Function TraceAgent.new_program refactored with the following changes:
- Replace call to format with f-string. (
use-fstring-for-formatting)
| percepts.append(percept) | ||
| action = table.get(tuple(percepts)) | ||
| return action | ||
| return table.get(tuple(percepts)) |
There was a problem hiding this comment.
Function TableDrivenAgentProgram.program refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| action = rule.action | ||
| return action | ||
| return rule.action |
There was a problem hiding this comment.
Function SimpleReflexAgentProgram.program refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| print("Death by {} [-1000].".format(explorer[0].killed_by)) | ||
| print(f"Death by {explorer[0].killed_by} [-1000].") | ||
| else: | ||
| print("Explorer climbed out {}." | ||
| .format("with Gold [+1000]!" if Gold() not in self.things else "without Gold [+0]")) | ||
| print( | ||
| f'Explorer climbed out {"with Gold [+1000]!" if Gold() not in self.things else "without Gold [+0]"}.' | ||
| ) | ||
|
|
There was a problem hiding this comment.
Function WumpusEnvironment.is_done refactored with the following changes:
- Replace call to format with f-string. (
use-fstring-for-formatting)
| envs = [EnvFactory() for i in range(n)] | ||
| envs = [EnvFactory() for _ in range(n)] |
There was a problem hiding this comment.
Function compare_agents refactored with the following changes:
- Replace unused for index with underscore (
for-index-underscore)
|
|
||
| def __repr__(self): | ||
| return '<{}>'.format(getattr(self, '__name__', self.__class__.__name__)) | ||
| return f"<{getattr(self, '__name__', self.__class__.__name__)}>" |
There was a problem hiding this comment.
Function Thing.__repr__ refactored with the following changes:
- Replace call to format with f-string. (
use-fstring-for-formatting)
|
|
||
| def program(percept): | ||
| return eval(input('Percept={}; action? '.format(percept))) | ||
| return eval(input(f'Percept={percept}; action? ')) |
There was a problem hiding this comment.
Function Agent.__init__.program refactored with the following changes:
- Replace call to format with f-string. (
use-fstring-for-formatting)
| def new_program(percept): | ||
| action = old_program(percept) | ||
| print('{} perceives {} and does {}'.format(agent, percept, action)) | ||
| print(f'{agent} perceives {percept} and does {action}') |
There was a problem hiding this comment.
Function TraceAgent.new_program refactored with the following changes:
- Replace call to format with f-string. (
use-fstring-for-formatting)
| percepts.append(percept) | ||
| action = table.get(tuple(percepts)) | ||
| return action | ||
| return table.get(tuple(percepts)) |
There was a problem hiding this comment.
Function TableDrivenAgentProgram.program refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| action = rule.action | ||
| return action | ||
| return rule.action |
There was a problem hiding this comment.
Function SimpleReflexAgentProgram.program refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| action = rule.action | ||
| return action | ||
| return rule.action |
There was a problem hiding this comment.
Function ModelBasedReflexAgentProgram.program refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| for step in range(steps): | ||
| for _ in range(steps): |
There was a problem hiding this comment.
Function Environment.run refactored with the following changes:
- Replace unused for index with underscore (
for-index-underscore)
| print(" Thing to be removed: {} at {}".format(thing, thing.location)) | ||
| print(" from list: {}".format([(thing, thing.location) for thing in self.things])) | ||
| print(f" Thing to be removed: {thing} at {thing.location}") | ||
| print(f" from list: {[(thing, thing.location) for thing in self.things]}") |
There was a problem hiding this comment.
Function Environment.delete_thing refactored with the following changes:
- Replace call to format with f-string. (
use-fstring-for-formatting)
| return {v: self.curr_domains[v][0] | ||
| for v in self.variables if 1 == len(self.curr_domains[v])} | ||
| return { | ||
| v: self.curr_domains[v][0] | ||
| for v in self.variables | ||
| if len(self.curr_domains[v]) == 1 | ||
| } |
There was a problem hiding this comment.
Function CSP.infer_assignment refactored with the following changes:
- Ensure constant in comparison is on the right (
flip-comparison)
| if revised: | ||
| if not csp.curr_domains[Xi]: | ||
| return False, checks # CSP is inconsistent | ||
| if revised and not csp.curr_domains[Xi]: | ||
| return False, checks # CSP is inconsistent |
There was a problem hiding this comment.
Function AC4 refactored with the following changes:
- Merge nested if conditions (
merge-nested-ifs)
| var = select_unassigned_variable(assignment, csp) | ||
| for value in order_domain_values(var, assignment, csp): | ||
| if 0 == csp.nconflicts(var, value, assignment): | ||
| if csp.nconflicts(var, value, assignment) == 0: |
There was a problem hiding this comment.
Function backtracking_search.backtrack refactored with the following changes:
- Ensure constant in comparison is on the right (
flip-comparison)
| csp.assign(var, val, current) | ||
| # Now repeatedly choose a random conflicted variable and change it | ||
| for i in range(max_steps): | ||
| for _ in range(max_steps): |
There was a problem hiding this comment.
Function min_conflicts refactored with the following changes:
- Replace unused for index with underscore (
for-index-underscore)
|
|
||
| def tree_csp_solver(csp): | ||
| """[Figure 6.11]""" | ||
| assignment = {} |
There was a problem hiding this comment.
Function tree_csp_solver refactored with the following changes:
- Merge dictionary assignment with declaration (
merge-dict-assign) - Move assignment closer to its usage within a block (
move-assign-in-block)
| keep = False # Keep or remove val1 | ||
| for val2 in csp.domains[Xk]: | ||
| if csp.constraints(Xj, val1, Xk, val2): | ||
| # Found a consistent assignment for val1, keep it | ||
| keep = True | ||
| break | ||
|
|
||
| keep = any(csp.constraints(Xj, val1, Xk, val2) for val2 in csp.domains[Xk]) |
| if csp.constraints(Xj, parent_assignment, Xk, val) | ||
| ), | ||
| None, | ||
| ) |
| if assignment.get(var, '') == val: | ||
| ch = '*' | ||
| else: | ||
| ch = ' ' | ||
| ch = '*' if assignment.get(var, '') == val else ' ' |
There was a problem hiding this comment.
Function NQueensCSP.display refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp)
| _BGRID = [[[[_CELL() for x in _R3] for y in _R3] for bx in _R3] for by in _R3] | ||
| _BGRID = [[[[_CELL() for _ in _R3] for _ in _R3] for _ in _R3] for _ in _R3] |
There was a problem hiding this comment.
Lines 731-731 refactored with the following changes:
- Replace unused for index with underscore (
for-index-underscore)
| return SortedSet(to_do, key=lambda t: 1 / len([var for var in t[1].scope])) | ||
| return SortedSet(to_do, key=lambda t: 1 / len(list(t[1].scope))) |
There was a problem hiding this comment.
Function sat_up refactored with the following changes:
- Replace identity comprehension with call to collection constructor (
identity-comprehension)
| print("current state:") | ||
| game.display(state) | ||
| print("available moves: {}".format(game.actions(state))) | ||
| print(f"available moves: {game.actions(state)}") |
There was a problem hiding this comment.
Function query_player refactored with the following changes:
- Replace call to format with f-string. (
use-fstring-for-formatting)
|
|
||
| def __repr__(self): | ||
| return '<{}>'.format(self.__class__.__name__) | ||
| return f'<{self.__class__.__name__}>' |
There was a problem hiding this comment.
Function Game.__repr__ refactored with the following changes:
- Replace call to format with f-string. (
use-fstring-for-formatting)
| return self.utils[state] | ||
| else: | ||
| return -self.utils[state] | ||
| return self.utils[state] if player == 'MAX' else -self.utils[state] |
There was a problem hiding this comment.
Function Fig52Game.utility refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp)
| if player == 'MAX': | ||
| return self.utils[state] | ||
| else: | ||
| return -self.utils[state] | ||
| return self.utils[state] if player == 'MAX' else -self.utils[state] |
There was a problem hiding this comment.
Function Fig52Extended.utility refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp)
| board = [point.copy() for index in range(24)] | ||
| board = [point.copy() for _ in range(24)] |
There was a problem hiding this comment.
Function Backgammon.__init__ refactored with the following changes:
- Replace unused for index with underscore (
for-index-underscore)
Sourcery Code Quality Report✅ Merging this PR will increase code quality in the affected files by 0.33%.
Here are some functions in these files that still need a tune-up:
Legend and ExplanationThe emojis denote the absolute quality of the code:
The 👍 and 👎 indicate whether the quality has improved or gotten worse with this pull request. Please see our documentation here for details on how these metrics are calculated. We are actively working on this report - lots more documentation and extra metrics to come! Help us improve this quality report! |
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!