-
Notifications
You must be signed in to change notification settings - Fork 0
Sourcery refactored main 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: main
Are you sure you want to change the base?
Conversation
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.
Due to GitHub API limits, only the first 60 comments can be shown.
if ( uname == None and passwd == None): | ||
if uname is None and passwd is None: | ||
return {"message" : "invalid user"} | ||
elif not valid_users.get(uname) == None: | ||
elif valid_users.get(uname) is not None: |
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 signup
refactored with the following changes:
- Use x is None rather than x == None [×3] (
none-compare
) - Simplify logical expression using De Morgan identities (
de-morgan
)
if not valid_users.get(user.username) == None: | ||
if valid_users.get(user.username) is not None: | ||
return ValidUser(id=None, username = None, password = None, passphrase = None) | ||
else: | ||
valid_user = ValidUser(id=uuid1(), username= user.username, password = user.password, passphrase = hashpw(user.password.encode(),gensalt())) | ||
valid_users[user.username] = valid_user | ||
del pending_users[user.username] | ||
return valid_user | ||
valid_user = ValidUser(id=uuid1(), username= user.username, password = user.password, passphrase = hashpw(user.password.encode(),gensalt())) | ||
valid_users[user.username] = valid_user | ||
del pending_users[user.username] | ||
return valid_user |
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 approve_user
refactored with the following changes:
- Swap if/else branches [×2] (
swap-if-else-branches
) - Remove unnecessary else after guard condition (
remove-unnecessary-else
) - Simplify logical expression using De Morgan identities (
de-morgan
) - Use x is None rather than x == None (
none-compare
)
if username == None: | ||
if username is None: | ||
return {"message": "invalid user"} | ||
else: | ||
del valid_users[username] | ||
return {"message": "deleted user"} | ||
del valid_users[username] | ||
return {"message": "deleted user"} |
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 delete_user
refactored with the following changes:
- Remove unnecessary else after guard condition (
remove-unnecessary-else
) - Use x is None rather than x == None (
none-compare
)
if valid_users.get(username) == None: | ||
if valid_users.get(username) is None: | ||
return {"message": "user does not exist"} | ||
else: | ||
user = valid_users.get(username) | ||
if checkpw(password.encode(), user.passphrase.encode()): | ||
return user | ||
else: | ||
return {"message": "invalid user"} | ||
user = valid_users.get(username) | ||
return ( | ||
user | ||
if checkpw(password.encode(), user.passphrase.encode()) | ||
else {"message": "invalid user"} | ||
) |
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 login
refactored with the following changes:
- Remove unnecessary else after guard condition (
remove-unnecessary-else
) - Use x is None rather than x == None (
none-compare
) - Replace if statement with if expression (
assign-if-exp
)
if valid_users.get(username) == None: | ||
if valid_users.get(username) is None: | ||
return {"message": "user does not exist"} | ||
elif old_passw == '' or new_passw == '': | ||
elif not old_passw or not new_passw: | ||
characters = ascii_lowercase | ||
temporary_passwd = ''.join(random.choice(characters) for i in range(passwd_len)) | ||
temporary_passwd = ''.join( | ||
random.choice(characters) for _ in range(passwd_len) | ||
) |
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 change_password
refactored with the following changes:
- Use x is None rather than x == None (
none-compare
) - Replaces an empty collection equality with a boolean operation [×2] (
simplify-empty-collection-comparison
) - Replace unused for index with underscore (
for-index-underscore
)
if valid_users.get(username) == None: | ||
if valid_users.get(username) is None: | ||
return {"message": "user does not exist"} | ||
elif discussion_posts.get(id) == None: | ||
elif discussion_posts.get(id) is None: |
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 delete_discussion
refactored with the following changes:
- Use x is None rather than x == None [×2] (
none-compare
)
if valid_users.get(username) == None: | ||
if valid_users.get(username) is None: | ||
return {"message": "user does not exist"} | ||
elif discussion_posts.get(id) == None: | ||
elif discussion_posts.get(id) is None: | ||
return {"message": "post does not exist"} | ||
else: | ||
forum = discussion_posts[id] | ||
return forum | ||
return discussion_posts[id] |
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 view_discussion
refactored with the following changes:
- Use x is None rather than x == None [×2] (
none-compare
) - Inline variable that is immediately returned (
inline-immediately-returned-variable
)
tour = Tour(id=tid, name=input.name, city=input.city, country=input.country, type=input.type, location=input.location, | ||
amenities=input.amenities, feedbacks=list(), ratings=0.0, visits=0, isBooked=False) | ||
tour = Tour( | ||
id=tid, | ||
name=input.name, | ||
city=input.city, | ||
country=input.country, | ||
type=input.type, | ||
location=input.location, | ||
amenities=input.amenities, | ||
feedbacks=[], | ||
ratings=0.0, | ||
visits=0, | ||
isBooked=False, | ||
) |
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 add_tour_destination
refactored with the following changes:
- Replace
list()
with[]
(list-literal
)
if approved_users.get(touristId) == None and tours.get(tid) == None: | ||
if approved_users.get(touristId) is None and tours.get(tid) is None: | ||
raise PostFeedbackException(detail='tourist and tour details invalid', status_code=403) | ||
assessId = uuid1() | ||
assessment = Assessment(id=assessId, post=post, tour_id= tid, tourist_id=touristId) | ||
assessment = Assessment(id=assessId, post=post, tour_id= tid, tourist_id=touristId) | ||
feedback_tour[assessId] = assessment | ||
tours[tid].ratings = (tours[tid].ratings + post.rating)/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 post_tourist_feedback
refactored with the following changes:
- Use x is None rather than x == None [×2] (
none-compare
)
if feedback_tour.get(assessId) == None: | ||
if feedback_tour.get(assessId) is None: |
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 update_tour_rating
refactored with the following changes:
- Use x is None rather than x == None (
none-compare
)
if approved_users.get(touristId) == None and feedback_tour.get(assessId): | ||
if approved_users.get(touristId) is None and feedback_tour.get(assessId): |
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 delete_tourist_feedback
refactored with the following changes:
- Use x is None rather than x == None (
none-compare
)
tourist = Tourist(id=userid, login=login, date_signed=datetime.now(), booked=0, tours=list() ) | ||
tourist = Tourist( | ||
id=userid, | ||
login=login, | ||
date_signed=datetime.now(), | ||
booked=0, | ||
tours=[], | ||
) |
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 signup
refactored with the following changes:
- Replace
list()
with[]
(list-literal
)
tourist_list = [ tourist for tourist in approved_users.values() if tourist['login']['username'] == username and tourist['login']['password'] == password] | ||
if len(tourist_list) == 0 or tourist_list == None: | ||
tourist_list = [ tourist for tourist in approved_users.values() if tourist['login']['username'] == username and tourist['login']['password'] == password] | ||
if not tourist_list or tourist_list is None: | ||
return JSONResponse(content={"message": "invalid operation"}, status_code=status.HTTP_403_FORBIDDEN) | ||
else: | ||
tourist = tourist_list[0] | ||
tour_json = jsonable_encoder(tourist) | ||
bg_task.add_task(audit_log_transaction, touristId=str(tourist['login']['id']), message="login") | ||
return JSONResponse(content=tour_json, status_code=status.HTTP_200_OK) | ||
tourist = tourist_list[0] | ||
tour_json = jsonable_encoder(tourist) | ||
bg_task.add_task(audit_log_transaction, touristId=str(tourist['login']['id']), message="login") | ||
return JSONResponse(content=tour_json, status_code=status.HTTP_200_OK) |
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 login
refactored with the following changes:
- Remove unnecessary else after guard condition (
remove-unnecessary-else
) - Simplify sequence length comparison (
simplify-len-comparison
) - Use x is None rather than x == None (
none-compare
)
if tours[id].amenities != None: | ||
amenities = tours[id].amenities | ||
amenities_json = jsonable_encoder(amenities) | ||
return JSONResponse(content=amenities_json) | ||
else: | ||
return {"message": "no amenities"} | ||
if tours[id].amenities is None: | ||
return {"message": "no amenities"} | ||
amenities = tours[id].amenities | ||
amenities_json = jsonable_encoder(amenities) | ||
return JSONResponse(content=amenities_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.
Function show_amenities
refactored with the following changes:
- Swap if/else branches (
swap-if-else-branches
) - Remove unnecessary else after guard condition (
remove-unnecessary-else
) - Use x is None rather than x == None (
none-compare
)
if approved_users.get(touristId) == None: | ||
raise HTTPException(status_code=500, detail="details are missing") | ||
if approved_users.get(touristId) is None: | ||
raise HTTPException(status_code=500, detail="details are missing") |
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 create_booking
refactored with the following changes:
- Use x is None rather than x == None (
none-compare
)
account = {"id": id, "username": username, "password": password, "type": type} | ||
return account | ||
return {"id": id, "username": username, "password": password, "type": type} |
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 create_login
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
user = {"id": id, "firstname": firstname, "lastname": lastname, "middle": middle, "bday": bday, "pos": pos, "login": login} | ||
return user | ||
return { | ||
"id": id, | ||
"firstname": firstname, | ||
"lastname": lastname, | ||
"middle": middle, | ||
"bday": bday, | ||
"pos": pos, | ||
"login": login, | ||
} |
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 create_user_details
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
if keywords_recipe.get(id) == None: | ||
keywords = list() | ||
keywords.append(keyword) | ||
keywords_recipe[id] = keywords | ||
else: | ||
keywords = keywords_recipe[id] | ||
keywords.append(keyword) | ||
keywords_recipe[id] = keywords | ||
keywords = [] if keywords_recipe.get(id) is None else keywords_recipe[id] | ||
keywords.append(keyword) | ||
keywords_recipe[id] = keywords |
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 KeywordRepository.add_keywords
refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp
) - Use x is None rather than x == None (
none-compare
) - Replace
list()
with[]
(list-literal
) - Hoist repeated code outside conditional statement [×2] (
hoist-statement-from-if
)
recipes_list = [val.name for val in recipes.values()] | ||
return recipes_list | ||
return [val.name for val in recipes.values()] |
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_recipe_names
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
logger.info('Request to access ' + request.url.path) | ||
logger.info(f'Request to access {request.url.path}') | ||
try: | ||
response = await call_next(request) | ||
except Exception as ex: | ||
logger.error(f"Request to " + request.url.path + " failed: {ex}") | ||
logger.error(f"Request to {request.url.path}" + " failed: {ex}") | ||
response = JSONResponse(content={"success": False}, status_code=500) | ||
finally: | ||
logger.info('Successfully accessed ' + request.url.path) | ||
logger.info(f'Successfully accessed {request.url.path}') |
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 log_middleware
refactored with the following changes:
- Use f-string instead of string concatenation [×3] (
use-fstring-for-concatenation
)
|
||
|
||
class StudentSettings(BaseSettings): | ||
application:str = 'Student Management System' | ||
webmaster:str = 'sjctrags@university.com' | ||
created:date = '2021-11-10' | ||
|
||
|
||
|
||
|
||
class ServerSettings(BaseSettings): | ||
production_server:str | ||
prod_port:int | ||
development_server:str | ||
development_server:str | ||
dev_port:int | ||
|
||
|
||
|
||
|
||
class Config: | ||
env_file = os.getcwd() + '/configuration/erp_settings.properties' | ||
env_file = f'{os.getcwd()}/configuration/erp_settings.properties' |
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 14-28
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
if not account == None: | ||
if account is not None: |
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 approved_signup
refactored with the following changes:
- Simplify logical expression using De Morgan identities (
de-morgan
) - Use x is None rather than x == None (
none-compare
)
result = login_service.update_login_password(user_id, newpass) | ||
if result: | ||
if result := login_service.update_login_password(user_id, newpass): | ||
return JSONResponse(content={'message':'password changed successfully'}, status_code=201) | ||
else: | ||
else: |
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 change_password
refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression
)
result = faculty_service.add_faculty(faculty) | ||
if result: | ||
if result := faculty_service.add_faculty(faculty): | ||
return jsonable_encoder(faculty) | ||
else: | ||
else: |
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 create_profile
refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression
)
result = faculty_service.update_faculty(faculty_id, profile_dict ) | ||
if result: | ||
if result := faculty_service.update_faculty(faculty_id, profile_dict): | ||
return JSONResponse(content={'message':'profile updated successfully'}, status_code=201) | ||
else: | ||
else: |
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 update_profile
refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression
)
result = self.repo.delete_faculty(faculty_id) | ||
return result | ||
return self.repo.delete_faculty(faculty_id) |
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 FacultyService.remove_faculty
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
result = self.repo.insert_login(login) | ||
return result | ||
return self.repo.insert_login(login) |
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 FacultyLoginService.add_faculty_login
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
result = self.repo.update_password(user_id, newpass) | ||
return result | ||
return self.repo.update_password(user_id, newpass) |
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 FacultyLoginService.update_login_password
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
result = self.repo.delete_login(user_id) | ||
return result | ||
return self.repo.delete_login(user_id) |
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 FacultyLoginService.remove_faculty_login
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
result = self.repo.insert_item(signup) | ||
return result | ||
return self.repo.insert_item(signup) |
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 FacultySignupService.add_signup
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
Branch
main
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
main
branch, then run:Help us improve this pull request!