Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions AutoDuck/Dump2HHC.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,7 @@ def _urlescape(name):


def _genCategoryHTMLFromDict(dict, output):
keys = list(dict.keys())
keys.sort()
for key in keys:
for key in sorted(dict):
topic = dict[key]
output.write(f'<LI><A HREF="{topic.context}">{topic.name}</A>\n')

Expand Down Expand Up @@ -285,9 +283,7 @@ def genCategoryHTML(output_dir, cats):

def _genItemsFromDict(dict, cat, output, target, do_children=1):
CHM = "mk:@MSITStore:%s.chm::/" % target
keys = list(dict.keys())
keys.sort()
for k in keys:
for k in sorted(dict):
context = dict[k].context
name = dict[k].name
output.write(
Expand Down
8 changes: 2 additions & 6 deletions AutoDuck/InsertExternalOverviews.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,8 @@ def genHTML(doc):
s = ""
for cat in doc:
s += f"<H3>{cat.label}</H3>\n"
dict = {}
for item in cat.overviewItems.items:
dict[item.name] = item.href
keys = list(dict.keys())
keys.sort()
for k in keys:
dict = {item.name: item.href for item in cat.overviewItems.items}
for k in sorted(dict):
s += f'<LI><A HREF="html/{dict[k]}">{k}</A>\n'
return s

Expand Down
4 changes: 2 additions & 2 deletions AutoDuck/py2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def build_module(fp, mod_name):
functions = []
classes = []
constants = []
for name, ob in list(mod.__dict__.items()):
for name, ob in mod.__dict__.items():
if name.startswith("_"):
continue
if hasattr(ob, "__module__") and ob.__module__ != mod_name:
Expand Down Expand Up @@ -139,7 +139,7 @@ def build_module(fp, mod_name):
func_infos = []
# We need to iter the keys then to a getattr() so the funky descriptor
# things work.
for n in list(ob.ob.__dict__.keys()):
for n in ob.ob.__dict__:
o = getattr(ob.ob, n)
if isinstance(o, (types.FunctionType, types.MethodType)):
info = BuildInfo(n, o)
Expand Down
2 changes: 1 addition & 1 deletion CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ Coming in build 307, as yet unreleased
* Cleaned up unused imports (#1986, #2051, #1990, #2124, #2126, @Avasam)
* Removed duplicated declarations, constants and definitions (#2050 , #1950, #1990, @Avasam)
* Small generalized optimization by using augmented assignements (in-place operators) where possible (#2274, @Avasam)
* General speed and size improvements due to all the removed code. (#2046, #1986, #2050, #1950, #2085, #2087, #2051, #1990, #2106, #2127, #2124, #2126, #2177, #2218, #2202, #2205, #2217)
* General speed and size improvements due to all the removed code. (#2046, #1986, #2050, #1950, #2085, #2087, #2051, #1990, #2106, #2127, #2124, #2126, #2177, #2218, #2202, #2205, #2217, #2332)

### adodbapi
* Remove references to outdated IronPython (#2049, @Avasam)
Expand Down
4 changes: 1 addition & 3 deletions Pythonwin/pywin/Demos/app/customprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ def OnDraw(self, dc):
oldPen = None
x, y = self.size
delta = 2
colors = list(self.colors.keys())
colors.sort()
colors *= 2
colors = sorted(self.colors) * 2
for color in colors:
if oldPen is None:
oldPen = dc.SelectObject(self.pens[color])
Expand Down
2 changes: 1 addition & 1 deletion Pythonwin/pywin/debugger/configui.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def OnInitDialog(self):
def OnOK(self):
self.UpdateData()
dirty = 0
for key, val in list(self.items()):
for key, val in self.items():
if key in self.options:
if self.options[key] != val:
self.options[key] = val
Expand Down
2 changes: 1 addition & 1 deletion Pythonwin/pywin/debugger/debugger.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ def DeleteSelected(self):
item_id = self.GetItem(num)[6]
from bdb import Breakpoint

for bplist in list(Breakpoint.bplist.values()):
for bplist in Breakpoint.bplist.values():
for bp in bplist:
if id(bp) == item_id:
self.debugger.clear_break(bp.file, bp.line)
Expand Down
2 changes: 1 addition & 1 deletion Pythonwin/pywin/framework/dbgcommands.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def HookCommands(self):
if not methUpdate is None:
frame.HookCommandUpdate(methUpdate, id)

for id in list(IdToBarNames.keys()):
for id in IdToBarNames:
frame.HookCommand(self.OnDebuggerBar, id)
frame.HookCommandUpdate(self.OnUpdateDebuggerBar, id)

Expand Down
4 changes: 1 addition & 3 deletions Pythonwin/pywin/framework/mdi_pychecker.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,7 @@ def __init__(self, str, recurse=0):
sd = sd.lower()
if sd not in dirs:
dirs[sd] = None
self.dirs = []
for d in dirs.keys():
self.dirs.append(d)
self.dirs = list(dirs)

def __getitem__(self, key):
return self.dirs[key]
Expand Down
2 changes: 1 addition & 1 deletion Pythonwin/pywin/framework/scriptutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ def ImportFile():
# note that some packages (*cough* email *cough*) use "lazy importers"
# meaning sys.modules can change as a side-effect of looking at
# module.__file__ - so we must take a copy (ie, list(items()))
for key, mod in list(sys.modules.items()):
for key, mod in sys.modules.items():
if getattr(mod, "__file__", None):
fname = mod.__file__
base, ext = os.path.splitext(fname)
Expand Down
4 changes: 1 addition & 3 deletions Pythonwin/pywin/framework/sgrepmdi.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,7 @@ def __init__(self, str, recurse=0):
sd = sd.lower()
if sd not in dirs:
dirs[sd] = None
self.dirs = []
for d in list(dirs.keys()):
self.dirs.append(d)
self.dirs = list(dirs)

def __getitem__(self, key):
return self.dirs[key]
Expand Down
6 changes: 3 additions & 3 deletions Pythonwin/pywin/mfc/dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,13 @@ def __setitem__(self, key, item):
self._obj_.data[key] = item # self.UpdateData(0)

def keys(self):
return list(self.data.keys())
return self.data.keys()

def items(self):
return list(self.data.items())
return self.data.items()

def values(self):
return list(self.data.values())
return self.data.values()

def __contains__(self, key):
return key in self.data
Expand Down
2 changes: 1 addition & 1 deletion Pythonwin/pywin/scintilla/bindings.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def prepare_configure(self):
self.keymap = {}

def complete_configure(self):
for id in command_to_events.keys():
for id in command_to_events:
self.parent_view.HookCommand(self._OnCommand, id)

def close(self):
Expand Down
6 changes: 2 additions & 4 deletions Pythonwin/pywin/scintilla/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ def configure(self, editor, subsections=None):
ns = None
if ns:
num = 0
for name, func in list(ns.items()):
for name, func in ns.items():
if isinstance(func, types.FunctionType) and name[:1] != "_":
bindings.bind(name, func)
num += 1
Expand Down Expand Up @@ -230,10 +230,8 @@ def get_key_binding(self, event, subsections=None):
for subsection in subsections:
map = self.key_to_events.get(subsection)
if map is None: # Build it
map = {}
keymap = subsection_keymap.get(subsection, {})
for key_info, map_event in list(keymap.items()):
map[map_event] = key_info
map = {map_event: key_info for key_info, map_event in keymap.items()}
self.key_to_events[subsection] = map

info = map.get(event)
Expand Down
3 changes: 1 addition & 2 deletions Pythonwin/pywin/scintilla/configui.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,7 @@ def OnInitDialog(self):
self.butIsDefaultBackground = self.GetDlgItem(win32ui.IDC_CHECK2)
self.listbox = self.GetDlgItem(win32ui.IDC_LIST1)
self.HookCommand(self.OnListCommand, win32ui.IDC_LIST1)
names = list(self.styles.keys())
names.sort()
names = sorted(self.styles)
for name in names:
if self.styles[name].aliased is None:
self.listbox.AddString(name)
Expand Down
6 changes: 3 additions & 3 deletions Pythonwin/pywin/scintilla/formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def ApplyFormattingStyles(self, bReload=1):
defaultStyle = Style("default", baseFormat)
defaultStyle.stylenum = scintillacon.STYLE_DEFAULT
self._ReformatStyle(defaultStyle)
for style in list(self.styles.values()):
for style in self.styles.values():
if style.aliased is None:
style.NormalizeAgainstDefault(baseFormat)
self._ReformatStyle(style)
Expand All @@ -202,7 +202,7 @@ def LoadPreferences(self):
)
self.bUseFixed = int(self.LoadPreference("Use Fixed", 1))

for style in list(self.styles.values()):
for style in self.styles.values():
new = self.LoadPreference(style.name, str(style.format))
try:
style.format = eval(new)
Expand All @@ -222,7 +222,7 @@ def SavePreferences(self):
self.SavePreference("Base Format Fixed", str(self.baseFormatFixed))
self.SavePreference("Base Format Proportional", str(self.baseFormatProp))
self.SavePreference("Use Fixed", self.bUseFixed)
for style in list(self.styles.values()):
for style in self.styles.values():
if style.aliased is None:
self.SavePreference(style.name, str(style.format))
bg_name = style.name + " background"
Expand Down
16 changes: 9 additions & 7 deletions Pythonwin/pywin/scintilla/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -517,10 +517,14 @@ def list2dict(l):
)
)

# ensure all keys are strings.
items = [str(k) for k in items_dict.keys()]
# All names that start with "_" go!
items = [k for k in items if not k.startswith("_")]
items = [
k
for k in
# ensure all keys are strings.
map(str, items_dict)
# All names that start with "_" go!
if not k.startswith("_")
]

if not items:
# Heuristics a-la AutoExpand
Expand Down Expand Up @@ -550,9 +554,7 @@ def list2dict(l):
if curclass and left == "self":
self._UpdateWithClassMethods(unique, curclass)

items = [
word for word in unique.keys() if word[:2] != "__" or word[-2:] != "__"
]
items = [word for word in unique if word[:2] != "__" or word[-2:] != "__"]
# Ignore the word currently to the right of the dot - probably a red-herring.
try:
items.remove(right[1:])
Expand Down
9 changes: 2 additions & 7 deletions Pythonwin/pywin/tools/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def CalculateIsExpandable(self):
if hasattr(self.myobject, "__doc__"):
return 1
try:
for key in self.myobject.__dict__.keys():
for key in self.myobject.__dict__:
if key not in special_names:
return 1
except (AttributeError, TypeError):
Expand Down Expand Up @@ -288,12 +288,7 @@ def IsExpandable(self):
return len(self.myobject) > 0

def GetSubList(self):
ret = []
keys = list(self.myobject.keys())
keys.sort()
for key in keys:
ob = self.myobject[key]
ret.append(MakeHLI(ob, str(key)))
ret = [MakeHLI(self.myobject[key], str(key)) for key in sorted(self.myobject)]
self.InsertDocString(ret)
return ret

Expand Down
16 changes: 9 additions & 7 deletions com/win32com/client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
# with dynamic.Dispatch behaviour, where dynamic objects are always used.

import sys
from itertools import chain

import pythoncom
import pywintypes
Expand Down Expand Up @@ -510,17 +511,18 @@ def __init__(self, oobj=None):
self.__dict__["_oleobj_"] = oobj # so we don't call __setattr__

def __dir__(self):
lst = (
list(self.__dict__.keys())
+ dir(self.__class__)
+ list(self._prop_map_get_.keys())
+ list(self._prop_map_put_.keys())
attributes = chain(
self.__dict__,
dir(self.__class__),
self._prop_map_get_,
self._prop_map_put_,
)

try:
lst += [p.Name for p in self.Properties_]
attributes = chain(attributes, [p.Name for p in self.Properties_])
except AttributeError:
pass
return list(set(lst))
return list(set(attributes))

# Provide a prettier name than the CLSID
def __repr__(self):
Expand Down
19 changes: 11 additions & 8 deletions com/win32com/client/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import datetime
import string
from itertools import chain
from keyword import iskeyword

import pythoncom
Expand Down Expand Up @@ -493,18 +494,20 @@ def Build(self, typeinfo, attr, bForUser=1):
DispatchItem.Build(self, typeinfo, attr, bForUser)
assert typeinfo is not None, "Can't build vtables without type info!"

meth_list = (
list(self.mapFuncs.values())
+ list(self.propMapGet.values())
+ list(self.propMapPut.values())
meth_list = sorted(
chain(
self.mapFuncs.values(),
self.propMapGet.values(),
self.propMapPut.values(),
),
key=lambda m: m.desc[7],
)
meth_list.sort(key=lambda m: m.desc[7])

# Now turn this list into the run-time representation
# (ready for immediate use or writing to gencache)
self.vtableFuncs = []
for entry in meth_list:
self.vtableFuncs.append((entry.names, entry.dispid, entry.desc))
self.vtableFuncs = [
(entry.names, entry.dispid, entry.desc) for entry in meth_list
]


# A Lazy dispatch item - builds an item on request using info from
Expand Down
11 changes: 6 additions & 5 deletions com/win32com/client/dynamic.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"""

import traceback
from itertools import chain
from types import MethodType

import pythoncom # Needed as code we eval() references it.
Expand Down Expand Up @@ -233,19 +234,19 @@ def __str__(self):
return self.__repr__()

def __dir__(self):
lst = list(self.__dict__.keys()) + dir(self.__class__) + self._dir_ole_()
attributes = chain(self.__dict__, dir(self.__class__), self._dir_ole_())
try:
lst += [p.Name for p in self.Properties_]
attributes = chain(attributes, [p.Name for p in self.Properties_])
except AttributeError:
pass
return list(set(lst))
return list(set(attributes))

def _dir_ole_(self):
items_dict = {}
for iTI in range(0, self._oleobj_.GetTypeInfoCount()):
typeInfo = self._oleobj_.GetTypeInfo(iTI)
self._UpdateWithITypeInfo_(items_dict, typeInfo)
return list(items_dict.keys())
return list(items_dict)

def _UpdateWithITypeInfo_(self, items_dict, typeInfo):
typeInfos = [typeInfo]
Expand Down Expand Up @@ -455,7 +456,7 @@ def _print_details_(self):
print("AxDispatch container", self._username_)
try:
print("Methods:")
for method in self._olerepr_.mapFuncs.keys():
for method in self._olerepr_.mapFuncs:
print("\t", method)
print("Props:")
for prop, entry in self._olerepr_.propMap.items():
Expand Down
Loading