Sourcery refactored main branch - #1
Conversation
| ) | ||
| args = parser.parse_args() | ||
| return args | ||
| return parser.parse_args() |
There was a problem hiding this comment.
Function parse_args refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| model = model_cls.from_config(model_config).to('cuda:{}'.format(args.gpu_id)) | ||
| model = model_cls.from_config(model_config).to(f'cuda:{args.gpu_id}') |
There was a problem hiding this comment.
Lines 65-76 refactored with the following changes:
- Replace call to format with f-string [×3] (
use-fstring-for-formatting)
| ) | ||
| args = parser.parse_args() | ||
| return args | ||
| return parser.parse_args() |
There was a problem hiding this comment.
Function parse_args refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| device = 'cuda:{}'.format(args.gpu_id) | ||
| device = f'cuda:{args.gpu_id}' |
There was a problem hiding this comment.
Lines 58-58 refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting)
| substrings = [match for match in matches] | ||
|
|
||
| return substrings | ||
| return list(matches) |
There was a problem hiding this comment.
Function extract_substrings refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable) - Replace identity comprehension with call to collection constructor (
identity-comprehension)
| return opts | ||
|
|
||
| return [(opt + "=" + value) for opt, value in zip(opts[0::2], opts[1::2])] | ||
| return [f"{opt}={value}" for opt, value in zip(opts[::2], opts[1::2])] |
There was a problem hiding this comment.
Function Config._convert_to_dot_list refactored with the following changes:
- Use f-string instead of string concatenation [×2] (
use-fstring-for-concatenation) - Replace a[0:x] with a[:x] and a[x:len(a)] with a[x:] (
remove-redundant-slice-index)
| # description + key-value pair string for each argument | ||
| help_msg = str(self.description) | ||
| return help_msg + ", available arguments: " + self.format_arguments() | ||
| return f"{help_msg}, available arguments: {self.format_arguments()}" |
There was a problem hiding this comment.
Function ConfigValidator.format_help refactored with the following changes:
- Use f-string instead of string concatenation [×2] (
use-fstring-for-concatenation)
| help="Learning rate scheduler to use, from {}".format(lr_scheds_choices), | ||
| help=f"Learning rate scheduler to use, from {lr_scheds_choices}", | ||
| ) | ||
| task_choices = registry.list_tasks() | ||
| validator.add_argument( | ||
| "task", | ||
| type=str, | ||
| choices=task_choices, | ||
| help="Task to use, from {}".format(task_choices), | ||
| help=f"Task to use, from {task_choices}", |
There was a problem hiding this comment.
Function create_runner_config_validator refactored with the following changes:
- Replace call to format with f-string [×2] (
use-fstring-for-formatting)
| if not dist.is_initialized(): | ||
| return False | ||
| return True | ||
| return False if not dist.is_available() else bool(dist.is_initialized()) |
There was a problem hiding this comment.
Function is_dist_avail_and_initialized refactored with the following changes:
- Lift code into else after jump in control flow [×2] (
reintroduce-else) - Replace if statement with if expression [×2] (
assign-if-exp) - Simplify boolean if expression (
boolean-if-exp-identity)
| if not is_dist_avail_and_initialized(): | ||
| return 1 | ||
| return dist.get_world_size() | ||
| return 1 if not is_dist_avail_and_initialized() else dist.get_world_size() |
There was a problem hiding this comment.
Function get_world_size 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 not is_dist_avail_and_initialized(): | ||
| return 0 | ||
| return dist.get_rank() | ||
| return 0 if not is_dist_avail_and_initialized() else dist.get_rank() |
There was a problem hiding this comment.
Function get_rank 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)
| "| distributed init (rank {}, world {}): {}".format( | ||
| args.rank, args.world_size, args.dist_url | ||
| ), | ||
| f"| distributed init (rank {args.rank}, world {args.world_size}): {args.dist_url}", |
There was a problem hiding this comment.
Function init_distributed_mode refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting)
| [conv.append_message( | ||
| conv.roles[0], '<Img><ImageHere></Img> {}'.format(text)) for conv, text in zip(convs, texts)] | ||
| [ | ||
| conv.append_message(conv.roles[0], f'<Img><ImageHere></Img> {text}') | ||
| for conv, text in zip(convs, texts) | ||
| ] |
There was a problem hiding this comment.
Function prepare_texts refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting)
| iou = intersection_area / union_area | ||
| return iou | ||
| return intersection_area / union_area |
There was a problem hiding this comment.
Function computeIoU refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| return self.__dict__[attr] | ||
| raise AttributeError( | ||
| "'{}' object has no attribute '{}'".format(type(self).__name__, attr) | ||
| f"'{type(self).__name__}' object has no attribute '{attr}'" |
There was a problem hiding this comment.
Function MetricLogger.__getattr__ refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting)
| size_in_mb = os.path.getsize(filename) / float(1024**2) | ||
| return size_in_mb | ||
| return os.path.getsize(filename) / float(1024**2) |
There was a problem hiding this comment.
Function get_file_size refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| self.qqa = {} | ||
| self.imgToQA = {} | ||
| if not annotation_file == None and not question_file == None: | ||
| if annotation_file is not None and question_file is not None: |
There was a problem hiding this comment.
Function VQA.__init__ refactored with the following changes:
- Simplify logical expression using De Morgan identities [×2] (
de-morgan) - Use x is None rather than x == None [×2] (
none-compare)
| """ | ||
| for key, value in self.datset["info"].items(): | ||
| print("%s: %s" % (key, value)) | ||
| print(f"{key}: {value}") |
There was a problem hiding this comment.
Function VQA.info refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring)
| if not len(imgIds) == 0: | ||
| if len(imgIds) != 0: | ||
| anns = sum( | ||
| [self.imgToQA[imgId] for imgId in imgIds if imgId in self.imgToQA], | ||
| ( | ||
| self.imgToQA[imgId] | ||
| for imgId in imgIds | ||
| if imgId in self.imgToQA | ||
| ), |
There was a problem hiding this comment.
Function VQA.getQuesIds refactored with the following changes:
- Replace unneeded comprehension with generator (
comprehension-to-generator) - Inline variable that is immediately returned (
inline-immediately-returned-variable) - Simplify logical expression using De Morgan identities (
de-morgan)
| if not len(quesIds) == 0: | ||
| anns = sum( | ||
| [self.qa[quesId] for quesId in quesIds if quesId in self.qa], [] | ||
| ) | ||
| if len(quesIds) != 0: | ||
| anns = sum((self.qa[quesId] for quesId in quesIds if quesId in self.qa), []) |
There was a problem hiding this comment.
Function VQA.getImgIds refactored with the following changes:
- Replace unneeded comprehension with generator (
comprehension-to-generator) - Inline variable that is immediately returned (
inline-immediately-returned-variable) - Simplify logical expression using De Morgan identities (
de-morgan)
| for ann in anns: | ||
| quesId = ann["question_id"] | ||
| print("Question: %s" % (self.qqa[quesId]["question"])) | ||
| print(f'Question: {self.qqa[quesId]["question"]}') |
There was a problem hiding this comment.
Function VQA.showQA refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring)
| if quesIds == None: | ||
| quesIds = [quesId for quesId in self.params["question_id"]] | ||
| if quesIds is None: | ||
| quesIds = list(self.params["question_id"]) |
There was a problem hiding this comment.
Function VQAEval.evaluate refactored with the following changes:
- Use x is None rather than x == None (
none-compare) - Replace identity comprehension with call to collection constructor (
identity-comprehension)
| if (p + " " in inText or " " + p in inText) or ( | ||
| re.search(self.commaStrip, inText) != None | ||
| if ( | ||
| f"{p} " in inText | ||
| or f" {p}" in inText | ||
| or re.search(self.commaStrip, inText) != None |
There was a problem hiding this comment.
Function VQAEval.processPunctuation refactored with the following changes:
- Use f-string instead of string concatenation [×2] (
use-fstring-for-concatenation)
| else: | ||
| pass | ||
| for wordId, word in enumerate(outText): | ||
| if word in self.contractions: | ||
| outText[wordId] = self.contractions[word] | ||
| outText = " ".join(outText) | ||
| return outText | ||
| return " ".join(outText) |
There was a problem hiding this comment.
Function VQAEval.processDigitArticle refactored with the following changes:
- Remove redundant pass statement (
remove-redundant-pass) - Inline variable that is immediately returned (
inline-immediately-returned-variable)
| if quesIds == None: | ||
| quesIds = [quesId for quesId in self.params['question_id']] | ||
| if quesIds is None: | ||
| quesIds = list(self.params['question_id']) |
There was a problem hiding this comment.
Function VQAEval.evaluate refactored with the following changes:
- Use x is None rather than x == None (
none-compare) - Replace identity comprehension with call to collection constructor (
identity-comprehension)
| msg = "Received." | ||
|
|
||
| return msg | ||
| return "Received." |
There was a problem hiding this comment.
Function Chat.upload_img refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| ), "Do not support multiple {} datasets.".format(split_name) | ||
| ), f"Do not support multiple {split_name} datasets." | ||
| datasets[split_name] = datasets[split_name][0] | ||
| else: | ||
| iterable_datasets, map_datasets = [], [] | ||
| for dataset in datasets[split_name]: | ||
| if isinstance(dataset, wds.DataPipeline): | ||
| logging.info( | ||
| "Dataset {} is IterableDataset, can't be concatenated.".format( | ||
| dataset | ||
| ) | ||
| ) | ||
| logging.info(f"Dataset {dataset} is IterableDataset, can't be concatenated.") |
There was a problem hiding this comment.
Function concat_datasets refactored with the following changes:
- Replace call to format with f-string [×2] (
use-fstring-for-formatting) - Simplify sequence length comparison (
simplify-len-comparison) - Replace unneeded comprehension with generator (
comprehension-to-generator)
| else: | ||
| cfg = load_dataset_config(cfg_path) | ||
|
|
||
| cfg = None if cfg_path is None else load_dataset_config(cfg_path) |
There was a problem hiding this comment.
Function load_dataset refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp) - Inline variable that is immediately returned (
inline-immediately-returned-variable)
| datasets = self.build() # dataset['train'/'val'/'test'] | ||
|
|
||
| return datasets | ||
| return self.build() |
There was a problem hiding this comment.
Function BaseDatasetBuilder.build_datasets refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
This removes the following comments ( why? ):
# dataset['train'/'val'/'test']
| logging.info("Using existing file {}.".format(dst)) | ||
| logging.info(f"Using existing file {dst}.") | ||
| else: | ||
| if os.path.isdir(storage_path): | ||
| # if only dirname is provided, suffix with basename of URL. | ||
| raise ValueError( | ||
| "Expecting storage_path to be a file path, got directory {}".format( | ||
| storage_path | ||
| ) | ||
| f"Expecting storage_path to be a file path, got directory {storage_path}" |
There was a problem hiding this comment.
Function BaseDatasetBuilder._download_ann refactored with the following changes:
- Replace call to format with f-string [×2] (
use-fstring-for-formatting)
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!