Skip to main content

Extend the ``inspect`` standard library.

Project description

https://travis-ci.org/MacHu-GWU/inspect_mate-project.svg?branch=master

Welcome to inspect_mate Documentation

inspect_mate can easily separate:

  1. regular attribute.
  2. property attribute.
  3. regular method.
  4. static method.
  5. class method.
  6. all attributes, include regular attribute and property attribute.
  7. all methods, include regular method, static method and class method.

Example

import:

from inspect_mate import (
    is_attribute,
    is_property_method,
    is_regular_method,
    is_static_method,
    is_class_method,
    get_attributes,
    get_property_methods,
    get_regular_methods,
    get_static_methods,
    get_class_methods,
    get_all_attributes,
    get_all_methods,
)

define a class:

class Base(object):
    attribute = "attribute"

    def __init__(self):
        self.initiated_attribute = "initiated_attribute"

    @property
    def property_method(self):
        return "property_method"

    def regular_method(self):
        return "regular_method"

    @staticmethod
    def static_method():
        return "static_method"

    @classmethod
    def class_method(cls):
        return "class_method"


class Klass(Base):
    pass


instance = Klass()

usage:

# tester_function(klass_or_instance, "attribute_name")
>>> is_attribute(Klass, "attribute")
True
>>> is_property_method(Klass, "property_attribute")
True
>>> is_regular_method(Klass, "regular_method")
True
>>> is_static_method(Klass, "static_method")
True
>>> is_class_method(Klass, "class_method")
True

>>> is_attribute(instance, "attribute")
True
>>> is_attribute(instance, "initiated_attribute")
True
>>> is_property_method(instance, "property_attribute")
True
>>> is_regular_method(instance, "regular_method")
True
>>> is_static_method(instance, "static_method")
True
>>> is_class_method(instance, "class_method")
True

# getter_function(klass_or_instance), yield (attr, value)
>>> get_attributes(Klass)
[("attribute", "attribute")]

>>> get_property_methods(Klass)
[("property_attribute", "property_attribute")]

>>> get_regular_methods(Klass)
[("regular_method", Klass.regular_method)]

>>> get_static_methods(Klass)
[("static_method", "Klass.static_method")]

>>> get_class_methods(Klass)
[("class_method", "Klass.class_method")]

>>> get_all_attributes(Klass)
[("attribute", "attribute"), ("property_attribute", "property_attribute")]

>>> get_all_methods(Klass)
[("regular_method", Klass.regular_method), ("static_method", "Klass.static_method"), ("class_method", "Klass.class_method")]

Install

inspect_mate is released on PyPI, so all you need is:

$ pip install inspect_mate

To upgrade to latest version:

$ pip install --upgrade inspect_mate

Project details


Release history Release notifications

This version
History Node

0.0.1

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
inspect_mate-0.0.1.tar.gz (9.9 kB) Copy SHA256 hash SHA256 Source None Jul 14, 2017

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging CloudAMQP CloudAMQP RabbitMQ AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page