Skip to content

Conversation

ruchirarya
Copy link
Contributor

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

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
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@bvasil-cb
Copy link
Contributor

Hi Ruchir,
Thanks for the fix, we are a bit swamped this sprint, but we have a ticket in our backlog to verify it won't break python2.
Thanks again for your contribution and support!
Becca

Copy link
Contributor

@avanbrunt-cb avanbrunt-cb left a 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

Copy link
Contributor Author

@ruchirarya ruchirarya left a 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.

@ruchirarya
Copy link
Contributor Author

@avanbrunt-cb check when time permits.

@ruchirarya
Copy link
Contributor Author

Copy link
Contributor

@avanbrunt-cb avanbrunt-cb left a comment

Choose a reason for hiding this comment

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

LGTM

@abowersox-cb
Copy link
Contributor

Simple enough once you understand how types can be reassigned. I approve.

@abowersox-cb abowersox-cb self-requested a review December 2, 2019 21:32
@abowersox-cb
Copy link
Contributor

I wasn't a reviewer, so I had to add myself before I could approve it :)

@abowersox-cb abowersox-cb merged commit 945649d into carbonblack:master Dec 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants