Skip to content
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

Improvement: Refactor code to use dict.get() method #1065

Open
4 tasks
codesankalp opened this issue Mar 29, 2021 · 11 comments · May be fixed by #1124
Open
4 tasks

Improvement: Refactor code to use dict.get() method #1065

codesankalp opened this issue Mar 29, 2021 · 11 comments · May be fixed by #1124
Assignees
Labels
Category: Coding Changes to code base or refactored code that doesn't fix a bug. Type: Enhancement New feature or request.

Comments

@codesankalp
Copy link
Member

Description

As a developer,
I need code to be consistent and error-free.

Mocks

name = data["name"]
username = data["username"]
password = data["password"]
email = data["email"]
terms_and_conditions_checked = data["terms_and_conditions_checked"]

For example this can be replaced by the get method i.e. data.get("KEY", "DEFAULT_VALUE") to avoid KeyError

Acceptance Criteria

Update [Required]

  • Use get method in all code to avoid the raise of KeyError
  • Handle exceptions for default value

Definition of Done

  • All of the required items are completed.
  • Approval by 1 mentor.

Estimation

2 hours

@codesankalp codesankalp added Category: Coding Changes to code base or refactored code that doesn't fix a bug. Status: Available Issue was approved and available to claim or abandoned for over 3 days. Type: Enhancement New feature or request. labels Mar 29, 2021
@harsh7in
Copy link

hey @codesankalp can i work on this ?

@codesankalp
Copy link
Member Author

Sure @harsh-9in 😄. Assigning you!

@vj-codes vj-codes removed the Status: Available Issue was approved and available to claim or abandoned for over 3 days. label Mar 29, 2021
@vj-codes
Copy link
Member

@codesankalp hey was this issue update discussed anywhere?

@codesankalp
Copy link
Member Author

@vj-codes This is the referenced comment: anitab-org/stem-diverse-tv#146 (comment)

@isabelcosta
Copy link
Member

@vj-codes thank you for confirming it! I saw the issue being created on stem diverse and thought it could be a little improvement here :)

cc @codesankalp

@vj-codes
Copy link
Member

vj-codes commented Apr 5, 2021

@harsh-9in any updates on this?

@vj-codes
Copy link
Member

vj-codes commented Apr 8, 2021

@harsh-9in if you have any questions about the issue or setting up the project, you can ask us here in comments or on zulip too :)

@devkapilbansal devkapilbansal added the Status: Available Issue was approved and available to claim or abandoned for over 3 days. label Apr 10, 2021
@aakankshaagr
Copy link
Contributor

@vj-codes Can I work on this issue?

@vj-codes vj-codes removed the Status: Available Issue was approved and available to claim or abandoned for over 3 days. label May 18, 2021
@epicadk
Copy link
Member

epicadk commented May 25, 2021

@codesankalp I don't get this? Why would we need a default value here? The data that comes from the user is already validated and needs to have these keys.

image

@codesankalp
Copy link
Member Author

@codesankalp I don't get this? Why would we need a default value here? The data that comes from the user is already validated and needs to have these keys.

Yes, it is but when you see the code there is a lot of repetition of code for validation which can be reduced using dict.get()

In the description, I just gave the example of dao/user.py but what I want to convey is to use dict.get method wherever necessary so that code doesn't look repetitive.

Example:

if "bio" in data:
if data["bio"]:
user.bio = data["bio"]
else:
user.bio = None

This can be written as:
data.get("bio", None)

This needs to be changed in the whole code.

@aakankshaagr
Copy link
Contributor

aakankshaagr commented May 25, 2021

@vj-codes @epicadk @codesankalp I have created a PR. Please check, if any changes are required.
Run tests are failing due to black (formatting issue) and I don't know the command for that. Can someone please tell me the command to remove that issue?

@aakankshaagr aakankshaagr linked a pull request Jun 20, 2021 that will close this issue
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Category: Coding Changes to code base or refactored code that doesn't fix a bug. Type: Enhancement New feature or request.
Projects
None yet
7 participants