-
Notifications
You must be signed in to change notification settings - Fork 86
FIX: Py3 - NameError: name 'long' is not defined #200
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
Conversation
Merge pull request from carbonblack/cbapi-python
PEP 237: Essentially, long renamed to int. That is, there is only one built-in integral type, named int; but it behaves mostly like the old long type. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ File "C:\Program Files\Python38\lib\site-packages\cbapi\models.py", line 147, in __get__ if type(d) is float or type(d) is int or type(d) is long: NameError: name 'long' is not defined ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Hi Ruchir, |
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 would prefer to keep the long option instead wrap the code in a try .. except which catches the NameError. Then just make the same check without the long check that way we can still support long for the python2 users as well as support the new python3 users. It's not pretty but until we move more away from python2 this will maintain better support
d = super(EpochDateTimeFieldDescriptor, self).__get__(instance, instance_type)
try:
if type(d) is float or type(d) is int or type(d) is long:
epoch_seconds = d / self.multiplier
return datetime.utcfromtimestamp(epoch_seconds)
else:
return datetime.utcfromtimestamp(0) # default to epoch time (1970-01-01) if we have a non-numeric type
except NameError:
if type(d) is float or type(d) is int:
epoch_seconds = d / self.multiplier
return datetime.utcfromtimestamp(epoch_seconds)
else:
return datetime.utcfromtimestamp(0) # default to epoch time (1970-01-01) if we have a non-numeric 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.
Check if this looks better (wanted to reduce few redundant statements), otherwise, I will change it to the try-catch block as you proposed.
@avanbrunt-cb check when time permits. |
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.
LGTM
Simple enough once you understand how types can be reassigned. I approve. |
I wasn't a reviewer, so I had to add myself before I could approve it :) |
@bvasil-cb @avanbrunt-cb @llyon-cb Verify the modification, not sure if this would break something in Python 2 or not, but Python 3 has no data type "long". Feel free to modify accordingly.