a few more py3 improvements

This commit is contained in:
Mahmoud Hashemi 2024-03-31 13:32:55 -07:00 committed by Mahmoud Hashemi
parent 59dc6be731
commit 0e4dc6a7ed
5 changed files with 12 additions and 12 deletions

View File

@ -932,7 +932,7 @@ class FunctionBuilder:
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

View File

@ -1398,10 +1398,7 @@ class GUIDerator:
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):

View File

@ -128,6 +128,7 @@ system instrumentation package.
import bisect
from math import floor, ceil
from collections import Counter
class _StatsProperty:
@ -595,12 +596,7 @@ class Stats:
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)]

View File

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

View File

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