Skip to content
8 changes: 4 additions & 4 deletions AutoDuck/py2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,11 @@ def build_module(fp, mod_name):
continue
if hasattr(ob, "__module__") and ob.__module__ != mod_name:
continue
if type(ob) in (type, type):
if type(ob) == type:
classes.append(BuildInfo(name, ob))
elif type(ob) == types.FunctionType:
elif isinstance(ob, types.FunctionType):
functions.append(BuildInfo(name, ob))
elif name.upper() == name and type(ob) in (int, str):
elif name.upper() == name and isinstance(ob, (int, str)):
constants.append((name, ob))
info = BuildInfo(mod_name, mod)
Print("// @module %s|%s" % (mod_name, format_desc(info.desc)), file=fp)
Expand Down Expand Up @@ -169,7 +169,7 @@ def build_module(fp, mod_name):

for name, val in constants:
desc = "%s = %r" % (name, val)
if type(val) in (int, int):
if isinstance(val, int):
desc += " (0x%x)" % (val,)
Print("// @const %s|%s|%s" % (mod_name, name, desc), file=fp)

Expand Down
2 changes: 1 addition & 1 deletion Pythonwin/pywin/Demos/dlgtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def OnNotify(self, controlid, code):
# Simply increment the value in the text box.
def KillFocus(self, msg):
self.counter = self.counter + 1
if self.edit != None:
if self.edit is not None:
self.edit.SetWindowText(str(self.counter))

# Called when the dialog box is terminating...
Expand Down
2 changes: 1 addition & 1 deletion Pythonwin/pywin/debugger/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def post_mortem(t=None):
# No idea why I need to settrace to None - it should have been reset by now?
sys.settrace(None)
p.reset()
while t.tb_next != None:
while t.tb_next is not None:
t = t.tb_next
p.bAtPostMortem = 1
p.prep_run(None)
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 @@ -751,7 +751,7 @@ def run(self, cmd, globals=None, locals=None, start_stepping=1):
self.reset()
self.prep_run(cmd)
sys.settrace(self.trace_dispatch)
if type(cmd) != types.CodeType:
if not isinstance(cmd, types.CodeType):
cmd = cmd + "\n"
try:
try:
Expand Down
2 changes: 1 addition & 1 deletion Pythonwin/pywin/dialogs/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def GetPassword(title="Password", password=""):
if len(sys.argv) > 2:
def_userid = sys.argv[2]
userid, password = GetLogin(title, def_user)
if userid == password == None:
if userid == password is None:
print("User pressed Cancel")
else:
print("User ID: ", userid)
Expand Down
2 changes: 1 addition & 1 deletion Pythonwin/pywin/framework/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ def Win32RawInput(prompt=None):
if prompt is None:
prompt = ""
ret = dialog.GetSimpleInput(prompt)
if ret == None:
if ret is None:
raise KeyboardInterrupt("operation cancelled")
return ret

Expand Down
8 changes: 4 additions & 4 deletions Pythonwin/pywin/framework/mdi_pychecker.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,11 @@ def __delslice__(self, lo, hi):
del self.dirs[lo:hi]

def __add__(self, other):
if type(other) == type(self) or type(other) == type([]):
if isinstance(other, (dirpath, list)):
return self.dirs + other.dirs

def __radd__(self, other):
if type(other) == type(self) or type(other) == type([]):
if isinstance(other, (dirpath, list)):
return other.dirs + self.dirs


Expand Down Expand Up @@ -319,7 +319,7 @@ def idleHandler(self, handler, count):
import time

time.sleep(0.001)
if self.result != None:
if self.result is not None:
win32ui.GetApp().DeleteIdleHandler(self.idleHandler)
return 0
return 1 # more
Expand Down Expand Up @@ -389,7 +389,7 @@ def _inactive_idleHandler(self, handler, count):
lines = open(f, "r").readlines()
for i in range(len(lines)):
line = lines[i]
if self.pat.search(line) != None:
if self.pat.search(line) is not None:
self.GetFirstView().Append(f + "(" + repr(i + 1) + ") " + line)
else:
self.fndx = -1
Expand Down
6 changes: 3 additions & 3 deletions Pythonwin/pywin/framework/sgrepmdi.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,11 @@ def __delslice__(self, lo, hi):
del self.dirs[lo:hi]

def __add__(self, other):
if type(other) == type(self) or type(other) == type([]):
if isinstance(other, (dirpath, list)):
return self.dirs + other.dirs

def __radd__(self, other):
if type(other) == type(self) or type(other) == type([]):
if isinstance(other, (dirpath, list)):
return other.dirs + self.dirs


Expand Down Expand Up @@ -302,7 +302,7 @@ def SearchFile(self, handler, count):
lines = open(f, "r").readlines()
for i in range(len(lines)):
line = lines[i]
if self.pat.search(line) != None:
if self.pat.search(line) is not None:
self.GetFirstView().Append(f + "(" + repr(i + 1) + ") " + line)
else:
self.fndx = -1
Expand Down
4 changes: 2 additions & 2 deletions Pythonwin/pywin/framework/winout.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def OnRClick(self, params):
paramsList = self.GetRightMenuItems()
menu = win32ui.CreatePopupMenu()
for appendParams in paramsList:
if type(appendParams) != type(()):
if not isinstance(appendParams, tuple):
appendParams = (appendParams,)
menu.AppendMenu(*appendParams)
menu.TrackPopupMenu(params[5]) # track at mouse position.
Expand Down Expand Up @@ -377,7 +377,7 @@ def __init__(
self.title = title
self.bCreating = 0
self.interruptCount = 0
if type(defSize) == type(""): # is a string - maintain size pos from ini file.
if isinstance(defSize, str): # maintain size pos from ini file.
self.iniSizeSection = defSize
self.defSize = app.LoadWindowSize(defSize)
self.loadedSize = self.defSize
Expand Down
12 changes: 6 additions & 6 deletions Pythonwin/pywin/mfc/dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@

def dllFromDll(dllid):
"given a 'dll' (maybe a dll, filename, etc), return a DLL object"
if dllid == None:
if dllid is None:
return None
elif type("") == type(dllid):
elif isinstance(dllid, str):
return win32ui.LoadLibrary(dllid)
else:
try:
Expand All @@ -33,7 +33,7 @@ def __init__(self, id, dllid=None):
dllid may be None, a dll object, or a string with a dll name"""
# must take a reference to the DLL until InitDialog.
self.dll = dllFromDll(dllid)
if type(id) == type([]): # a template
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't this (and the similar change below) wrong?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fixed up the PR and removed the changes that shouldn't have been in there. Ready to review :)

if isinstance(id, list): # a template
dlg = win32ui.CreateDialogIndirect(id)
else:
dlg = win32ui.CreateDialog(id, self.dll)
Expand Down Expand Up @@ -114,7 +114,7 @@ def __init__(
dllid=None,
):
self.dll = dllFromDll(dllid)
if type(dlgID) == type([]): # a template
if isinstance(dlgID, list): # a template
raise TypeError("dlgID parameter must be an integer resource ID")
dlg = win32ui.CreatePrintDialog(dlgID, printSetupOnly, flags, parent, self.dll)
window.Wnd.__init__(self, dlg)
Expand Down Expand Up @@ -193,7 +193,7 @@ def __init__(self, id, dllid=None, caption=0):
self.dll = dllFromDll(dllid)
if self.dll:
oldRes = win32ui.SetResource(self.dll)
if type(id) == type([]):
if isinstance(id, list):
dlg = win32ui.CreatePropertyPageIndirect(id)
else:
dlg = win32ui.CreatePropertyPage(id, caption)
Expand Down Expand Up @@ -243,7 +243,7 @@ def AddPage(self, pages):

def DoAddSinglePage(self, page):
"Page may be page, or int ID. Assumes DLL setup"
if type(page) == type(0):
if isinstance(page, int):
self.sheet.AddPage(win32ui.CreatePropertyPage(page))
else:
self.sheet.AddPage(page)
Expand Down
2 changes: 1 addition & 1 deletion Pythonwin/pywin/scintilla/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ def configure(self, editor, subsections=None):
if ns:
num = 0
for name, func in list(ns.items()):
if type(func) == types.FunctionType and name[:1] != "_":
if isinstance(func, types.FunctionType) and name[:1] != "_":
bindings.bind(name, func)
num = num + 1
trace("Configuration Extension code loaded", num, "events")
Expand Down
4 changes: 2 additions & 2 deletions Pythonwin/pywin/scintilla/control.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ def SCICancel(self):

# AutoComplete
def SCIAutoCShow(self, text):
if type(text) in [type([]), type(())]:
if isinstance(text, (list, tuple)):
text = " ".join(text)
buff = (text + "\0").encode(default_scintilla_encoding)
return self.SendScintilla(scintillacon.SCI_AUTOCSHOW, 0, buff)
Expand Down Expand Up @@ -423,7 +423,7 @@ def GetSelText(self):
return txtBuf.tobytes()[:-1].decode(default_scintilla_encoding)

def SetSel(self, start=0, end=None):
if type(start) == type(()):
if isinstance(start, tuple):
assert (
end is None
), "If you pass a point in the first param, the second must be None"
Expand Down
2 changes: 1 addition & 1 deletion Pythonwin/pywin/scintilla/formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def __init__(self, name, format, background=CLR_INVALID):
# Default background for each style is only used when there are no
# saved settings (generally on first startup)
self.background = self.default_background = background
if type(format) == type(""):
if isinstance(format, str):
self.aliased = format
self.format = None
else:
Expand Down
8 changes: 4 additions & 4 deletions Pythonwin/pywin/tools/hierlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@

# helper to get the text of an arbitary item
def GetItemText(item):
if type(item) == type(()) or type(item) == type([]):
if isinstance(item, (tuple, list)):
use = item[0]
else:
use = item
if type(use) == type(""):
if isinstance(use, str):
return use
else:
return repr(item)
Expand Down Expand Up @@ -185,8 +185,8 @@ def AddItem(self, parentHandle, item, hInsertAfter=commctrl.TVI_LAST):
bitmapSel = self.GetSelectedBitmapColumn(item)
if bitmapSel is None:
bitmapSel = bitmapCol
## if type(text) is str:
## text = text.encode("mbcs")
## if isinstance(text, str):
## text = text.encode("mbcs")
hitem = self.listControl.InsertItem(
parentHandle,
hInsertAfter,
Expand Down
2 changes: 1 addition & 1 deletion adodbapi/adodbapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -1208,7 +1208,7 @@ def setoutputsize(self, size, column=None):

def _last_query(self): # let the programmer see what query we actually used
try:
if self.parameters == None:
if self.parameters is None:
ret = self.commandText
else:
ret = "%s,parameters=%s" % (self.commandText, repr(self.parameters))
Expand Down
6 changes: 3 additions & 3 deletions adodbapi/apibase.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ def __init__(self): # the details will be filled in by instances
self._ordinal_1899_12_31 = datetime.date(1899, 12, 31).toordinal() - 1
# Use cls.types to compare if an input parameter is a datetime
self.types = {
# Dynamically get the types as the methods may be overriden
type(self.Date(2000, 1, 1)),
type(self.Time(12, 1, 1)),
type(self.Timestamp(2000, 1, 1, 12, 1, 1)),
Expand Down Expand Up @@ -444,9 +445,8 @@ def pyTypeToADOType(d):
except KeyError: # The type was not defined in the pre-computed Type table
from . import dateconverter

if (
tp in dateconverter.types
): # maybe it is one of our supported Date/Time types
# maybe it is one of our supported Date/Time types
if tp in dateconverter.types:
return adc.adDate
# otherwise, attempt to discern the type by probing the data object itself -- to handle duck typing
if isinstance(d, StringTypes):
Expand Down
4 changes: 2 additions & 2 deletions adodbapi/remote/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,15 @@ def unfixpickle(x):
# for 'named' paramstyle user will pass a mapping
newargs = {}
for arg, val in list(x.items()):
if isinstance(arg, type(array.array("B"))):
if isinstance(arg, array.array):
newargs[arg] = Binary(val)
else:
newargs[arg] = val
return newargs
# if not a mapping, then a sequence
newargs = []
for arg in x:
if isinstance(arg, type(array.array("B"))):
if isinstance(arg, array.array):
newargs.append(Binary(arg))
else:
newargs.append(arg)
Expand Down
12 changes: 6 additions & 6 deletions adodbapi/test/adodbapitest.py
Original file line number Diff line number Diff line change
Expand Up @@ -1025,7 +1025,7 @@ def testRollBack(self):
self.conn.rollback()
crsr.execute(selectSql)
assert (
crsr.fetchone() == None
crsr.fetchone() is None
), "cursor.fetchone should return None if a query retrieves no rows"
crsr.execute("SELECT fldData from xx_%s" % config.tmp)
rs = crsr.fetchall()
Expand Down Expand Up @@ -1082,7 +1082,7 @@ def testAutoRollback(self):
row = crsr.fetchone()
except api.DatabaseError:
row = None # if the entire table disappeared the rollback was perfect and the test passed
assert row == None, (
assert row is None, (
"cursor.fetchone should return None if a query retrieves no rows. Got %s"
% repr(row)
)
Expand Down Expand Up @@ -1257,7 +1257,7 @@ def testMultipleSetReturn(self):
assert crsr.nextset() == True, "third set should be present"
rowdesc = crsr.fetchall()
self.assertEqual(rowdesc[0][0], 8)
assert crsr.nextset() == None, "No more return sets, should return None"
assert crsr.nextset() is None, "No more return sets, should return None"

self.helpRollbackTblTemp()

Expand Down Expand Up @@ -1348,7 +1348,7 @@ def getAnotherConnection(self, addkeys=None):

def testOkConnect(self):
c = self.db(*config.connStrAccess[0], **config.connStrAccess[1])
assert c != None
assert c is not None
c.close()


Expand Down Expand Up @@ -1384,7 +1384,7 @@ def getAnotherConnection(self, addkeys=None):

def testOkConnect(self):
c = self.db(*config.connStrMySql[0], **config.connStrMySql[1])
assert c != None
assert c is not None

# def testStoredProcedure(self):
# crsr=self.conn.cursor()
Expand Down Expand Up @@ -1450,7 +1450,7 @@ def getAnotherConnection(self, addkeys=None):

def testOkConnect(self):
c = self.db(*config.connStrPostgres[0], **config.connStrPostgres[1])
assert c != None
assert c is not None

# def testStoredProcedure(self):
# crsr=self.conn.cursor()
Expand Down
2 changes: 1 addition & 1 deletion adodbapi/test/test_adodbapi_dbapi20.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ def test_nextset(self):
names = cur.fetchall()
assert len(names) == len(self.samples)
s = cur.nextset()
assert s == None, "No more return sets, should return None"
assert s is None, "No more return sets, should return None"
finally:
try:
self.help_nextset_tearDown(cur)
Expand Down
2 changes: 1 addition & 1 deletion com/win32com/client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@ def _get_good_object_(self, obj, obUserName=None, resultCLSID=None):

# XXX - These should be consolidated with dynamic.py versions.
def _get_good_single_object_(obj, obUserName=None, resultCLSID=None):
if _PyIDispatchType == type(obj):
if isinstance(obj, _PyIDispatchType):
return Dispatch(obj, obUserName, resultCLSID)
return obj

Expand Down
Loading