python库中的空函数

2024-05-23 21:02:32 发布

您现在位置:Python中文网/ 问答频道 /正文

在我使用的许多库中,有些函数基本上什么都不做,并且有docstring。那么它们是如何使用的呢?我想弄明白一些事情,但当我查找源代码时,里面什么都没有

它是如何工作的?,这是元类方法吗?我想知道明白这一点,而不是解决运行时问题

这个例子class / functions,里面没有太多

# fafreplay.py
# encoding: utf-8
# module fafreplay
# from /home/greg/anaconda3/lib/python3.7/site-packages/fafreplay.cpython-35m-x86_64-linux-gnu.so
# by generator 1.147
""" Supreme Commander Forged Alliance replay parser """

# imports
import commands as commands # <module 'commands'>

# functions

def body_offset(replay, bytes=None, bytearray=None): # real signature unknown; restored from __doc__
    """
    body_offset(replay: Union[bytes, bytearray]) -> int

    Find the offset at which the body starts by parsing the header.
    Raises `ReplayReadError` if the header data is malformed.
    """
    return 0

def body_ticks(body, bytes=None, bytearray=None): # real signature unknown; restored from __doc__
    """
    body_ticks(body: Union[bytes, bytearray]) -> int

    Count the number of ticks in the replay body without checking for desyncs.
    Raises `ReplayReadError` if the body data is malformed.
    """
    return 0

# classes

class Parser(object):
    # no doc
    def parse(self, *args, **kwargs): # real signature unknown
        """ Parse a replay """
        pass

    def parse_body(self, *args, **kwargs): # real signature unknown
        """
        Parse a replay body. This implies that the header has already been parsed in order for
        `data` to be at the correct offset.
        """
        pass

    def parse_header(self, *args, **kwargs): # real signature unknown
        """ Parse a replay header """
        pass

    def __init__(self, *args, **kwargs): # real signature unknown
        pass

    @staticmethod # known case of __new__
    def __new__(*args, **kwargs): # real signature unknown
        """ Create and return a new object.  See help(type) for accurate signature. """
        pass


class ReplayReadError(Exception):
    # no doc
    def __init__(self, *args, **kwargs): # real signature unknown
        pass

    __weakref__ = property(lambda self: object(), lambda self, v: None, lambda self: None)  # default
    """list of weak references to the object (if defined)"""



class ReplayDesyncedError(ReplayReadError):
    # no doc
    def __init__(self, *args, **kwargs): # real signature unknown
        pass


# variables with complex values

__all__ = [
    '__doc__',
    'Parser',
    'ReplayReadError',
    'ReplayDesyncedError',
    'body_offset',
    'body_ticks',
    'commands',
]

__loader__ = None # (!) real value is '<_frozen_importlib_external.ExtensionFileLoader object at 0x7f643cf3ed10>'

__spec__ = None # (!) real value is "ModuleSpec(name='fafreplay', loader=<_frozen_importlib_external.ExtensionFileLoader object at 0x7f643cf3ed10>, origin='/home/greg/anaconda3/lib/python3.7/site-packages/fafreplay.cpython-37m-x86_64-linux-gnu.so')"

库链接:https://libraries.io/pypi/faf-replay-parser/0.4.0pip install faf-replay-parser==0.4.0

我正在代码中使用此库:

# my_file.py
from fafreplay import body_offset, body_ticks
ticks = body_ticks(data)

这会导致错误:

Traceback (most recent call last):
  File "/home/greg/_Local/git/faf-replay-analyzer/src/replay_reader.py", line 39, in <module>
    ticks = body_ticks(data)
fafreplay.ReplayReadError: Invalid command!

Tags: theselfnonereplaydefargsbodypass