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.1.0.tar.gz (1.4 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.1.0-py2.py3-none-any.whl (2.1 kB view details)

Uploaded Python 2Python 3

File details

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

File metadata

  • Download URL: enforce_with-1.1.0.tar.gz
  • Upload date:
  • Size: 1.4 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.1.0.tar.gz
Algorithm Hash digest
SHA256 5810777dc9d56aca503bb9391dcfe47a9a32274348f82747452deaf90f15ca3a
MD5 9a47e9e8711aca588c0e747d474dd485
BLAKE2b-256 8b0d899ef47a9dc8a532f2d5daf8f8e3d2ac29390d287c5c62169fa09455a1ff

See more details on using hashes here.

File details

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

File metadata

  • Download URL: enforce_with-1.1.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.1.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 80ecc5d58d4fb5e92daed42c4d3ccff9a060cd630a6a682f357bc8d59c4f4be5
MD5 63aed425c074add97ab3a4c2c955c326
BLAKE2b-256 69d5b657338fcfc35b68191edeb05055ee0678d367afa2b47c5a1b8c6f574577

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