Skip to main content

Enforce the usage of with keyword

Project description

enforce-with

This library makes it possible to enforce the usage of with keyword

Installation

pip install enforce-with

Usage

@enforce_with.enforce_with

Decorate your class with this decorator and it will no longer be possible to access the members of its instances unless you access them inside a with block. Example:

@enforce_with.enforce_with
class MyClass:
    def __init__(self):
        self.var = 10

    def func(self):
        pass

    def __enter__(self):
        print("entering")
        return self

    def __exit__(self, exc_type, exc_value, traceback):
        print("exiting")

with MyClass() as obj:
    obj.var # Ok
    obj.func() # Ok

MyClass().var # Error
MyClass().func() # Error

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

enforce_with-1.0.0.tar.gz (1.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

enforce_with-1.0.0-py2.py3-none-any.whl (2.1 kB view details)

Uploaded Python 2Python 3

File details

Details for the file enforce_with-1.0.0.tar.gz.

File metadata

  • Download URL: enforce_with-1.0.0.tar.gz
  • Upload date:
  • Size: 1.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.0

File hashes

Hashes for enforce_with-1.0.0.tar.gz
Algorithm Hash digest
SHA256 ce7ef4aefdf3b81e370c6158bc45c3637d92764e371e0b7b656471b43eb99f04
MD5 0f03e454842a0318641bbbdc4dd76155
BLAKE2b-256 94b0ded5e1fbf706a3b2520be2a0d37fb3e515643a3cf1b3eac8fad36d3d94ee

See more details on using hashes here.

File details

Details for the file enforce_with-1.0.0-py2.py3-none-any.whl.

File metadata

  • Download URL: enforce_with-1.0.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 2.1 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.0

File hashes

Hashes for enforce_with-1.0.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 363402f34757c5bcf0ef580459f7e02508648734aa3c1c4d4d32186316df93b9
MD5 b08cf4617077591d9f94ca2ae9b12c47
BLAKE2b-256 7dbd7fb4956702ee2b5bfb0850f904e624550b6ab68aa649d7c4871a6e6ed860

See more details on using hashes here.

Supported by

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