-
Notifications
You must be signed in to change notification settings - Fork 0
Sourcery refactored master branch #1
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
base: master
Are you sure you want to change the base?
Conversation
Sourcery Code Quality Report❌ Merging this PR will decrease code quality in the affected files by 0.90%.
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! |
e434e29
to
d0dd1ea
Compare
d0dd1ea
to
db1972d
Compare
data_path = os.getcwd() + "/data.json" | ||
data_path = f"{os.getcwd()}/data.json" |
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 9-9
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
@app.route(base_url + "/") | ||
@app.route(f"{base_url}/") |
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 all
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
@app.route(base_url + "/people/<int:t>") | ||
@app.route(f"{base_url}/people/<int:t>") | ||
def specific_id(t): | ||
with open (data_path, 'r') as f: | ||
user_data= json.load(f) | ||
return jsonify(error = None, message = "Object with ID %s is displayed" % t , data = user_data['data'][t-1]) | ||
return jsonify( | ||
error=None, | ||
message=f"Object with ID {t} is displayed", | ||
data=user_data['data'][t - 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 specific_id
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
) - Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
)
@app.route(base_url + "/people" , methods = ["POST","GET"]) | ||
@app.route(f"{base_url}/people", methods = ["POST","GET"]) | ||
def test(): | ||
if request.method == "POST": | ||
if request.method == "GET": | ||
with open(data_path, 'r') as f: | ||
user_data = json.load(f) | ||
#print (user_data) | ||
return jsonify({"error":None, "message":"Here is the required data", "data":user_data['data']}) | ||
elif request.method == "POST": | ||
a = request.json | ||
|
||
with open(data_path, 'r') as f: #'r' - shows that the file should be read | ||
user_data = json.load(f) #json.load - used to deserialize/decode(convert json to py) | ||
|
||
if len(a) == 0: | ||
return jsonify(error = "present", message = "empty json obj") | ||
return jsonify(error = "present", message = "empty json obj") | ||
if a in user_data['data']: | ||
return jsonify(error = "present", message = "duplication") | ||
else: | ||
if a in user_data['data']: | ||
return jsonify(error = "present", message = "duplication") | ||
else: | ||
user_data['data'].append(a) #append - used to add an info in the existing dict | ||
|
||
|
||
user_data['data'].append(a) #append - used to add an info in the existing dict | ||
|
||
|
||
with open(data_path,'w') as f: | ||
json.dump(user_data,f) #json.dump- used to serialize/encode(converting py to json) | ||
#json.dump is used to write data to a file.| json.dumps() is used to write to a python string | ||
# dump-converts dict of python to obj in json file.| dumps-converts dict obj of py to json string format | ||
return jsonify(error=None, message = "received sucesully") | ||
|
||
|
||
elif request.method == "GET": | ||
with open(data_path, 'r') as f: | ||
user_data = json.load(f) | ||
#print (user_data) | ||
return jsonify({"error":None, "message":"Here is the required data", "data":user_data['data']}) |
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
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
) - Simplify conditional into switch-like form [×3] (
switch
) - Remove unnecessary else after guard condition (
remove-unnecessary-else
)
@app.route(base_url + "/people/data/<int:i>" , methods = ["PUT" , "GET","DELETE"]) | ||
@app.route(f"{base_url}/people/data/<int:i>", methods = ["PUT" , "GET","DELETE"]) | ||
def user(i): | ||
if request.method == "PUT": | ||
request_data = request.json | ||
|
||
if request.method == "DELETE": | ||
with open(data_path , 'r') as f: | ||
user_data = json.load(f) | ||
|
||
user_data['data'][i-1].update(request_data) | ||
|
||
with open(data_path,'w') as f: | ||
json.dump(user_data,f) | ||
return jsonify(error = None, message = "Latest Obj Updated") | ||
#return jsonify(info = user_data['data'][i-1]) | ||
|
||
elif request.method == "DELETE": | ||
|
||
with open(data_path , 'r') as f: | ||
user_data = json.load(f) | ||
|
||
user_data['data'].pop(i-1) | ||
|
||
with open(data_path,'w') as f: | ||
json.dump(user_data,f) | ||
return jsonify(error = None, message = "Obj with ID %s is DELETED" % i ) | ||
#return jsonify(info = user_data['data'][i-1]) | ||
|
||
|
||
return jsonify(error = None, message=f"Obj with ID {i} is DELETED") | ||
elif request.method == "GET": | ||
with open(data_path , 'r') as f: | ||
user_data = json.load(f) | ||
return jsonify({"error":None, "message":"Here is the required data", "data":user_data['data']}) |
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 user
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
) - Simplify conditional into switch-like form [×3] (
switch
) - Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
)
This removes the following comments ( why? ):
#return jsonify(info = user_data['data'][i-1])
@app.route(base_url + "/people/count") | ||
@app.route(f"{base_url}/people/count") |
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 count
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
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:Help us improve this pull request!