Skip to content

Commit

Permalink
Update collections literals and comprehensions (#2108)
Browse files Browse the repository at this point in the history
  • Loading branch information
Avasam authored Sep 21, 2023
1 parent 6df8533 commit 56ecf8c
Show file tree
Hide file tree
Showing 13 changed files with 116 additions and 116 deletions.
86 changes: 43 additions & 43 deletions com/win32com/test/testShell.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ def _testSimple(self, make_unicode):
fgd = shell.FILEGROUPDESCRIPTORAsString([], make_unicode)
header = struct.pack("i", 0)
self.assertEqual(header, fgd[: len(header)])
self._testRT(dict())
d = dict()
self._testRT({})
d = {}
fgd = shell.FILEGROUPDESCRIPTORAsString([d], make_unicode)
header = struct.pack("i", 1)
self.assertEqual(header, fgd[: len(header)])
Expand All @@ -153,53 +153,53 @@ def testSimpleUnicode(self):
def testComplex(self):
clsid = pythoncom.MakeIID("{CD637886-DB8B-4b04-98B5-25731E1495BE}")
ctime, atime, wtime = self._getTestTimes()
d = dict(
cFileName="foo.txt",
clsid=clsid,
sizel=(1, 2),
pointl=(3, 4),
dwFileAttributes=win32con.FILE_ATTRIBUTE_NORMAL,
ftCreationTime=ctime,
ftLastAccessTime=atime,
ftLastWriteTime=wtime,
nFileSize=sys.maxsize + 1,
)
d = {
"cFileName": "foo.txt",
"clsid": clsid,
"sizel": (1, 2),
"pointl": (3, 4),
"dwFileAttributes": win32con.FILE_ATTRIBUTE_NORMAL,
"ftCreationTime": ctime,
"ftLastAccessTime": atime,
"ftLastWriteTime": wtime,
"nFileSize": sys.maxsize + 1,
}
self._testRT(d)

def testUnicode(self):
# exercise a bug fixed in build 210 - multiple unicode objects failed.
ctime, atime, wtime = self._getTestTimes()
d = [
dict(
cFileName="foo.txt",
sizel=(1, 2),
pointl=(3, 4),
dwFileAttributes=win32con.FILE_ATTRIBUTE_NORMAL,
ftCreationTime=ctime,
ftLastAccessTime=atime,
ftLastWriteTime=wtime,
nFileSize=sys.maxsize + 1,
),
dict(
cFileName="foo2.txt",
sizel=(1, 2),
pointl=(3, 4),
dwFileAttributes=win32con.FILE_ATTRIBUTE_NORMAL,
ftCreationTime=ctime,
ftLastAccessTime=atime,
ftLastWriteTime=wtime,
nFileSize=sys.maxsize + 1,
),
dict(
cFileName="foo\xa9.txt",
sizel=(1, 2),
pointl=(3, 4),
dwFileAttributes=win32con.FILE_ATTRIBUTE_NORMAL,
ftCreationTime=ctime,
ftLastAccessTime=atime,
ftLastWriteTime=wtime,
nFileSize=sys.maxsize + 1,
),
{
"cFileName": "foo.txt",
"sizel": (1, 2),
"pointl": (3, 4),
"dwFileAttributes": win32con.FILE_ATTRIBUTE_NORMAL,
"ftCreationTime": ctime,
"ftLastAccessTime": atime,
"ftLastWriteTime": wtime,
"nFileSize": sys.maxsize + 1,
},
{
"cFileName": "foo2.txt",
"sizel": (1, 2),
"pointl": (3, 4),
"dwFileAttributes": win32con.FILE_ATTRIBUTE_NORMAL,
"ftCreationTime": ctime,
"ftLastAccessTime": atime,
"ftLastWriteTime": wtime,
"nFileSize": sys.maxsize + 1,
},
{
"cFileName": "foo\xa9.txt",
"sizel": (1, 2),
"pointl": (3, 4),
"dwFileAttributes": win32con.FILE_ATTRIBUTE_NORMAL,
"ftCreationTime": ctime,
"ftLastAccessTime": atime,
"ftLastWriteTime": wtime,
"nFileSize": sys.maxsize + 1,
},
]
s = shell.FILEGROUPDESCRIPTORAsString(d, 1)
d2 = shell.StringAsFILEGROUPDESCRIPTOR(s)
Expand Down
2 changes: 1 addition & 1 deletion com/win32comext/axdebug/expressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def Start(self, callback):
sys.exc_info()[0], sys.exc_info()[1]
)
# l is a list of strings with trailing "\n"
self.result = string.join(map(lambda s: s[:-1], l), "\n")
self.result = string.join((s[:-1] for s in l), "\n")
self.hresult = winerror.E_FAIL
finally:
self.isComplete = 1
Expand Down
24 changes: 10 additions & 14 deletions com/win32comext/bits/test/show_all_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,17 @@
import pythoncom
from win32com.bits import bits

states = dict(
[
(val, (name[13:]))
for name, val in vars(bits).items()
if name.startswith("BG_JOB_STATE_")
]
)
states = {
val: name[13:]
for name, val in vars(bits).items()
if name.startswith("BG_JOB_STATE_")
}

job_types = dict(
[
(val, (name[12:]))
for name, val in vars(bits).items()
if name.startswith("BG_JOB_TYPE_")
]
)
job_types = {
val: name[12:]
for name, val in vars(bits).items()
if name.startswith("BG_JOB_TYPE_")
}

bcm = pythoncom.CoCreateInstance(
bits.CLSID_BackgroundCopyManager,
Expand Down
12 changes: 5 additions & 7 deletions com/win32comext/bits/test/test_bits.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,11 @@
StopEvent = win32event.CreateEvent(None, 0, 0, None)

job_name = "bits-pywin32-test"
states = dict(
[
(val, (name[13:]))
for name, val in vars(bits).items()
if name.startswith("BG_JOB_STATE_")
]
)
states = {
val: (name[13:])
for name, val in vars(bits).items()
if name.startswith("BG_JOB_STATE_")
}

bcm = pythoncom.CoCreateInstance(
bits.CLSID_BackgroundCopyManager,
Expand Down
4 changes: 1 addition & 3 deletions com/win32comext/shell/demos/IFileOperationProgressSink.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
from win32com.server.policy import DesignatedWrapPolicy
from win32com.shell import shell, shellcon

tsf_flags = list(
(k, v) for k, v in list(shellcon.__dict__.items()) if k.startswith("TSF_")
)
tsf_flags = [(k, v) for k, v in list(shellcon.__dict__.items()) if k.startswith("TSF_")]


def decode_flags(flags):
Expand Down
4 changes: 1 addition & 3 deletions com/win32comext/shell/demos/ITransferAdviseSink.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
from win32com.server.policy import DesignatedWrapPolicy
from win32com.shell import shell, shellcon

tsf_flags = list(
(k, v) for k, v in list(shellcon.__dict__.items()) if k.startswith("TSF_")
)
tsf_flags = [(k, v) for k, v in list(shellcon.__dict__.items()) if k.startswith("TSF_")]

TRANSFER_ADVISE_STATES = {}
for k, v in list(shellcon.__dict__.items()):
Expand Down
10 changes: 7 additions & 3 deletions com/win32comext/shell/demos/servers/folder_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,13 @@ def make_item_enum(level, flags):
else:
skip = not (flags & shellcon.SHCONTF_NONFOLDERS)
if not skip:
data = dict(
name=name, size=size, sides=sides, level=level, is_folder=is_folder
)
data = {
"name": name,
"size": size,
"sides": sides,
"level": level,
"is_folder": is_folder,
}
pidls.append([pickle.dumps(data)])
return NewEnum(pidls, shell.IID_IEnumIDList)

Expand Down
6 changes: 3 additions & 3 deletions win32/Lib/win32timezone.py
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ def _LoadDynamicInfoFromKey(self, key):
# if the target year is greater or equal.
self.dynamicInfo = RangeMap(
zip(years, values),
sort_params=dict(reverse=True),
sort_params={"reverse": True},
key_match_comparator=operator.ge,
)

Expand Down Expand Up @@ -967,7 +967,7 @@ def __init__(self, source, sort_params={}, key_match_comparator=operator.le):
self.match = key_match_comparator

def __getitem__(self, item):
sorted_keys = sorted(list(self.keys()), **self.sort_params)
sorted_keys = sorted(self.keys(), **self.sort_params)
if isinstance(item, RangeMap.Item):
result = self.__getitem__(sorted_keys[item])
else:
Expand Down Expand Up @@ -998,7 +998,7 @@ def is_match(k):
raise KeyError(item)

def bounds(self):
sorted_keys = sorted(list(self.keys()), **self.sort_params)
sorted_keys = sorted(self.keys(), **self.sort_params)
return (
sorted_keys[RangeMap.first_item],
sorted_keys[RangeMap.last_item],
Expand Down
4 changes: 2 additions & 2 deletions win32/test/handles.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,12 @@ def testOtherHandle(self):

def testHandleInDict(self):
h = pywintypes.HANDLE(1)
d = dict(foo=h)
d = {"foo": h}
self.assertEqual(d["foo"], h)

def testHandleInDictThenInt(self):
h = pywintypes.HANDLE(1)
d = dict(foo=h)
d = {"foo": h}
self.assertEqual(d["foo"], 1)

def testHandleCompareNone(self):
Expand Down
2 changes: 1 addition & 1 deletion win32/test/test_pywintypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def testGUIDRichCmp(self):
def testGUIDInDict(self):
s = "{00020400-0000-0000-C000-000000000046}"
iid = pywintypes.IID(s)
d = dict(item=iid)
d = {"item": iid}
self.assertEqual(d["item"], iid)


Expand Down
2 changes: 1 addition & 1 deletion win32/test/test_security.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def testNEOther(self):
self.assertNotEqual(None, self.pwr_sid)

def testSIDInDict(self):
d = dict(foo=self.pwr_sid)
d = {"foo": self.pwr_sid}
self.assertEqual(d["foo"], self.pwr_sid)

def testBuffer(self):
Expand Down
74 changes: 40 additions & 34 deletions win32/test/test_win32guistruct.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

class TestBase(unittest.TestCase):
def assertDictEquals(self, d, **kw):
checked = dict()
checked = {}
for n, v in kw.items():
self.assertEqual(v, d[n], "'%s' doesn't match: %r != %r" % (n, v, d[n]))
checked[n] = True
Expand All @@ -22,17 +22,17 @@ def assertDictEquals(self, d, **kw):

class TestMenuItemInfo(TestBase):
def _testPackUnpack(self, text):
vals = dict(
fType=win32con.MFT_MENUBARBREAK,
fState=win32con.MFS_CHECKED,
wID=123,
hSubMenu=1234,
hbmpChecked=12345,
hbmpUnchecked=123456,
dwItemData=1234567,
text=text,
hbmpItem=321,
)
vals = {
"fType": win32con.MFT_MENUBARBREAK,
"fState": win32con.MFS_CHECKED,
"wID": 123,
"hSubMenu": 1234,
"hbmpChecked": 12345,
"hbmpUnchecked": 123456,
"dwItemData": 1234567,
"text": text,
"hbmpItem": 321,
}
mii, extras = win32gui_struct.PackMENUITEMINFO(**vals)
(
fType,
Expand Down Expand Up @@ -94,7 +94,13 @@ def testEmptyMenuItemInfo(self):

class TestMenuInfo(TestBase):
def testPackUnpack(self):
vals = dict(dwStyle=1, cyMax=2, hbrBack=3, dwContextHelpID=4, dwMenuData=5)
vals = {
"dwStyle": 1,
"cyMax": 2,
"hbrBack": 3,
"dwContextHelpID": 4,
"dwMenuData": 5,
}

mi = win32gui_struct.PackMENUINFO(**vals)
(
Expand Down Expand Up @@ -132,16 +138,16 @@ def testEmptyMenuItemInfo(self):

class TestTreeViewItem(TestBase):
def _testPackUnpack(self, text):
vals = dict(
hitem=1,
state=2,
stateMask=3,
text=text,
image=4,
selimage=5,
citems=6,
param=7,
)
vals = {
"hitem": 1,
"state": 2,
"stateMask": 3,
"text": text,
"image": 4,
"selimage": 5,
"citems": 6,
"param": 7,
}

ti, extra = win32gui_struct.PackTVITEM(**vals)
(
Expand Down Expand Up @@ -197,16 +203,16 @@ def testEmpty(self):

class TestListViewItem(TestBase):
def _testPackUnpack(self, text):
vals = dict(
item=None,
subItem=None,
state=1,
stateMask=2,
text=text,
image=3,
param=4,
indent=5,
)
vals = {
"item": None,
"subItem": None,
"state": 1,
"stateMask": 2,
"text": text,
"image": 3,
"param": 4,
"indent": 5,
}

ti, extra = win32gui_struct.PackLVITEM(**vals)
(
Expand Down Expand Up @@ -265,7 +271,7 @@ def testEmpty(self):

class TestLVColumn(TestBase):
def _testPackUnpack(self, text):
vals = dict(fmt=1, cx=2, text=text, subItem=3, image=4, order=5)
vals = {"fmt": 1, "cx": 2, "text": text, "subItem": 3, "image": 4, "order": 5}

ti, extra = win32gui_struct.PackLVCOLUMN(**vals)
fmt, cx, text, subItem, image, order = win32gui_struct.UnpackLVCOLUMN(ti)
Expand Down
2 changes: 1 addition & 1 deletion win32/test/test_win32inet.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def testCookies(self):
InternetSetCookie("http://www.python.org", None, data)
got = InternetGetCookie("http://www.python.org", None)
# handle that there might already be cookies for the domain.
bits = map(lambda x: x.strip(), got.split(";"))
bits = (x.strip() for x in got.split(";"))
self.assertTrue(data in bits)

def testCookiesEmpty(self):
Expand Down

0 comments on commit 56ecf8c

Please sign in to comment.