Skip to content

Conversation

@tusharmakkar08
Copy link

Abstracted out the functionality and hence reducing number of "if's" in the code.

@coveralls
Copy link

Coverage Status

Coverage increased (+1.004%) to 60.22% when pulling 6041171 on tusharmakkar08:master into 0fda183 on python-diamond:master.

@tusharmakkar08
Copy link
Author

@jaingaurav : Any comments on this PR ?

if unit in units:
# returning self.type_of_unit
return self.convertb(value, object_type, counter)
return "None"
Copy link
Member

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"

Copy link
Author

@tusharmakkar08 tusharmakkar08 Apr 24, 2016

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.

Copy link
Contributor

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?

Copy link
Author

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.

Copy link
Contributor

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. 😕

Copy link
Member

Choose a reason for hiding this comment

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

return None

@jaingaurav
Copy link
Member

Made some minor comments. If you're able to resolve them please squash the commits and I'll check it in. Thanks.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.2%) to 59.413% when pulling 5b0f0eb on tusharmakkar08:master into 0fda183 on python-diamond:master.

@coveralls
Copy link

Coverage Status

Coverage increased (+1.05%) to 60.269% when pulling 6a72b8d on tusharmakkar08:master into 929e3eb on python-diamond:master.

@coveralls
Copy link

Coverage Status

Coverage increased (+1.004%) to 60.22% when pulling 66aec5f on tusharmakkar08:master into 929e3eb on python-diamond:master.

@tusharmakkar08
Copy link
Author

@jaingaurav : I have replied to the comments made by you and squashed the commits.

@coveralls
Copy link

coveralls commented Apr 24, 2016

Coverage Status

Coverage decreased (-0.4%) to 24.041% when pulling 36a89ad on tusharmakkar08:master into 0f3eb04 on python-diamond:master.

@tusharmakkar08 tusharmakkar08 force-pushed the master branch 2 times, most recently from 5474780 to 66aec5f Compare April 24, 2016 10:55
@tusharmakkar08
Copy link
Author

Any comments @jaingaurav ?

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":
Copy link
Member

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 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":
Copy link
Member

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
Copy link
Member

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))
Copy link
Member

Choose a reason for hiding this comment

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

Add return here

Copy link
Member

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

@shortdudey123
Copy link
Member

Added 6 comments, i verified those changes work

@tusharmakkar08
Copy link
Author

@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'],
Copy link
Member

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:
Copy link
Member

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:
Copy link
Member

Choose a reason for hiding this comment

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

if obj

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants