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

SG-36835 Python 2 removal #197

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
8 changes: 6 additions & 2 deletions hooks/collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@
import os
import sgtk
from tank import TankError
from tank_vendor import six

try:
from tank_vendor import sgutils
except ImportError:
from tank_vendor import six as sgutils

HookBaseClass = sgtk.get_hook_baseclass()

Expand Down Expand Up @@ -429,7 +433,7 @@ def _get_item_info(self, path):
# the system's default encoding. If a unicode string is
# returned, we simply ensure it's utf-8 encoded to avoid issues
# with toolkit, which expects utf-8
category_type = six.ensure_str(category_type)
category_type = sgutils.ensure_str(category_type)
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems category_type can be a Optional[str] type according to the documentation of guess_type function: https://docs.python.org/3.9/library/mimetypes.html#mimetypes.guess_type. So I think it can be safe to use just str.

The main difference here with ensure_str is that this function will raise an error when the argument is None, instead of converting None to 'None'.


# the category portion of the mimetype
category = category_type.split("/")[0]
Expand Down
8 changes: 6 additions & 2 deletions hooks/upload_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@
import os
import pprint
import sgtk
from tank_vendor import six

try:
from tank_vendor import sgutils
except ImportError:
from tank_vendor import six as sgutils

HookBaseClass = sgtk.get_hook_baseclass()

Expand Down Expand Up @@ -305,7 +309,7 @@ def publish(self, settings, item):
# on windows, ensure the path is utf-8 encoded to avoid issues with
# the shotgun api
if sgtk.util.is_windows():
upload_path = six.ensure_text(path)
upload_path = sgutils.ensure_text(path)
else:
upload_path = path

Expand Down
2 changes: 1 addition & 1 deletion python/tk_multi_publish2/api/plugins/instance_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def __init__(self, path, settings, publish_logger):
:param publish_logger: a logger object that will be used by the hook
"""

super(PluginInstanceBase, self).__init__()
super().__init__()

if not publish_logger:
publish_logger = logger
Expand Down
24 changes: 11 additions & 13 deletions python/tk_multi_publish2/api/plugins/publish_plugin_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,13 @@
# agreement to the Shotgun Pipeline Toolkit Source Code License. All rights
# not expressly granted therein are reserved by Shotgun Software Inc.

from contextlib import contextmanager
import traceback

try:
# In Python 3 the interface changed, getargspec is now deprecated.
# getfullargspec was deprecated in 3.5, but that was reversed in 3.6.
from inspect import getfullargspec as getargspec
except ImportError:
# Fallback for Python 2
from inspect import getargspec

import sgtk

from contextlib import contextmanager
from inspect import getfullargspec
julien-lang marked this conversation as resolved.
Show resolved Hide resolved

from .instance_base import PluginInstanceBase

logger = sgtk.platform.get_logger(__name__)
Expand All @@ -44,7 +39,7 @@ def __init__(self, name, path, settings, publish_logger=None):

self._icon_pixmap = None

super(PublishPluginInstance, self).__init__(path, settings, publish_logger)
super().__init__(path, settings, publish_logger)

def _create_hook_instance(self, path):
"""
Expand Down Expand Up @@ -234,7 +229,10 @@ def run_create_settings_widget(self, parent, items):

with self._handle_plugin_error(None, "Error laying out widgets: %s"):

if len(getargspec(self._hook_instance.create_settings_widget).args) == 3:
if (
len(getfullargspec(self._hook_instance.create_settings_widget).args)
== 3
):
return self._hook_instance.create_settings_widget(parent, items)
else:
# Items is a newer attribute, which an older version of the hook
Expand All @@ -257,7 +255,7 @@ def run_get_ui_settings(self, parent, items):

with self._handle_plugin_error(None, "Error reading settings from UI: %s"):

if len(getargspec(self._hook_instance.get_ui_settings).args) == 3:
if len(getfullargspec(self._hook_instance.get_ui_settings).args) == 3:
return self._hook_instance.get_ui_settings(parent, items)
else:
# Items is a newer attribute, which an older version of the hook
Expand All @@ -283,7 +281,7 @@ def run_set_ui_settings(self, parent, settings, items):

with self._handle_plugin_error(None, "Error writing settings to UI: %s"):

if len(getargspec(self._hook_instance.set_ui_settings).args) == 4:
if len(getfullargspec(self._hook_instance.set_ui_settings).args) == 4:
self._hook_instance.set_ui_settings(parent, settings, items)
else:
# Items is a newer attribute, which an older version of the hook
Expand Down
2 changes: 1 addition & 1 deletion python/tk_multi_publish2/api/plugins/setting.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def __init__(self, name, data_type, default_value, description=None):
configured ``PluginSettings``.
"""

super(PluginSetting, self).__init__()
super().__init__()

self.default_value = default_value
self.description = description
Expand Down
3 changes: 1 addition & 2 deletions python/tk_multi_publish2/api/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
# agreement to the Shotgun Pipeline Toolkit Source Code License. All rights
# not expressly granted therein are reserved by Shotgun Software Inc.

from __future__ import print_function
import traceback

import datetime
Expand Down Expand Up @@ -348,7 +347,7 @@ def default(self, data):
elif type(data) is datetime.datetime:
return {"_sgtk_custom_type": "datetime.datetime", "value": data.isoformat()}
else:
return super(_PublishTreeEncoder, self).default(data)
return super().default(data)


def _json_to_objects(data):
Expand Down
13 changes: 7 additions & 6 deletions python/tk_multi_publish2/dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@

import sgtk
from sgtk.platform.qt import QtCore, QtGui
from tank_vendor import six

try:
from tank_vendor import sgutils
except ImportError:
from tank_vendor import six as sgutils

from .api import PublishManager, PublishItem, PublishTask
from .ui.dialog import Ui_Dialog
Expand Down Expand Up @@ -286,7 +290,7 @@ def keyPressEvent(self, event):
self._progress_handler.hide_details()

else:
super(AppDialog, self).keyPressEvent(event)
super().keyPressEvent(event)

def closeEvent(self, event):
"""
Expand Down Expand Up @@ -870,7 +874,7 @@ def _on_drop(self, files):
self._progress_handler.push("Processing external files...")

# pyside gives us back unicode. Make sure we convert it to strings
str_files = [six.ensure_str(f) for f in files]
str_files = [sgutils.ensure_str(f) for f in files]

try:
self.ui.main_stack.setCurrentIndex(self.PUBLISH_SCREEN)
Expand Down Expand Up @@ -1780,6 +1784,3 @@ def __bool__(self):
:returns: ``True`` is the selection is not empty, ``False`` otherwise.
"""
return bool(self._items)

# To maintain Python 2 compatibility, define __nonzero__ as well as __bool__
__nonzero__ = __bool__
2 changes: 1 addition & 1 deletion python/tk_multi_publish2/drop_area.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def __init__(self, *args, **kwargs):
:param args: Arbitrary list of parameters used in base class init
:param args: Arbitrary dictionary of parameters used in base class init
"""
super(WrappedClass, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)
self.setAcceptDrops(True)
self._set_property("dragging", False)
self._restrict_to_ext = []
Expand Down
2 changes: 1 addition & 1 deletion python/tk_multi_publish2/progress/more_info_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def __init__(self, pixmap, message, text, parent):
:param parent: The parent widget
"""

super(MoreInfoDialog, self).__init__(parent)
super().__init__(parent)

# set up the UI
self.ui = Ui_MoreInfoWidget()
Expand Down
4 changes: 2 additions & 2 deletions python/tk_multi_publish2/progress/progress_details_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def __init__(self, parent):
:param parent: The model parent.
:type parent: :class:`~PySide.QtGui.QObject`
"""
super(ProgressDetailsWidget, self).__init__()
super().__init__()

self._bundle = sgtk.platform.current_bundle()

Expand Down Expand Up @@ -94,7 +94,7 @@ def toggle(self):
self.show()

def show(self):
super(ProgressDetailsWidget, self).show()
super().show()
self.__recompute_position()
self.ui.log_tree.expandAll()

Expand Down
2 changes: 1 addition & 1 deletion python/tk_multi_publish2/progress/progress_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def __init__(self, icon_label, status_label, progress_bar):
:param parent: The model parent.
:type parent: :class:`~PySide.QtGui.QObject`
"""
super(ProgressHandler, self).__init__()
super().__init__()

self._icon_label = icon_label
self._status_label = status_label
Expand Down
8 changes: 4 additions & 4 deletions python/tk_multi_publish2/progress_status_label.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def __init__(self, parent=None):
"""
:param parent: The parent QWidget for this control
"""
super(ProgressStatusLabel, self).__init__(parent)
super().__init__(parent)

# for the hover behavior
self.setMouseTracking(True)
Expand All @@ -44,15 +44,15 @@ def mousePressEvent(self, event):
"""
Fires when the mouse is pressed
"""
super(ProgressStatusLabel, self).mousePressEvent(event)
super().mousePressEvent(event)
self.clicked.emit()

def resizeEvent(self, event):
"""
When item is resized
"""
self.__update_text_elide()
super(ProgressStatusLabel, self).resizeEvent(event)
super().resizeEvent(event)

def __update_text_elide(self):
"""
Expand Down Expand Up @@ -85,4 +85,4 @@ def setText(self, message, compute_elide=True):
self.__update_text_elide()
else:
# called from __update_text_elide()
super(ProgressStatusLabel, self).setText(message)
super().setText(message)
4 changes: 2 additions & 2 deletions python/tk_multi_publish2/publish_description_edit.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def __init__(self, parent):

:param parent: QT parent object
"""
super(PublishDescriptionEdit, self).__init__(parent)
super().__init__(parent)

self._show_multiple_values = False

Expand Down Expand Up @@ -59,4 +59,4 @@ def paintEvent(self, paint_event):
)

else:
super(PublishDescriptionEdit, self).paintEvent(paint_event)
super().paintEvent(paint_event)
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def __init__(self, tree_node, parent=None):
"""
:param parent: The parent QWidget for this control
"""
super(CustomTreeWidgetBase, self).__init__(parent)
super().__init__(parent)
self._tree_node = tree_node

self._icon_lookup = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def __init__(self, tree_node, parent=None):
"""
:param parent: The parent QWidget for this control
"""
super(CustomTreeWidgetContext, self).__init__(tree_node, parent)
super().__init__(tree_node, parent)

# set up the UI
self.ui = Ui_ContextWidget()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def __init__(self, tree_node, parent=None):
"""
:param parent: The parent QWidget for this control
"""
super(CustomTreeWidgetItem, self).__init__(tree_node, parent)
super().__init__(tree_node, parent)

# set up the UI
self.ui = Ui_ItemWidget()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def __init__(self, tree_node, parent=None):
"""
:param parent: The parent QWidget for this control
"""
super(CustomTreeWidgetSummary, self).__init__(tree_node, parent)
super().__init__(tree_node, parent)

# set up the UI
self.ui = Ui_SummaryWidget()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def __init__(self, tree_node, parent=None):
"""
:param parent: The parent QWidget for this control
"""
super(CustomTreeWidgetTask, self).__init__(tree_node, parent)
super().__init__(tree_node, parent)

# set up the UI
self.ui = Ui_TaskWidget()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def __init__(self, parent):
"""
:param parent: The parent QWidget for this control
"""
super(PublishTreeWidget, self).__init__(parent)
super().__init__(parent)
self._publish_manager = None
self._selected_items_state = []
self._bundle = sgtk.platform.current_bundle()
Expand Down Expand Up @@ -98,7 +98,7 @@ def drawBranches(self, painter, rect, index):
to paint in the remainder of the selection box covering the branch area.
"""
# First draw the default visuals for the branch.
super(PublishTreeWidget, self).drawBranches(painter, rect, index)
super().drawBranches(painter, rect, index)

if index in self.selectedIndexes():
# Draw the selection boarder around the shifted item.
Expand Down Expand Up @@ -503,7 +503,7 @@ def dropEvent(self, event):
"""

# run default implementation
super(PublishTreeWidget, self).dropEvent(event)
super().dropEvent(event)

for ui_item, state in self._selected_items_state:

Expand Down Expand Up @@ -558,7 +558,7 @@ def dragEnterEvent(self, event):

self._selected_items_state = selected_items_state

super(PublishTreeWidget, self).dragEnterEvent(event)
super().dragEnterEvent(event)

def mouseMoveEvent(self, event):
"""
Expand All @@ -568,7 +568,7 @@ def mouseMoveEvent(self, event):
"""
if self.state() != QtGui.QAbstractItemView.DragSelectingState:
# bubble up all events that aren't drag select related
super(PublishTreeWidget, self).mouseMoveEvent(event)
super().mouseMoveEvent(event)


def _init_item_r(parent_item):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def __init__(self, parent):
"""
:param parent: The parent QWidget for this control
"""
super(TreeNodeBase, self).__init__(parent)
super().__init__(parent)
self.build_internal_widget()

self.setFlags(QtCore.Qt.ItemIsEnabled)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def __init__(self, context, parent):
:param parent: The parent QWidget for this control
"""
self._context = context
super(TreeNodeContext, self).__init__(parent)
super().__init__(parent)

# this object can have other items dropped on it
# but cannot be dragged
Expand Down
Loading