Skip to main content

create perfect singletons meta

Reason this release was yanked:

while not used anywhere use new vertion!

Project description

singleton_meta

Features

  1. perfect singleton (maybe thread safe!)
  2. collect all instances

License

See the LICENSE file for license rights and limitations (MIT).

Release history

See the HISTORY.md file for release history.

Installation

pip install singleton-meta

Import

from singleton_meta import *

GUIDE

See tests and source for other examples.

1. Use simple nesting (common)

from singleton_meta import *

class MySingleton(Singleton):
    pass

class MySingleton2(Singleton):
    pass

2. access to created instances

from singleton_meta import *

    class Victim1(Singleton):
        attr = 1

    class Victim2(Singleton):
        attr = 2

    assert Singleton._SINGLETONS == []
    Victim1()
    assert Singleton._SINGLETONS == [Victim1(), ]
    Victim2()
    assert Singleton._SINGLETONS == [Victim1(), Victim2(), ]

3. Use meta

from singleton_meta import *

class MySingleton(metaclass=SingletonMeta):
    pass

4. NOTICE: all your Singletons must be only last classes!

don't use nesting from any Your Singletons!

from singleton_meta import *

class MySingleton(Singleton):   # OK
    pass

class MySingleton2(MySingleton):    # WRONG
    pass

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

singleton_meta-0.0.2.tar.gz (3.3 kB view hashes)

Uploaded Source

Built Distribution

singleton_meta-0.0.2-py3-none-any.whl (3.6 kB view hashes)

Uploaded Python 3

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