Skip to content
8 changes: 4 additions & 4 deletions AutoDuck/py2d.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import re
import sys
import types
import re


def ad_escape(s):
Expand Down Expand Up @@ -108,9 +108,9 @@ def build_module(fp, mod_name):
continue
if type(ob) in (type, 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
13 changes: 4 additions & 9 deletions Pythonwin/pywin/Demos/dlgtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,11 @@
#
# ID's for the tabstop dialog - out test.
#
from win32ui import IDD_SET_TABSTOPS
from win32ui import IDC_EDIT_TABS
from win32ui import IDC_PROMPT_TABS
from win32con import IDOK
from win32con import IDCANCEL

import win32ui
import win32con

import win32ui
from pywin.mfc import dialog
from win32con import IDCANCEL, IDOK
from win32ui import IDC_EDIT_TABS, IDC_PROMPT_TABS, IDD_SET_TABSTOPS


class TestDialog(dialog.Dialog):
Expand Down Expand Up @@ -56,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
3 changes: 2 additions & 1 deletion Pythonwin/pywin/debugger/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def _CheckNeedGUI():
need = 0
if need:
import pywin.framework.app

from . import dbgpyapp

pywin.framework.app.CreateDefaultGUI(dbgpyapp.DebuggerPythonApp)
Expand Down Expand Up @@ -122,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
22 changes: 11 additions & 11 deletions Pythonwin/pywin/debugger/debugger.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,23 @@
# >>> import pywin.debugger
# >>> pywin.debugger.GetDebugger().run("command")

import pdb
import bdb
import sys
import string
import os
import pdb
import string
import sys
import traceback
import types

import win32ui
import commctrl
import pywin.docking.DockingBar
import win32api
import win32con
import pywin.docking.DockingBar
from pywin.mfc import dialog, object, afxres, window
from pywin.framework import app, interact, editor, scriptutils
from pywin.framework.editor.color.coloreditor import MARKER_CURRENT, MARKER_BREAKPOINT
import win32ui
from pywin.framework import app, editor, interact, scriptutils
from pywin.framework.editor.color.coloreditor import MARKER_BREAKPOINT, MARKER_CURRENT
from pywin.mfc import afxres, dialog, object, window
from pywin.tools import browser, hierlist
import commctrl
import traceback

# import win32traceutil
if win32ui.UNICODE:
Expand Down 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
4 changes: 2 additions & 2 deletions Pythonwin/pywin/dialogs/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
Merged with dlgpass and moved to pywin.dialogs by Mark Hammond Jan 1998.
"""

import win32ui
import win32api
import win32con
import win32ui
from pywin.mfc import dialog


Expand Down 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
17 changes: 9 additions & 8 deletions Pythonwin/pywin/framework/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@
#
# We also grab the FileOpen command, to invoke our Python editor
" The PythonWin application code. Manages most aspects of MDI, etc "
import win32con
import win32api
import win32ui
import sys
import string
import os
from pywin.mfc import window, dialog, afxres
from pywin.mfc.thread import WinApp
import string
import sys
import traceback

import regutil
import win32api
import win32con
import win32ui
from pywin.mfc import afxres, dialog, window
from pywin.mfc.thread import WinApp

from . import scriptutils

Expand Down Expand Up @@ -411,7 +412,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
22 changes: 15 additions & 7 deletions Pythonwin/pywin/framework/mdi_pychecker.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,19 @@
##
######################################################################

import win32ui
import glob
import os
import re
import stat
import string
import sys
import time

import win32api
from pywin.mfc import docview, dialog, window
import win32con
import sys, string, re, glob, os, stat, time
import win32ui
from pywin.mfc import dialog, docview, window

from . import scriptutils


Expand Down Expand Up @@ -131,11 +139,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, (type(self), list)):
return self.dirs + other.dirs

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


Expand Down Expand Up @@ -313,7 +321,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 @@ -383,7 +391,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
21 changes: 11 additions & 10 deletions Pythonwin/pywin/framework/sgrepmdi.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,17 @@
# Hats off to Mark Hammond for providing an environment where I could cobble
# something like this together in a couple evenings!

import win32ui
import win32api
from pywin.mfc import docview, dialog, window
import win32con
import string
import re
import glob
import os
import re
import stat
import glob
import string

import win32api
import win32con
import win32ui
from pywin.mfc import dialog, docview, window

from . import scriptutils


Expand Down Expand Up @@ -121,11 +122,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, (type(self), list)):
return self.dirs + other.dirs

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


Expand Down Expand Up @@ -303,7 +304,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
22 changes: 14 additions & 8 deletions Pythonwin/pywin/framework/winout.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,16 @@
# This module is thread safe - output can originate from any thread. If any thread
# other than the main thread attempts to print, it is always queued until next idle time

import sys, string, re
from pywin.mfc import docview
from pywin.framework import app, window
import win32ui, win32api, win32con
import queue
import re
import string
import sys

import win32api
import win32con
import win32ui
from pywin.framework import app, window
from pywin.mfc import docview

debug = lambda msg: None

Expand All @@ -43,8 +48,8 @@ class flags:
# WindowOutputDocumentParent=docview.RichEditDoc
# WindowOutputDocumentParent=docview.Document
import pywin.scintilla.document
from pywin.scintilla import scintillacon
from pywin import default_scintilla_encoding
from pywin.scintilla import scintillacon

WindowOutputDocumentParent = pywin.scintilla.document.CScintillaDocument

Expand Down Expand Up @@ -126,7 +131,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 All @@ -144,7 +149,8 @@ def HandleSpecialLine(self):
# An OLE Exception - pull apart the exception
# and try and locate a help file.
try:
import win32api, win32con
import win32api
import win32con

det = eval(line[line.find(":") + 1 :].strip())
win32ui.SetStatusText("Opening help file on OLE error...")
Expand Down Expand Up @@ -373,7 +379,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
18 changes: 9 additions & 9 deletions Pythonwin/pywin/mfc/dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@
# dialog.py
# Python class for Dialog Boxes in PythonWin.

import win32ui
import win32con
import win32ui

# sob - 2to3 doesn't see this as a relative import :(
from pywin.mfc import window


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,10 +33,10 @@ 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 :)

dlg = win32ui.CreateDialogIndirect(id)
else:
if isinstance(id, int):
dlg = win32ui.CreateDialog(id, self.dll)
else: # a template
dlg = win32ui.CreateDialogIndirect(id)
window.Wnd.__init__(self, dlg)
self.HookCommands()
self.bHaveInit = None
Expand Down Expand Up @@ -114,7 +114,7 @@ def __init__(
dllid=None,
):
self.dll = dllFromDll(dllid)
if type(dlgID) == type([]): # a template
if not isinstance(dlgID, int): # 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
Loading