Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix F841 flake8 errors #923

Merged
merged 5 commits into from
Apr 1, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 0 additions & 2 deletions pyface/action/tests/test_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ def test_append_action(self):

def test_append_callable(self):
group = Group(self.action_item)
action2 = Action(name="Action 2")
# XXX items doesn't fire a change event. Should it?
group.append(self.perform)
self.assertEqual(len(group.items), 2)
Expand Down Expand Up @@ -118,7 +117,6 @@ def test_insert_action(self):

def test_insert_callable(self):
group = Group(self.action_item)
action2 = Action(name="Action 2")
# XXX items doesn't fire a change event. Should it?
group.insert(1, self.perform)
self.assertEqual(len(group.items), 2)
Expand Down
12 changes: 6 additions & 6 deletions pyface/tests/test_image_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@ def setUp(self):
self.image_cache = ImageCache(32, 32)

def test_get_image(self):
image = self.image_cache.get_image(IMAGE_PATH)
self.image_cache.get_image(IMAGE_PATH)

def test_get_bitmap(self):
bitmap = self.image_cache.get_bitmap(IMAGE_PATH)
self.image_cache.get_bitmap(IMAGE_PATH)

def test_get_image_twice(self):
image1 = self.image_cache.get_image(IMAGE_PATH)
image2 = self.image_cache.get_image(IMAGE_PATH)
self.image_cache.get_image(IMAGE_PATH)
self.image_cache.get_image(IMAGE_PATH)

def test_get_bitmap_twice(self):
bitmap1 = self.image_cache.get_bitmap(IMAGE_PATH)
bitmap2 = self.image_cache.get_bitmap(IMAGE_PATH)
self.image_cache.get_bitmap(IMAGE_PATH)
self.image_cache.get_bitmap(IMAGE_PATH)

def test_get_image_different_sizes(self):
other_image_cache = ImageCache(48, 48)
Expand Down
4 changes: 2 additions & 2 deletions pyface/tests/test_resource_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ def setUp(self):
self.resource_factory = PyfaceResourceFactory()

def test_image_from_file(self):
image = self.resource_factory.image_from_file(IMAGE_PATH)
self.resource_factory.image_from_file(IMAGE_PATH)

def test_image_from_data(self):
with open(IMAGE_PATH, "rb") as fp:
data = fp.read()
image = self.resource_factory.image_from_data(data)
self.resource_factory.image_from_data(data)

def test_locate_image(self):
class ASequence(Sequence):
Expand Down
4 changes: 2 additions & 2 deletions pyface/tests/test_toolkit.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ def test_missing_import(self):
# test that we get an undefined object if no toolkit implementation
cls = pyface.toolkit.toolkit_object("tests:Missing")
with self.assertRaises(NotImplementedError):
obj = cls()
cls()

def test_bad_import(self):
# test that we don't filter unrelated import errors
with self.assertRaises(ImportError):
cls = pyface.toolkit.toolkit_object("tests.bad_import:Missing")
pyface.toolkit.toolkit_object("tests.bad_import:Missing")

def test_core_plugins(self):
# test that we can see appropriate core entrypoints
Expand Down
2 changes: 1 addition & 1 deletion pyface/tests/test_ui_traits.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def test_init_pyface_image(self):
from pyface.image_resource import ImageResource

image_class = ImageClass(image="about")
im = image_class.image.create_image()
image_class.image.create_image()

self.assertIsInstance(image_class.image, ImageResource)
self.assertEqual(image_class.image.name, "about")
Expand Down
10 changes: 1 addition & 9 deletions pyface/ui/null/action/action_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,7 @@ def __init__(
# If the action has an image then convert it to a bitmap (as required
# by the toolbar).
if action.image is not None:
image = action.image.create_image()
path = action.image.absolute_path
bmp = image_cache.get_bitmap(path)

else:
from pyface.api import ImageResource

image = ImageResource("foo")
bmp = image.create_bitmap()
action.image.create_image()
rahulporuri marked this conversation as resolved.
Show resolved Hide resolved

self.control_id = 1
self.control = None
Expand Down
1 change: 0 additions & 1 deletion pyface/ui/qt4/about_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ def _create_contents(self, parent):

def _create_html(self):
# Load the image to be displayed in the about box.
image = self.image.create_image()
path = self.image.absolute_path

# The additional strings.
Expand Down
3 changes: 0 additions & 3 deletions pyface/ui/qt4/action/action_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,6 @@ def __init__(self, tool_palette, image_cache, item, show_labels):
# And they never contain shortcuts.
label = label.replace("&", "")

image = action.image.create_image()
path = action.image.absolute_path
bmp = image_cache.get_bitmap(path)

Expand Down Expand Up @@ -574,8 +573,6 @@ def _on_tool(self, event):
action = self.item.action
action_event = ActionEvent()

is_checkable = action.style == "radio" or action.style == "check"

# Perform the action!
action.checked = self.tool_palette.get_tool_state(self.tool_id) == 1
action.perform(action_event)
Expand Down
2 changes: 1 addition & 1 deletion pyface/ui/qt4/clipboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def _get_object_data(self):
mime_data = cb.mimeData()
if mime_data.hasFormat(PYTHON_TYPE):
serialized_data = BytesIO(mime_data.data(PYTHON_TYPE).data())
klass = load(serialized_data)
_ = load(serialized_data)
rahulporuri marked this conversation as resolved.
Show resolved Hide resolved
obj = load(serialized_data)
return obj

Expand Down
2 changes: 0 additions & 2 deletions pyface/ui/qt4/code_editor/code_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -517,11 +517,9 @@ def _show_selected_blocks(self, selected_blocks):
def _get_selected_blocks(self):
cursor = self.textCursor()
if cursor.position() > cursor.anchor():
move_op = QtGui.QTextCursor.PreviousBlock
start_pos = cursor.anchor()
end_pos = cursor.position()
else:
move_op = QtGui.QTextCursor.NextBlock
start_pos = cursor.position()
end_pos = cursor.anchor()

Expand Down
1 change: 0 additions & 1 deletion pyface/ui/qt4/console/call_tip_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ def show_tip(self, tip):
"""
# Attempt to find the cursor position at which to show the call tip.
text_edit = self._text_edit
document = text_edit.document()
cursor = text_edit.textCursor()
search_pos = cursor.position() - 1
self._start_position, _ = self._find_parenthesis(
Expand Down
3 changes: 1 addition & 2 deletions pyface/ui/qt4/python_shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ def _execute(self, source, hidden):
# Run the source code in the interpeter
self._hidden = hidden
try:
more = self.interpreter.runsource(source)
self.interpreter.runsource(source)
finally:
self._hidden = False

Expand Down Expand Up @@ -499,7 +499,6 @@ def _document_contents_change(self, position, removed, added):
# Calculate where the cursor should be *after* the change:
position += added

document = self._control.document()
if position == self._get_cursor().position():
self._call_tip()

Expand Down
4 changes: 2 additions & 2 deletions pyface/ui/qt4/tasks/advanced_editor_area_pane.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def create(self, parent):
""" Create and set the toolkit-specific control that represents the
pane.
"""
self.control = control = EditorAreaWidget(self, parent)
self.control = EditorAreaWidget(self, parent)
self._filter = EditorAreaDropFilter(self)
self.control.installEventFilter(self._filter)

Expand Down Expand Up @@ -582,7 +582,7 @@ def _focus_changed(self, old, new):
for editor in self.editor_area.editors:
control = editor.control
if control is not None and control.isAncestorOf(new):
self.editor_area.active_editor = focused = editor
self.editor_area.active_editor = editor
break
else:
if not self.editor_area.editors:
Expand Down
5 changes: 1 addition & 4 deletions pyface/ui/qt4/tasks/tests/test_split_editor_area_pane.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,8 @@ def test_collapse_nonempty(self):
the tabs of the collapsing tabwidgets.
"""
# setup root
root, left, right = self._setUp_collapse()
btn0 = left.tabwidget().widget(0)
btn1 = left.tabwidget().widget(1)
root, _, right = self._setUp_collapse()
btn2 = right.tabwidget().widget(0)
btn3 = right.tabwidget().widget(1)

# perform collapse on rightchild
root.rightchild.collapse()
Expand Down
2 changes: 1 addition & 1 deletion pyface/ui/qt4/util/tests/test_image_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def test_qimage_to_array_bad(self):
qimage.fill(QColor(0x44, 0x88, 0xcc))

with self.assertRaises(ValueError):
array = QImage_to_array(qimage)
QImage_to_array(qimage)

@unittest.skipIf(
qt_api == 'pyside2' and sys.platform == 'linux',
Expand Down
5 changes: 0 additions & 5 deletions pyface/ui/wx/action/action_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,8 +491,6 @@ def _on_tool(self, event):
action = self.item.action
action_event = ActionEvent()

is_checkable = action.style == "radio" or action.style == "check"

# Perform the action!
if self.controller is not None:
# fixme: There is a difference here between having a controller
Expand Down Expand Up @@ -566,7 +564,6 @@ def __init__(self, tool_palette, image_cache, item, show_labels):
# And they never contain shortcuts.
label = label.replace("&", "")

image = action.image.create_image()
path = action.image.absolute_path
bmp = image_cache.get_bitmap(path)

Expand Down Expand Up @@ -633,8 +630,6 @@ def _on_tool(self, event):
action = self.item.action
action_event = ActionEvent()

is_checkable = action.style == "radio" or action.style == "check"

# Perform the action!
action.checked = self.tool_palette.get_tool_state(self.tool_id) == 1
action.perform(action_event)
Expand Down
2 changes: 0 additions & 2 deletions pyface/ui/wx/action/tool_bar_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,6 @@ def InsertToolInOrder(self, tool_id):
orig_pos, tool = self.tool_map[tool_id]
pos = -1
for pos in range(self.GetToolsCount()):
existing_tool = self.GetToolByPos(pos)
existing_id = existing_tool.GetId()
existing_orig_pos, _ = self.tool_map[tool_id]
if existing_orig_pos > orig_pos:
break
Expand Down
8 changes: 4 additions & 4 deletions pyface/ui/wx/action/tool_palette_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,15 @@ def create_tool_palette(self, parent, controller=None):
def _add_tools(self, tool_palette, groups):
""" Adds tools for all items in a list of groups. """

previous_non_empty_group = None
# previous_non_empty_group = None
for group in self.groups:
if len(group.items) > 0:
# Is a separator required?
## FIXME : Does the palette need the notion of a separator?
## if previous_non_empty_group is not None and group.separator:
## tool_bar.AddSeparator()
## if previous_non_empty_group is not None and group.separator:
## tool_bar.AddSeparator()
##
## previous_non_empty_group = group
## previous_non_empty_group = group
Comment on lines +85 to +88
Copy link
Contributor

Choose a reason for hiding this comment

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

why not just delete the commented code?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't have a very good reason here. It just looked like meaningful code and that there might be some value in keeping it.


# Create a tool bar tool for each item in the group.
for item in group.items:
Expand Down
1 change: 0 additions & 1 deletion pyface/ui/wx/grid/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -1055,7 +1055,6 @@ def _on_key_down(self, evt):
#
# Don't change the behavior if the <Control> key is pressed as this
# has meaning to the edit control.
key_code = evt.GetKeyCode()

evt.Skip()

Expand Down
2 changes: 1 addition & 1 deletion pyface/ui/wx/grid/grid_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ def set_value(self, row, col, value):
value = float(value)
except ValueError:
value = value
rows_appended = self._set_value(row, col, value)
self._set_value(row, col, value)

self.fire_content_changed()

Expand Down
3 changes: 0 additions & 3 deletions pyface/ui/wx/grid/tests/test_simple_grid_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,6 @@ def test_get_value(self):

def test_is_cell_empty(self):

rows = self.model.get_row_count()
columns = self.model.get_column_count()

self.assertEqual(
rahulporuri marked this conversation as resolved.
Show resolved Hide resolved
self.model.is_cell_empty(0, 0),
True,
Expand Down
2 changes: 1 addition & 1 deletion pyface/ui/wx/grid/trait_grid_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@ def __get_column_name(self, col):

def __get_column_typename(self, col):

name = column = self.__get_column(col)
column = self.__get_column(col)
typename = None
if isinstance(column, TraitGridColumn):
typename = column.typename
Expand Down
2 changes: 1 addition & 1 deletion pyface/ui/wx/ipython_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def is_complete(self, string):
clean_string, "<string>", "exec"
)
self.release_output()
except Exception as e:
except Exception:
# XXX: Hack: return True so that the
# code gets executed and the error captured.
is_complete = True
Expand Down
3 changes: 0 additions & 3 deletions pyface/ui/wx/tasks/editor_area_pane.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,4 @@ def _update_active_editor(self, evt):
@observe("hide_tab_bar")
def _update_tab_bar(self, event):
if self.control is not None:
visible = (
self.control.GetPageCount() > 1 if self.hide_tab_bar else True
)
pass # Can't actually hide the tab bar on wx.aui
1 change: 0 additions & 1 deletion pyface/ui/wx/tree/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -882,7 +882,6 @@ def _on_nodes_removed(self, event):
""" Called when nodes have been removed. """
node_event = event.new
parent = node_event.node
children = node_event.children

# Has the node actually appeared in the tree yet?
pid = self._get_wxid(parent)
Expand Down
3 changes: 0 additions & 3 deletions pyface/ui/wx/viewer/table_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,6 @@ def __init__(self, parent, image_size=(16, 16), **traits):
# Create the toolkit-specific control.
self.control = table = _Table(parent, image_size, self)

# Get our actual id.
wxid = table.GetId()

# Table events.
table.Bind(wx.EVT_LIST_ITEM_SELECTED, self._on_item_selected)
table.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self._on_item_activated)
Expand Down
3 changes: 0 additions & 3 deletions pyface/ui/wx/viewer/tree_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,6 @@ def __init__(self, parent, image_size=(16, 16), **traits):
# Create the toolkit-specific control.
self.control = tree = wx.TreeCtrl(parent, -1, style=self._get_style())

# Get our actual Id.
wxid = tree.GetId()

# Wire up the wx tree events.
tree.Bind(wx.EVT_CHAR, self._on_char)
tree.Bind(wx.EVT_LEFT_DOWN, self._on_left_down)
Expand Down
10 changes: 0 additions & 10 deletions pyface/viewer/default_tree_content_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,30 +50,20 @@ def insert_before(self, parent, before, child):

index, child = parent.insert_before(before, child)

# Trait notification.
# self.items_inserted(parent, [index], [child])

return (index, child)

def insert(self, parent, index, child):
""" Inserts 'child' into the 'parent' item at 'index'. """

parent.insert(index, child)

# Trait notification.
# self.items_inserted(parent, [index], [child])

return child

def remove(self, parent, child):
""" Removes 'child' from the 'parent' item. """

index = parent.children.index(child)
parent.remove(child)

# Trait notification.
# self.items_removed(parent, [index], [child])

return child

# ------------------------------------------------------------------------
Expand Down
1 change: 0 additions & 1 deletion pyface/wx/aui.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ def CalculateDockSizerLimits(self, dock):
docks, panes = aui.CopyDocksAndPanes2(self._docks, self._panes)

sash_size = self._art.GetMetric(aui.AUI_DOCKART_SASH_SIZE)
caption_size = self._art.GetMetric(aui.AUI_DOCKART_CAPTION_SIZE)
opposite_size = self.GetOppositeDockTotalSize(
docks, dock.dock_direction
)
Expand Down
Loading