Skip to content

Commit

Permalink
Python 3: use native metaclass definition syntax (#9753)
Browse files Browse the repository at this point in the history
* NVDA object: metaclass syntax.

Python 2 classes can specify metaclasses via __metaclass__ attribute, whereas a metaclass keyword argument is required in Python 3. Thus use Python 3 native syntax for specifying metaclasses.

* Excel window object: metaclass syntax.

* Base object: metaclass syntax.

* Browse mode: metaclass syntax.

* Content recog: metaclass syntax.

* Acc prop server: metaclass syntax.

* Settings dialogs: metaclass syntax.

* Speech commands: metaclass syntax.

* Metaclass: remove six.with_metaclass import as Python 3 native metaclass syntax is used.
  • Loading branch information
josephsl authored and michaelDCurran committed Jun 16, 2019
1 parent b34733e commit c3d8e4a
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 19 deletions.
3 changes: 1 addition & 2 deletions source/NVDAObjects/__init__.py
Expand Up @@ -7,7 +7,6 @@

"""Module that contains the base NVDA object type"""

from six import with_metaclass
import time
import re
import weakref
Expand Down Expand Up @@ -147,7 +146,7 @@ def clearDynamicClassCache(cls):
"""
cls._dynamicClassCache.clear()

class NVDAObject(with_metaclass(DynamicNVDAObjectType, documentBase.TextContainerObject,baseObject.ScriptableObject)):
class NVDAObject(documentBase.TextContainerObject, baseObject.ScriptableObject, metaclass=DynamicNVDAObjectType):
"""NVDA's representation of a single control/widget.
Every widget, regardless of how it is exposed by an application or the operating system, is represented by a single NVDAObject instance.
This allows NVDA to work with all widgets in a uniform way.
Expand Down
3 changes: 1 addition & 2 deletions source/NVDAObjects/window/excel.py
Expand Up @@ -5,7 +5,6 @@
#See the file COPYING for more details.

import abc
from six import with_metaclass
import ctypes
from comtypes import COMError, BSTR
import comtypes.automation
Expand Down Expand Up @@ -1085,7 +1084,7 @@ class FormulaExcelCellInfoQuickNavItem(ExcelCellInfoQuickNavItem):
def label(self):
return "%s: %s"%(self.excelCellInfo.address.split('!')[-1],self.excelCellInfo.formula)

class ExcelCellInfoQuicknavIterator(with_metaclass(abc.ABCMeta,object)):
class ExcelCellInfoQuicknavIterator(object, metaclass=abc.ABCMeta):
cellInfoFlags=NVCELLINFOFLAG_ADDRESS|NVCELLINFOFLAG_COORDS

@abc.abstractproperty
Expand Down
5 changes: 2 additions & 3 deletions source/baseObject.py
Expand Up @@ -10,7 +10,6 @@
import weakref
from logHandler import log
from abc import ABCMeta, abstractproperty
from six import with_metaclass

class Getter(object):

Expand Down Expand Up @@ -104,7 +103,7 @@ def __init__(self,name,bases,dict):
# The __abstractmethods__ set is frozen, therefore we ought to override it.
self.__abstractmethods__=(self.__abstractmethods__|newAbstractProps)-oldAbstractProps

class AutoPropertyObject(with_metaclass(AutoPropertyType, object)):
class AutoPropertyObject(object, metaclass=AutoPropertyType):
"""A class that dynamically supports properties, by looking up _get_*, _set_*, and _del_* methods at runtime.
_get_x will make property x with a getter (you can get its value).
_set_x will make a property x with a setter (you can set its value).
Expand Down Expand Up @@ -188,7 +187,7 @@ def __new__(meta, name, bases, dict):
setattr(cls, gesturesDictName, gestures)
return cls

class ScriptableObject(with_metaclass(ScriptableType, AutoPropertyObject)):
class ScriptableObject(AutoPropertyObject, metaclass=ScriptableType):
"""A class that implements NVDA's scripting interface.
Input gestures are bound to scripts such that the script will be executed when the appropriate input gesture is received.
Scripts are methods named with a prefix of C{script_}; e.g. C{script_foo}.
Expand Down
3 changes: 1 addition & 2 deletions source/browseMode.py
Expand Up @@ -35,7 +35,6 @@
import gui.guiHelper
from NVDAObjects import NVDAObject
from abc import ABCMeta, abstractmethod
from six import with_metaclass

REASON_QUICKNAV = "quickNav"

Expand Down Expand Up @@ -93,7 +92,7 @@ def mergeQuickNavItemIterators(iterators,direction="next"):
continue
curValues.append((it,newVal))

class QuickNavItem(with_metaclass(ABCMeta, object)):
class QuickNavItem(object, metaclass=ABCMeta):
""" Emitted by L{BrowseModeTreeInterceptor._iterNodesByType}, this represents one of many positions in a browse mode document, based on the type of item being searched for (e.g. link, heading, table etc)."""

itemType=None #: The type of items searched for (e.g. link, heading, table etc)
Expand Down
5 changes: 2 additions & 3 deletions source/contentRecog/__init__.py
Expand Up @@ -16,10 +16,9 @@
from collections import namedtuple
import textInfos.offsets
from abc import ABCMeta, abstractmethod
from six import with_metaclass
from locationHelper import RectLTWH

class ContentRecognizer(with_metaclass(ABCMeta, object)):
class ContentRecognizer(object, metaclass=ABCMeta):
"""Implementation of a content recognizer.
"""

Expand Down Expand Up @@ -129,7 +128,7 @@ def convertHeightToScreen(self, height):
"""
return int(height / self.resizeFactor)

class RecognitionResult(with_metaclass(ABCMeta, object)):
class RecognitionResult(object, metaclass=ABCMeta):
"""Provides access to the result of recognition by a recognizer.
The result is textual, but to facilitate navigation by word, line, etc.
and to allow for retrieval of screen coordinates within the text,
Expand Down
3 changes: 1 addition & 2 deletions source/gui/accPropServer.py
Expand Up @@ -11,12 +11,11 @@
from comtypes import COMObject, GUID
from comInterfaces.Accessibility import IAccPropServer, ANNO_CONTAINER, ANNO_THIS
from abc import ABCMeta, abstractmethod, abstractproperty
from six import with_metaclass
import weakref
import winUser
import wx

class IAccPropServer_Impl(with_metaclass(ABCMeta, COMObject)):
class IAccPropServer_Impl(COMObject, metaclass=ABCMeta):
"""Base class for implementing a COM interface for a hwnd based AccPropServer\
to annotate a WX control.
The AccPropServer registers itself using the window handle of the WX control.
Expand Down
5 changes: 2 additions & 3 deletions source/gui/settingsDialogs.py
Expand Up @@ -7,7 +7,6 @@

import logging
from abc import abstractmethod
from six import with_metaclass
import os
import copy
import re
Expand Down Expand Up @@ -50,7 +49,7 @@
import keyLabels
from .dpiScalingHelper import DpiScalingHelperMixin

class SettingsDialog(with_metaclass(guiHelper.SIPABCMeta, wx.Dialog, DpiScalingHelperMixin)):
class SettingsDialog(wx.Dialog, DpiScalingHelperMixin, metaclass=guiHelper.SIPABCMeta):
"""A settings dialog.
A settings dialog consists of one or more settings controls and OK and Cancel buttons and an optional Apply button.
Action may be taken in response to the OK, Cancel or Apply buttons.
Expand Down Expand Up @@ -243,7 +242,7 @@ def _onWindowDestroy(self, evt):
# redo the layout in whatever way makes sense for their particular content.
_RWLayoutNeededEvent, EVT_RW_LAYOUT_NEEDED = wx.lib.newevent.NewCommandEvent()

class SettingsPanel(with_metaclass(guiHelper.SIPABCMeta, wx.Panel, DpiScalingHelperMixin)):
class SettingsPanel(wx.Panel, DpiScalingHelperMixin, metaclass=guiHelper.SIPABCMeta):
"""A settings panel, to be used in a multi category settings dialog.
A settings panel consists of one or more settings controls.
Action may be taken in response to the parent dialog's OK or Cancel buttons.
Expand Down
3 changes: 1 addition & 2 deletions source/speech/commands.py
Expand Up @@ -7,7 +7,6 @@
"""Commands that can be embedded in a speech sequence for changing synth parameters, playing sounds or running other callbacks."""

from abc import ABCMeta, abstractmethod
from six import with_metaclass
import config
import languageHandler
from synthDriverHandler import getSynth
Expand Down Expand Up @@ -229,7 +228,7 @@ def __repr__(self):
out += ", text=%r" % self.text
return out + ")"

class BaseCallbackCommand(with_metaclass(ABCMeta, SpeechCommand)):
class BaseCallbackCommand(SpeechCommand, metaclass=ABCMeta):
"""Base class for commands which cause a function to be called when speech reaches them.
This class should not be instantiated directly.
It is designed to be subclassed to provide specific functionality;
Expand Down

0 comments on commit c3d8e4a

Please sign in to comment.