Python builtins 模块,super() 实例源码

我们从Python开源项目中,提取了以下17个代码示例,用于说明如何使用builtins.super()

项目:packaging    作者:blockstack    | 项目源码 | 文件源码
def test_call_with_args_does_nothing(self):
        if utils.PY2:
            from __builtin__ import super as builtin_super
        else:
            from builtins import super as builtin_super
        class Base(object):
            def calc(self,value):
                return 2 * value
        class Sub1(Base):
            def calc(self,value):
                return 7 + super().calc(value)
        class Sub2(Base):
            def calc(self,value):
                return super().calc(value) - 1
        class Diamond(Sub1,Sub2):
            def calc(self,value):
                return 3 * super().calc(value)
        for cls in (Base,Sub1,Sub2,Diamond,):
            obj = cls()
            self.assertSuperEquals(builtin_super(cls), super(cls))
            self.assertSuperEquals(builtin_super(cls,obj), super(cls,obj))
项目:qtpandas    作者:draperjames    | 项目源码 | 文件源码
def __init__(self, dataFrame=None, copyDataFrame=False, filePath=None):
        """

        Args:
            dataFrame (pandas.core.frame.DataFrame, optional): initializes the model with given DataFrame.
                If none is given an empty DataFrame will be set. defaults to None.
            copyDataFrame (bool, optional): create a copy of dataFrame or use it as is. defaults to False.
                If you use it as is, you can change it from outside otherwise you have to reset the dataFrame
                after external changes.
            filePath (str, optional): stores the original path for tracking.

        """
        super(DataFrameModel, self).__init__()

        self._dataFrame = pandas.DataFrame()

        if dataFrame is not None:
            self.setDataFrame(dataFrame, copyDataFrame=copyDataFrame)

        self.dataChanged.emit()

        self._dataFrameOriginal = None
        self._search = DataSearch("nothing", "")
        self.editable = False
        self._filePath = filePath
项目:qtpandas    作者:draperjames    | 项目源码 | 文件源码
def flags(self, index):
        """Returns the item flags for the given index as ored value, e.x.: Qt.ItemIsUserCheckable | Qt.ItemIsEditable

        If a combobox for bool values should pop up ItemIsEditable have to set for bool columns too.

        Args:
            index (QtCore.QModelIndex): Index to define column and row

        Returns:
            if column dtype is not boolean Qt.ItemIsSelectable | Qt.ItemIsEnabled | Qt.ItemIsEditable
            if column dtype is boolean Qt.ItemIsSelectable | Qt.ItemIsEnabled | Qt.ItemIsUserCheckable
        """
        flags = super(DataFrameModel, self).flags(index)

        if not self.editable:
            return flags

        col = self._dataFrame.columns[index.column()]
        if self._dataFrame[col].dtype == numpy.bool:
            flags |= Qt.ItemIsUserCheckable
        else:
            # if you want to have a combobox for bool columns set this
            flags |= Qt.ItemIsEditable

        return flags
项目:qtpandas    作者:draperjames    | 项目源码 | 文件源码
def setData(self, data):
        """Add some data.

        Args:
            data (object): Object to add as data. This object has to be pickable. 
                Qt objects don't work!

        Raises:
            TypeError if data is not pickable
        """
        try:
            bytestream = pickle.dumps(data)
            super(MimeData, self).setData(self._mimeType, bytestream)
        except TypeError:
            raise TypeError(self.tr("can not pickle added data"))
        except:
            raise
项目:qtpandas    作者:draperjames    | 项目源码 | 文件源码
def __init__(self, dfindex, column, value, dtype, parentId):
        """store dataframe information in a pickable object

        Args:
            dfindex (pandas.index): index of the dragged data.
            column (str): name of column to be dragged.
            value (object): value on according position.
            dtype (pandas dtype): data type of column.
            parentId (str): hex(id(...)) of according DataFrameModel.

        """
        super(PandasCellPayload, self).__init__()
        self.dfindex = dfindex
        self.column = column
        self.value = value
        self.dtype = dtype
        self.parentId = parentId
项目:meme_get    作者:memegen    | 项目源码 | 文件源码
def __init__(self, cache_size=500, maxcache_day=1):
        super(QuickMeme, self).__init__(
            "http://www.quickmeme.com/", cache_size, maxcache_day)
        self._posts_per_page = 10
        self._origin = Origins.QUICKMEME

        if self._no_cache() or self._cache_expired():
            self._build_cache()
项目:meme_get    作者:memegen    | 项目源码 | 文件源码
def __init__(self, cache_size=500, maxcache_day=1,
                 popular_type="Daily", timeout=20):
        """ The __init__ method for MemeGenerator class

        Args:
            cache_size (int): Number of memes stored as cache
            maxcache_day (int): Number of days until the cache expires
        """
        super(MemeGenerator, self).__init__(
            "http://www.memegenerator.net", cache_size, maxcache_day)
        self._origin = Origins.MEMEGENERATOR
        self._api = "http://version1.api.memegenerator.net/"
        self._method_entry = "Instances_Select_ByPopular"

        if popular_type == "Daily":
            self._popular_days = 1
        elif popular_type == "Weekly":
            self._popular_days = 7
        elif popular_type == "Monthly":
            self._popular_days = 30
        else:
            raise ValueError(
                "Wrong popular type. Supported: Daily, Weekly, Monthly")

        self._timeout = timeout
        self._posts_per_page = 15
        if self._no_cache() or self._cache_expired():
            self._build_cache()
项目:meme_get    作者:memegen    | 项目源码 | 文件源码
def __init__(self, cache_size=500, maxcache_day=1,
                 popular_type="Daily", timeout=20):
        """ The __init__ method for MemeGenerator class

        Args:
            cache_size (int): Number of memes stored as cache
            maxcache_day (int): Number of days until the cache expires
        """
        super(RedditMemes, self).__init__(
            "https://www.reddit.com/r/memes/", cache_size, maxcache_day)
        self._origin = Origins.REDDITMEMES

        # Client ID and user agent requested by Reddit API
        config = configparser.ConfigParser()

        cdir = os.path.dirname(os.path.realpath(__file__))
        config.read(os.path.join(cdir, 'config.ini'))

        self._client_id = config['Reddit']['ClientID']
        self._client_secret = config['Reddit']['ClientSecret']
        if self._client_secret == '':
            self._client_secret = None
        self._user_agent = config['Reddit']['UserAgent'].format(sys.platform)

        # Generate a Reddit instance
        self._reddit = praw.Reddit(client_id=self._client_id,
                                   client_secret=self._client_secret,
                                   user_agent=self. _user_agent)

        if self._no_cache() or self._cache_expired():
            self._build_cache()
项目:fypp    作者:aradi    | 项目源码 | 文件源码
def __init__(self, msg, fname=None, span=None, cause=None):
        super(FyppError, self).__init__()
        self.msg = msg
        self.fname = fname
        self.span = span
        self.cause = cause
项目:napalm-yang    作者:napalm-automation    | 项目源码 | 文件源码
def _translate_leaf_default(self, attribute, model, other, mapping, translation):
        force = False

        if model == other and not self.replace:
            return

        if not model._changed() and other is not None and not self.replace:
            force = True
            mapping["value"] = mapping["negate"]
        if not model._changed() and other is not None and self.replace:
            return

        mapping["element"] = "command"
        super()._translate_leaf_default(attribute, model, other, mapping, translation, force)
项目:napalm-yang    作者:napalm-automation    | 项目源码 | 文件源码
def _init_element_default(self, attribute, model, other, mapping, translation):
        extra_vars = {}
        if other is not None:
            if not napalm_yang.utils.diff(model, other) and not self.replace:
                # If objects are equal we return None as that aborts translating
                # the rest of the object
                return False, {}

        if not model._changed() and other is not None and not self.replace:
            mapping["key_value"] = mapping["negate"]
        if not model._changed() and other is not None and self.replace:
            return translation, {}

        mapping["key_element"] = "command"
        mapping["container"] = model._yang_name

        for i in ('prefix', 'negate_prefix'):
            if i in mapping:
                extra_vars[i] = mapping.get(i)

        t = super()._init_element_default(attribute, model, other, mapping, translation)

        end = mapping.get("end", "")
        if end and t is not None:
            e = etree.SubElement(translation, "command")
            e.text = end

        return t, extra_vars
项目:napalm-yang    作者:napalm-automation    | 项目源码 | 文件源码
def _parse_leaf_default(self, attribute, mapping, data):
        attribute = mapping.get("attribute", None)
        path = mapping.get("path", None)
        if attribute and path:
            attribute = "@{}".format(attribute)
            mapping["path"] = "{}.{}".format(mapping["path"], attribute)
        elif "present" not in mapping and path:
            attribute = "#text"
            mapping["path"] = "{}.{}".format(mapping["path"], "#text")
        return super()._parse_leaf_default(attribute, mapping, data)
项目:napalm-yang    作者:napalm-automation    | 项目源码 | 文件源码
def _parse_leaf_default(self, attribute, mapping, data):
        extra_path = "#standalone" if "present" in mapping else "#text"
        if "path" in mapping:
            mapping["path"] = "{}.{}".format(mapping["path"], extra_path)
        else:
            mapping["path"] = extra_path
        return super()._parse_leaf_default(attribute, mapping, data)
项目:qtpandas    作者:draperjames    | 项目源码 | 文件源码
def __init__(self, mimeType=PandasCellMimeType):
        """create a new MimeData object.   

        Args:
            mimeType (str): the mime type.
        """
        super(MimeData, self).__init__()
        self._mimeType = mimeType
项目:qtpandas    作者:draperjames    | 项目源码 | 文件源码
def data(self):
        """return stored data

        Returns:
            unpickled data
        """
        try:
            bytestream = super(MimeData, self).data(self._mimeType).data()
            return pickle.loads(bytestream)
        except:
            raise
项目:tensorflow-tbcnn    作者:Aetf    | 项目源码 | 文件源码
def find_class(self, module, name):
            if module == '__main__' and name == 'Node':
                return Node
            else:
                return super().find_class(module, name)
项目:tensorflow-tbcnn    作者:Aetf    | 项目源码 | 文件源码
def find_class(self, module, name):
            if module == '__main__' and name == 'Node':
                return Node
            else:
                return super().find_class(module, name)