示例#1
0
def dir_class(cls):
    """Return a list of names available on `cls`.

    Eliminates names that bind to an `ObjectMethod` without a corresponding
    class method; see `ObjectMethod`.
    """
    # Class attributes (including methods).
    for name, value in vars_class(cls).items():
        if isinstance(value, ObjectMethod):
            if value.has_classmethod:
                yield name
        elif isinstance(value, Disabled):
            pass  # Hide this; disabled.
        else:
            yield name
    # Metaclass attributes.
    for name, value in vars_class(type(cls)).items():
        if name == "mro":
            pass  # Hide this; not interesting.
        elif isinstance(value, Disabled):
            pass  # Hide this; disabled.
        else:
            yield name
示例#2
0
 def __repr__(self, *, fields=None):
     if fields is None:
         fields = sorted(name
                         for name, value in vars_class(type(self)).items()
                         if isinstance(value, ObjectField))
     else:
         fields = sorted(fields)
     values = (getattr(self, name) for name in fields)
     pairs = starmap("{0}={1!r}".format, zip(fields, values))
     desc = " ".join(pairs)
     if len(desc) == 0:
         return "<%s>" % (self.__class__.__name__, )
     else:
         return "<%s %s>" % (self.__class__.__name__, desc)
示例#3
0
def dir_class(cls):
    """Return a list of names available on `cls`.

    Eliminates names that bind to an `ObjectMethod` without a corresponding
    class method; see `ObjectMethod`.
    """
    # Class attributes (including methods).
    for name, value in vars_class(cls).items():
        if isinstance(value, ObjectMethod):
            if value.has_classmethod:
                yield name
        elif isinstance(value, Disabled):
            pass  # Hide this; disabled.
        else:
            yield name
    # Metaclass attributes.
    for name, value in vars_class(type(cls)).items():
        if name == "mro":
            pass  # Hide this; not interesting.
        elif isinstance(value, Disabled):
            pass  # Hide this; disabled.
        else:
            yield name
示例#4
0
 def __repr__(self, *, fields=None):
     if fields is None:
         fields = sorted(
             name for name, value in vars_class(type(self)).items()
             if isinstance(value, ObjectField))
     else:
         fields = sorted(fields)
     values = (getattr(self, name) for name in fields)
     pairs = starmap("{0}={1!r}".format, zip(fields, values))
     desc = " ".join(pairs)
     if len(desc) == 0:
         return "<%s>" % (self.__class__.__name__, )
     else:
         return "<%s %s>" % (self.__class__.__name__, desc)
示例#5
0
def dir_instance(inst):
    """Return a list of names available on `inst`.

    Eliminates names that bind to an `ObjectMethod` without a corresponding
    instance method; see `ObjectMethod`.
    """
    # Skip instance attributes; __slots__ is automatically defined, and
    # descriptors are used to define attributes. Instead, go straight to class
    # attributes (including methods).
    for name, value in vars_class(type(inst)).items():
        if isinstance(value, ObjectMethod):
            if value.has_instancemethod:
                yield name
        elif isinstance(value, Disabled):
            pass  # Hide this; disabled.
        elif isinstance(value, (classmethod, staticmethod)):
            pass  # Hide this; not interesting here.
        else:
            yield name
示例#6
0
def dir_instance(inst):
    """Return a list of names available on `inst`.

    Eliminates names that bind to an `ObjectMethod` without a corresponding
    instance method; see `ObjectMethod`.
    """
    # Skip instance attributes; __slots__ is automatically defined, and
    # descriptors are used to define attributes. Instead, go straight to class
    # attributes (including methods).
    for name, value in vars_class(type(inst)).items():
        if isinstance(value, ObjectMethod):
            if value.has_instancemethod:
                yield name
        elif isinstance(value, Disabled):
            pass  # Hide this; disabled.
        elif isinstance(value, (classmethod, staticmethod)):
            pass  # Hide this; not interesting here.
        else:
            yield name