Softpedia
 


LINUX CATEGORIES:



GLOBAL PAGES >>
NEWS ARCHIVE >>
SOFTPEDIA REVIEWS >>
MEET THE EDITORS >>
WEEK'S BEST
  • Linux Kernel 3.9.3 / 3....
  • LibreOffice 3.6.6 / 4.0.3
  • MPlayer 1.1.1
  • systemd 204
  • Arch Linux 2013.05.01
  • Blender 2.67a
  • KDE Software Compilatio...
  • CrunchBang Linux Stable...
  • Elementary OS 0.1 / 0.2...
  • SystemRescueCd 3.6.0
  • Home > Linux > Programming > Libraries

    virtualmethod 0.0.1

    Download button

    No screenshots available
    Downloads: 122  View global page NEW!  Tell us about an update
    User Rating:
    Rated by:
    NOT RATED
    0 user(s)
    Developer:

    License / Price:

    Last Updated:

    Category:
    Brad Greenlee | More programs
    The Apache License 2.0 / FREE
    July 15th, 2011, 21:59 GMT
    ROOT / Programming / Libraries

     Read user reviews (0)  Refer to a friend  Subscribe

    virtualmethod description

    Decorator to prevent base class methods from being called directly

    virtualmethod is a decorator to prevent base class methods from being called directly.

    Usage

    from virtualmethod import virtualmethod

    class Base(object):
     @virtualmethod
     def my_virtual_method(self):
     print "This is a virtual method. Call me from a subclass!"

    class A(Base):
     pass

    class B(Base):
     def my_virtual_method(self):
     print "I went ahead and implemented my own version."

    base = Base()
    a = A()
    b = B()

    a.my_virtual_method()
    -> This is a virtual method. Call me from a subclass!

    b.my_virtual_method()
    -> I went ahead and implemented my own version.

    base.my_virtual_method()
    -> Traceback (most recent call last):
     File "", line 1, in
     File "virtualmethod/core.py", line 11, in __call__
     raise TypeError("Virtual method %s must be called from a subclass." % self.__name__)
    TypeError: Virtual method my_virtual_method must be called from a subclass.


    Note(s)

    @virtualmethod works with @classmethod and @staticmethod, but must be declared first, i.e.:

    @virtualmethod
    @classmethod
    def my_virtual_class_method(cls):
     ...



    Product's homepage

    Requirements:

    · Python

      


    TAGS:

    class methods | Python library | virtual | class | methods

    Go to top

    WindowsGamesDriversMacLinuxScriptsMobileHandheldNews

    SUBMIT PROGRAM   |   ADVERTISE   |   GET HELP   |   SEND US FEEDBACK   |   RSS FEEDS   |   UPDATE YOUR SOFTWARE   |   ROMANIAN FORUM