Skip to content

Sourcery refactored master branch#1

Open
sourcery-ai[bot] wants to merge 1 commit intomasterfrom
sourcery/master
Open

Sourcery refactored master branch#1
sourcery-ai[bot] wants to merge 1 commit intomasterfrom
sourcery/master

Conversation

@sourcery-ai
Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot commented May 28, 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 Deadstarjay62 May 28, 2023 19:18
Comment thread Credit_Card_Validator.py
Comment on lines -8 to +12
if c in [13, 15, 16]:
if c in {13, 15, 16}:
cnn = cn
while cnn > 9:
scn = str(cnn)
i = int(scn[-2])
i = i*2
i = int(scn[-2]) * 2
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 8-52 refactored with the following changes:

This removes the following comments ( why? ):

# Check for AMEX
# Check for MASTERCARD and VISA

Comment on lines -8 to +28
# Opens csv and dna files
file1 = open(argv[1], 'r')
file2 = open(argv[2], 'r')
read1 = csv.DictReader(file1)
fnames = read1.fieldnames
read1 = csv.reader(file1)
read2 = file2.read()
dictr = []
dnal = {}
# Creates a dictionary with csv data
for i in read1:
l = {}
for j in range(len(fnames)):
l[fnames[j]] = i[j]
dictr.append(l)
# Checks for matching STRs in DNA and takes count
for c in range(1, len(fnames)):
dnal[fnames[c]] = 0
for k in range(len(read2)):
count = 0
while fnames[c] == read2[k:(k+len(fnames[c]))]:
count += 1
k += len(fnames[c])
if dnal[fnames[c]] < count:
dnal[fnames[c]] = count
file1.close()
with open(argv[1], 'r') as file1:
file2 = open(argv[2], 'r')
read1 = csv.DictReader(file1)
fnames = read1.fieldnames
read1 = csv.reader(file1)
read2 = file2.read()
dictr = []
dnal = {}
# Creates a dictionary with csv data
for i in read1:
l = {fnames[j]: i[j] for j in range(len(fnames))}
dictr.append(l)
# Checks for matching STRs in DNA and takes count
for c in range(1, len(fnames)):
dnal[fnames[c]] = 0
for k in range(len(read2)):
count = 0
while fnames[c] == read2[k:(k+len(fnames[c]))]:
count += 1
k += len(fnames[c])
dnal[fnames[c]] = max(dnal[fnames[c]], count)
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 8-33 refactored with the following changes:

This removes the following comments ( why? ):

# Opens csv and dna files

Comment thread Guess_Game.py

name = input("What is your name?:")
print("Hello " + name + " ! Welcome to Guess the Number game!")
print(f"Hello {name} ! Welcome to Guess the Number game!")
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 5-22 refactored with the following changes:

Comment thread Mario_Pattern.py
Comment on lines -7 to +14

for i in range(height):
for j in range(height - i - 1):
for _ in range(height - i - 1):
print(" ", end="")
for j in range(i + 1):
for _ in range(i + 1):
print("#", end="")
print(" ", end="")
for j in range(i + 1):
for _ in range(i + 1):
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 7-14 refactored with the following changes:

Comment thread Serialmonitor.py
Comment on lines -8 to +15
try:
c = si.readline().decode('ascii')
if c:
print(c)
sleep(1)
try:
if c := si.readline().decode('ascii'):
print(c)
sleep(1)

except Exception as e:
print("Error: ", e)
sleep(5)
except Exception as e:
print("Error: ", e)
sleep(5)
Copy link
Copy Markdown
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:

Comment thread non-regexp.py
if not num[i].isdecimal():
return False
return True
return all(num[i].isdecimal() for i in range(8, 12))
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function isPhoneNumber refactored with the following changes:

Comment thread tiny_blockchain.py
new_index = last_block.index + 1
new_timestamp = dt.datetime.now()
new_data = "This is block " + str(new_index)
new_data = f"This is block {str(new_index)}"
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function next_block refactored with the following changes:

Comment thread tiny_blockchain.py
Comment on lines -35 to +40
for i in range(num):
for _ in range(num):
block_to_add = next_block(prev_block)
myblockchain.append(block_to_add)
prev_block = block_to_add
print("Block #{} has been added to your blockchain".format(prev_block.index))
print("Hash: {}\n".format(prev_block.hash))
print(f"Block #{prev_block.index} has been added to your blockchain")
print(f"Hash: {prev_block.hash}\n")
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 35-40 refactored with the following changes:

Comment thread Houses_db/Import_Data.py
Comment on lines -8 to +21
# Opens csv file in read mode
file = open(argv[1], 'r')
# Reads data in csv into a list of dictionaries
read = csv.DictReader(file)
# Sets up db connection
db = SQL("sqlite:///students.db")
# Stores data in dictionary into db
for row in read:
n = row['name'].split()
if len(n) == 2:
db.execute("INSERT INTO students (first, middle, last, house, birth) VALUES (?,?,?,?,?)",
n[0], None, n[1], row['house'], row['birth'])
else:
db.execute("INSERT INTO students (first, middle, last, house, birth) VALUES (?,?,?,?,?)",
n[0], n[1], n[2], row['house'], row['birth'])
file.close()
with open(argv[1], 'r') as file:
# Reads data in csv into a list of dictionaries
read = csv.DictReader(file)
# Sets up db connection
db = SQL("sqlite:///students.db")
# Stores data in dictionary into db
for row in read:
n = row['name'].split()
if len(n) == 2:
db.execute("INSERT INTO students (first, middle, last, house, birth) VALUES (?,?,?,?,?)",
n[0], None, n[1], row['house'], row['birth'])
else:
db.execute("INSERT INTO students (first, middle, last, house, birth) VALUES (?,?,?,?,?)",
n[0], n[1], n[2], row['house'], row['birth'])
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 8-23 refactored with the following changes:

This removes the following comments ( why? ):

# Opens csv file in read mode

Comment thread Houses_db/Roster.py
Comment on lines -11 to +13
# Displays required data
# Displays required data
for a in s:
if a['middle'] == None:
if a['middle'] is None:
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 11-13 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.

0 participants