py-bson / bson

Independent BSON codec for Python that doesn't depend on MongoDB.
Other
439 stars 81 forks source link

pytz.utc vs datetime.timezone.utc #76

Open dajose opened 6 years ago

dajose commented 6 years ago

I want to integrate bson in a custom yocto image and I'm having troubles installing pytz dependency. I searched the repo and I found it is used here

I'm wondering if we could replace it with datetime.timezone.utc.

Parkayun commented 6 years ago

I know that python2 doen't have datetime.timezone. Do you have any idea about python2 and 3 complexity without pytz?

dajose commented 6 years ago

ok, for python2 pytz is irreplaceable

I don't understand the question of complexity, what do you mean by that?

Parkayun commented 6 years ago

Ah, It means any idea to remove pytz. I agree with removing pytz dependency if we can.

dajose commented 6 years ago

oh, I found you guys use it in 2 places only and both times you use it to get utc... As far as I've found on the web it is the same to use pytz.utc to datetime.timezone.utc, but I am not really sure about that.

Where I see the difficulty is supporting python2, because as you'd said there is no datetime.timezone there :(

Parkayun commented 6 years ago

if we use datetime.timezone. then we can see error when use python2. python3 ok.

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'timezone'

so we use pytz for python2.

amcgregor commented 5 years ago

I like the idea of dependency elimination, esp. if it's only included for the use of a single constant. Official PyMongo rolls its own utc.