-
Notifications
You must be signed in to change notification settings - Fork 597
Made code more DRY #439
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?
Made code more DRY #439
Conversation
|
@jaingaurav : Any comments on this PR ? |
src/diamond/convertor.py
Outdated
| if unit in units: | ||
| # returning self.type_of_unit | ||
| return self.convertb(value, object_type, counter) | ||
| return "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.
Please return None vs "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.
I tried doing that but tests started failing since convertb also returns None. Let me know if you want to have -1 instead of "None" as return value of _object_mapper function.
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.
When doesn convertb return 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.
@Lacrymology : Just checked in the failing tests, that the issue isn't due to convertb returning None but _object_mapper returning None causes float(actual_value) to throw TypeError. You can check here for more details.
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.
I don't see how there's a difference between if obj == "None" and if obj is None in L67 &c. 😕
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.
return None
|
Made some minor comments. If you're able to resolve them please squash the commits and I'll check it in. Thanks. |
|
@jaingaurav : I have replied to the comments made by you and squashed the commits. |
5474780 to
66aec5f
Compare
|
Any comments @jaingaurav ? |
src/diamond/convertor.py
Outdated
| if unit in ['yottabit', 'Ybit', 'Yibit']: | ||
| return self.yottabit(value=value) | ||
| obj = self._object_mapper(unit, value, _LIST_OF_UNITS_BIT, self.bit) | ||
| if obj != "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.
if obj is not None:
src/diamond/convertor.py
Outdated
| if unit in ['yottabyte', 'YB', 'YiB']: | ||
| return self.yottabyte(value=value) | ||
| obj = self._object_mapper(unit, value, _LIST_OF_UNITS_BYTE, self.byte) | ||
| if obj != "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.
if obj is not None:
| if value is None: | ||
| return self.value / 8 | ||
| else: | ||
| self.value = float(value) * 8 |
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.
add return self.value on next line
| if value is None: | ||
| return source() / pow(1024, offset) | ||
| else: | ||
| source(value * pow(1024, offset)) |
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.
Add return here
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.
and change def bit to
def bit(self, value=None):
- if value is None:
- return self.value
- else:
+ if value is not None:
self.value = float(value)
+ return self.value|
Added 6 comments, i verified those changes work |
|
@shortdudey123 : If I replace "None" with None, it doesn't pass the test cases. Please check. |
| # Lists are in the order of increasing magnitude | ||
| _LIST_OF_UNITS_BIT = [['bit', 'b'], | ||
| ['kilobit', 'kbit', 'Kibit'], | ||
| ['megabit', 'Mbit', 'Mibit', 'Mbit'], |
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.
dupe Mbit
| if unit in ['yottabit', 'Ybit', 'Yibit']: | ||
| return self.yottabit(value=value) | ||
| obj = self._object_mapper(unit, value, _LIST_OF_UNITS_BIT, self.bit) | ||
| if not obj: |
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.
if obj
| if unit in ['yottabyte', 'YB', 'YiB']: | ||
| return self.yottabyte(value=value) | ||
| obj = self._object_mapper(unit, value, _LIST_OF_UNITS_BYTE, self.byte) | ||
| if not obj: |
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.
if obj
Abstracted out the functionality and hence reducing number of "if's" in the code.