Skip to content

Commit

Permalink
a few more py3 improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
mahmoud committed Mar 31, 2024
1 parent 59dc6be commit 0e4dc6a
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion boltons/funcutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -932,7 +932,7 @@ def remove_arg(self, arg_name):
try:
self.kwonlyargs.remove(arg_name)
except (AttributeError, ValueError):
# py2, or py3 and missing from both
# missing from both
exc = MissingArgument('arg %r not found in %s argument list:'
' %r' % (arg_name, self.name, args))
exc.arg_name = arg_name
Expand Down
5 changes: 1 addition & 4 deletions boltons/iterutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1398,10 +1398,7 @@ def reseed(self):
self.salt = '-'.join([str(self.pid),
socket.gethostname() or '<nohostname>',
str(time.time()),
codecs.encode(os.urandom(6),
'hex_codec').decode('ascii')])
# that codecs trick is the best/only way to get a bytes to
# hexbytes in py2/3
os.urandom(6).hex()])
return

def __iter__(self):
Expand Down
8 changes: 2 additions & 6 deletions boltons/statsutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@

import bisect
from math import floor, ceil
from collections import Counter


class _StatsProperty:
Expand Down Expand Up @@ -595,12 +596,7 @@ def get_histogram_counts(self, bins=None, **kw):
bins = sorted(set(bins))

idxs = [bisect.bisect(bins, d) - 1 for d in self.data]
count_map = {} # would have used Counter, but py26 support
for idx in idxs:
try:
count_map[idx] += 1
except KeyError:
count_map[idx] = 1
count_map = Counter(idxs)

bin_counts = [(b, count_map.get(i, 0)) for i, b in enumerate(bins)]

Expand Down
7 changes: 7 additions & 0 deletions docs/timeutils.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,18 @@ working with them:

.. _UTC: https://en.wikipedia.org/wiki/Coordinated_Universal_Time

.. note::

These days, Python has a `built-in UTC`_, and the UTC tzinfo here,
while equivalent, is just for backwards compat.

.. autoattribute:: boltons.timeutils.UTC
.. autodata:: boltons.timeutils.LocalTZ

.. autoclass:: boltons.timeutils.ConstantTZInfo

.. _built-in UTC: https://docs.python.org/3/library/datetime.html#datetime.timezone.utc

US timezones
------------

Expand Down
2 changes: 1 addition & 1 deletion tests/test_fileutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ def test_fileperms():

assert repr(up) == "FilePerms(user='rwx', group='rwx', other='')"
assert up.user == 'rwx'
assert oct(int(up)).endswith('770') # 0770 on py2 and 0o770 on py3
assert oct(int(up)) == '0o770'

assert int(FilePerms()) == 0

0 comments on commit 0e4dc6a

Please sign in to comment.