Skip to main content

Py3k-alike style super() for Py2.x

Project description

Intro

newsuper provides you Python3k-alike super() for Python2.x

Since 0.3, newsuper is 110% behaving like Python3k’s super()

Why

you must hate to write code like this:

super(Foo, self).__init__()

and you might have written (WRONG) code like this:

super(self.__class__, self).__init__()

Python3k’s super() saves your ass a bit:

super().__init__()

Example

You can make your topest-level class subclassing newsuper.Object

from newsuper import Object

class Foo(Object):
    def __init__(self):
        self.foo = 1

    @classmethod
    def do_something_with_class(cls):
        return [cls, 'Foo']

    @staticmethod
    def do_something_static():
        return ['Foo']

class Bar(Foo):
    def __init__(self):
        super().__init__()
        self.bar = 1

    @classmethod
    def do_something_static(cls):
        return super().do_something_static() + ['Bar']

class Baz(Bar):
    def __init__(self):
        super().__init__()
        self.baz = 1

    @classmethod
    def do_something_with_class(cls):
        # Compatible with old super(Baz, cls)
        return super(Baz, cls).do_something_with_class() + ['Baz']

    @staticmethod
    def do_something_static():
        # Yes, you can even super a staticmethod!
        return super().do_something_static() + ['Baz']

if __name__ == '__main__':
    assert Baz().foo == Baz().bar == Baz().baz == 1
    assert Baz.do_something_with_class() == [Baz, 'Foo', 'Baz']
    assert Baz.do_something_static() == ['Foo', 'Bar', 'Baz']

property is supported too.

Install

Let’s try it now

Use pip:

pip install newsuper

or easy_install:

easy_install newsuper

also, there is windows installer.

Project details


Download files

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

Source Distribution

newsuper-0.3a.zip (5.3 kB view details)

Uploaded Source

Built Distribution

newsuper-0.3a.win32.exe (201.6 kB view details)

Uploaded Source

File details

Details for the file newsuper-0.3a.zip.

File metadata

  • Download URL: newsuper-0.3a.zip
  • Upload date:
  • Size: 5.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for newsuper-0.3a.zip
Algorithm Hash digest
SHA256 de9a7a7a2a05ab84418fcf313008c4cb3dd5217a7a645caeea6d07d4138e687b
MD5 686e40253c7c65f8c9c87965b8f40d23
BLAKE2b-256 da57ec195b525284761ef5b4840950bdb016fa0d8825c00dd0e7e88c541f72da

See more details on using hashes here.

File details

Details for the file newsuper-0.3a.win32.exe.

File metadata

  • Download URL: newsuper-0.3a.win32.exe
  • Upload date:
  • Size: 201.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for newsuper-0.3a.win32.exe
Algorithm Hash digest
SHA256 de0af91f47c9d76057de91d6c217b72fcd0dbff6ef532ed0ac76191eccf5dc73
MD5 3961265c80e5d6fb56b30378ba4c2fb2
BLAKE2b-256 904bd6edd5cafb71cf70f7215e3f88a159de397a899f1414e8c2cabffcee5bfe

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page