-
Notifications
You must be signed in to change notification settings - Fork 5
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
Sourcery Starbot ⭐ refactored programmer290399/pyqna #22
base: main
Are you sure you want to change the base?
Conversation
extra_deps["all"] = set(vv for v in extra_deps.values() for vv in v) | ||
extra_deps["all"] = {vv for v in extra_deps.values() for vv in v} |
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_extra_requires
refactored with the following changes:
- Replace list(), dict() or set() with comprehension (
collection-builtin-to-comprehension
)
python_requires=">={}".format(".".join(str(n) for n in min_version)), | ||
python_requires=f'>={".".join(str(n) for n in min_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.
Lines 75-75
refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting
)
"Warning: build in %s is using versioneer.py from %s" | ||
% (os.path.dirname(me), versioneer_py) | ||
f"Warning: build in {os.path.dirname(me)} is using versioneer.py from {versioneer_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 get_root
refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
)
print("unable to run %s" % dispcmd) | ||
print(f"unable to run {dispcmd}") | ||
print(e) | ||
return None, None | ||
else: | ||
if verbose: | ||
print("unable to find command, tried %s" % (commands,)) | ||
print(f"unable to find command, tried {commands}") | ||
return None, None | ||
stdout = p.communicate()[0].strip() | ||
if sys.version_info[0] >= 3: | ||
stdout = stdout.decode() | ||
if p.returncode != 0: | ||
if verbose: | ||
print("unable to run %s (error)" % dispcmd) | ||
print("stdout was %s" % stdout) | ||
print(f"unable to run {dispcmd} (error)") | ||
print(f"stdout was {stdout}") |
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 run_command
refactored with the following changes:
- Replace interpolated string formatting with f-string [×4] (
replace-interpolation-with-fstring
)
f = open(versionfile_abs, "r") | ||
for line in f.readlines(): | ||
if line.strip().startswith("git_refnames ="): | ||
mo = re.search(r'=\s*"(.*)"', line) | ||
if mo: | ||
keywords["refnames"] = mo.group(1) | ||
if line.strip().startswith("git_full ="): | ||
mo = re.search(r'=\s*"(.*)"', line) | ||
if mo: | ||
keywords["full"] = mo.group(1) | ||
if line.strip().startswith("git_date ="): | ||
mo = re.search(r'=\s*"(.*)"', line) | ||
if mo: | ||
keywords["date"] = mo.group(1) | ||
f.close() | ||
with open(versionfile_abs, "r") as f: | ||
for line in f: | ||
if line.strip().startswith("git_refnames ="): | ||
if mo := re.search(r'=\s*"(.*)"', line): | ||
keywords["refnames"] = mo[1] | ||
if line.strip().startswith("git_full ="): | ||
if mo := re.search(r'=\s*"(.*)"', line): | ||
keywords["full"] = mo[1] | ||
if line.strip().startswith("git_date ="): | ||
if mo := re.search(r'=\s*"(.*)"', line): | ||
keywords["date"] = mo[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 git_get_keywords
refactored with the following changes:
- Use
with
when opening file to ensure closure (ensure-file-closed
) - Iterate over files directly rather than using readlines() (
use-file-iterator
) - Use named expression to simplify assignment and conditional [×3] (
use-named-expression
) - Replace m.group(x) with m[x] for re.Match objects [×3] (
use-getitem-for-re-match-groups
)
raise ValueError("unknown style '%s'" % style) | ||
raise ValueError(f"unknown style '{style}'") |
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 render
refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
)
assert handlers, "unrecognized VCS '%s'" % cfg.VCS | ||
assert handlers, f"unrecognized VCS '{cfg.VCS}'" |
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_versions
refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression
) - Replace interpolated string formatting with f-string [×5] (
replace-interpolation-with-fstring
)
cmds = {} | ||
|
||
# we add "version" to both distutils and setuptools | ||
from distutils.core import Command | ||
|
||
|
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_cmdclass
refactored with the following changes:
- Move assignment closer to its usage within a block [×2] (
move-assign-in-block
) - Replace interpolated string formatting with f-string [×9] (
replace-interpolation-with-fstring
) - Merge dictionary assignment with declaration [×2] (
merge-dict-assign
)
This removes the following comments ( why? ):
# "version": versioneer.get_version().split("+", 1)[0], # FILEVERSION
# nczeczulin reports that py2exe won't like the pep440-style string
# as FILEVERSION, but it can be used for PRODUCTVERSION, e.g.
# "product_version": versioneer.get_version(),
# ...
# setup(console=[{
print(" creating %s" % cfg.versionfile_source) | ||
print(f" creating {cfg.versionfile_source}") |
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 do_setup
refactored with the following changes:
- Replace interpolated string formatting with f-string [×5] (
replace-interpolation-with-fstring
)
for line in f.readlines(): | ||
for line in f: |
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 scan_setup_py
refactored with the following changes:
- Iterate over files directly rather than using readlines() (
use-file-iterator
)
keywords = {"refnames": git_refnames, "full": git_full, "date": git_date} | ||
return keywords | ||
return {"refnames": git_refnames, "full": git_full, "date": git_date} |
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_keywords
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
print("unable to run %s" % dispcmd) | ||
print(f"unable to run {dispcmd}") | ||
print(e) | ||
return None, None | ||
else: | ||
if verbose: | ||
print("unable to find command, tried %s" % (commands,)) | ||
print(f"unable to find command, tried {commands}") | ||
return None, None | ||
stdout = p.communicate()[0].strip() | ||
if sys.version_info[0] >= 3: | ||
stdout = stdout.decode() | ||
if p.returncode != 0: | ||
if verbose: | ||
print("unable to run %s (error)" % dispcmd) | ||
print("stdout was %s" % stdout) | ||
print(f"unable to run {dispcmd} (error)") | ||
print(f"stdout was {stdout}") |
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 run_command
refactored with the following changes:
- Replace interpolated string formatting with f-string [×4] (
replace-interpolation-with-fstring
)
for i in range(3): | ||
for _ in range(3): |
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 versions_from_parentdir
refactored with the following changes:
- Replace unused for index with underscore (
for-index-underscore
) - Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
) - Remove unnecessary else after guard condition (
remove-unnecessary-else
) - Remove unnecessary calls to
str()
from formatted values in f-strings (remove-str-from-fstring
)
f = open(versionfile_abs, "r") | ||
for line in f.readlines(): | ||
if line.strip().startswith("git_refnames ="): | ||
mo = re.search(r'=\s*"(.*)"', line) | ||
if mo: | ||
keywords["refnames"] = mo.group(1) | ||
if line.strip().startswith("git_full ="): | ||
mo = re.search(r'=\s*"(.*)"', line) | ||
if mo: | ||
keywords["full"] = mo.group(1) | ||
if line.strip().startswith("git_date ="): | ||
mo = re.search(r'=\s*"(.*)"', line) | ||
if mo: | ||
keywords["date"] = mo.group(1) | ||
f.close() | ||
with open(versionfile_abs, "r") as f: | ||
for line in f: | ||
if line.strip().startswith("git_refnames ="): | ||
if mo := re.search(r'=\s*"(.*)"', line): | ||
keywords["refnames"] = mo[1] | ||
if line.strip().startswith("git_full ="): | ||
if mo := re.search(r'=\s*"(.*)"', line): | ||
keywords["full"] = mo[1] | ||
if line.strip().startswith("git_date ="): | ||
if mo := re.search(r'=\s*"(.*)"', line): | ||
keywords["date"] = mo[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 git_get_keywords
refactored with the following changes:
- Use
with
when opening file to ensure closure (ensure-file-closed
) - Iterate over files directly rather than using readlines() (
use-file-iterator
) - Use named expression to simplify assignment and conditional [×3] (
use-named-expression
) - Replace m.group(x) with m[x] for re.Match objects [×3] (
use-getitem-for-re-match-groups
)
refs = set([r.strip() for r in refnames.strip("()").split(",")]) | ||
refs = {r.strip() for r in refnames.strip("()").split(",")} | ||
# starting in git-1.8.3, tags are listed as "tag: foo-1.0" instead of | ||
# just "foo-1.0". If we see a "tag: " prefix, prefer those. | ||
TAG = "tag: " | ||
tags = set([r[len(TAG) :] for r in refs if r.startswith(TAG)]) | ||
tags = {r[len(TAG) :] for r in refs if r.startswith(TAG)} |
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 git_versions_from_keywords
refactored with the following changes:
- Replace list(), dict() or set() with comprehension [×3] (
collection-builtin-to-comprehension
) - Replace unneeded comprehension with generator [×3] (
comprehension-to-generator
) - Replace interpolated string formatting with f-string [×3] (
replace-interpolation-with-fstring
)
if pieces["dirty"]: | ||
rendered += ".dev0" | ||
else: | ||
# exception #1 | ||
rendered = "0.post%d" % pieces["distance"] | ||
if pieces["dirty"]: | ||
rendered += ".dev0" | ||
if pieces["dirty"]: | ||
rendered += ".dev0" |
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 render_pep440_old
refactored with the following changes:
- Hoist conditional out of nested conditional (
hoist-if-from-if
) - Hoist repeated code outside conditional statement (
hoist-statement-from-if
)
raise ValueError("unknown style '%s'" % style) | ||
raise ValueError(f"unknown style '{style}'") |
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 render
refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
)
for i in cfg.versionfile_source.split("/"): | ||
for _ in cfg.versionfile_source.split("/"): |
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_versions
refactored with the following changes:
- Replace unused for index with underscore (
for-index-underscore
)
@@ -60,7 +60,6 @@ def _infer_from_model(self, context: str, question: str) -> Dict: | |||
Infer the answer from the model. One question at a time. | |||
""" | |||
|
|||
ret_val = dict() |
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 TransformerQnAModel._infer_from_model
refactored with the following changes:
- Move assignment closer to its usage within a block (
move-assign-in-block
) - Replace
dict()
with{}
(dict-literal
) - Merge dictionary assignment with declaration (
merge-dict-assign
)
@@ -1,3 +1,2 @@ | |||
def test_one_plus_one_is_two(): | |||
"Check that one and one are indeed two." | |||
assert 1 + 1 == 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 test_one_plus_one_is_two
refactored with the following changes:
- Remove
assert True
statements (remove-assert-true
) - Simplify numeric comparison (
simplify-numeric-comparison
) - Simplify x == x -> True and x != x -> False (
equality-identity
)
Thanks for starring sourcery-ai/sourcery ✨ 🌟 ✨
Here's your pull request refactoring your most popular Python repo.
If you want Sourcery to refactor all your Python repos and incoming pull requests install our bot.
Review changes via command line
To manually merge these changes, make sure you're on the
main
branch, then run: