{"id":21451853,"url":"https://github.com/reity/barriers","last_synced_at":"2026-03-12T17:33:21.402Z","repository":{"id":122905637,"uuid":"525585123","full_name":"reity/barriers","owner":"reity","description":"Python decorator for including/removing type checks, value/bounds checks, and other code blocks within the compiled bytecode of functions and methods.","archived":false,"fork":false,"pushed_at":"2025-09-27T01:26:55.000Z","size":77,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-11-27T17:25:13.727Z","etag":null,"topics":["bounds-checking","python","python-decorators","python-library","python-syntax-converter","python-testing","type-checking"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/barriers","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/reity.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-08-17T00:27:28.000Z","updated_at":"2025-09-27T01:23:05.000Z","dependencies_parsed_at":null,"dependency_job_id":"b6968e1e-a35d-49a4-88fa-43c25bb942a5","html_url":"https://github.com/reity/barriers","commit_stats":{"total_commits":21,"total_committers":3,"mean_commits":7.0,"dds":0.09523809523809523,"last_synced_commit":"c9f78df814e85219039ed89f5820705650a26242"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/reity/barriers","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reity%2Fbarriers","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reity%2Fbarriers/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reity%2Fbarriers/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reity%2Fbarriers/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/reity","download_url":"https://codeload.github.com/reity/barriers/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reity%2Fbarriers/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30435223,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-12T14:34:45.044Z","status":"ssl_error","status_checked_at":"2026-03-12T14:09:33.793Z","response_time":114,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bounds-checking","python","python-decorators","python-library","python-syntax-converter","python-testing","type-checking"],"created_at":"2024-11-23T04:26:23.937Z","updated_at":"2026-03-12T17:33:21.382Z","avatar_url":"https://github.com/reity.png","language":"Python","readme":"========\nbarriers\n========\n\nPython decorators for including/excluding type checks, value/bounds checks, and other code blocks within the compiled bytecode of functions and methods.\n\n|pypi| |readthedocs| |actions| |coveralls|\n\n.. |pypi| image:: https://badge.fury.io/py/barriers.svg#\n   :target: https://badge.fury.io/py/barriers\n   :alt: PyPI version and link.\n\n.. |readthedocs| image:: https://readthedocs.org/projects/barriers/badge/?version=latest\n   :target: https://barriers.readthedocs.io/en/latest/?badge=latest\n   :alt: Read the Docs documentation status.\n\n.. |actions| image:: https://github.com/reity/barriers/workflows/lint-test-cover-docs/badge.svg#\n   :target: https://github.com/reity/barriers/actions/workflows/lint-test-cover-docs.yml\n   :alt: GitHub Actions status.\n\n.. |coveralls| image:: https://coveralls.io/repos/github/reity/barriers/badge.svg?branch=main\n   :target: https://coveralls.io/github/reity/barriers?branch=main\n   :alt: Coveralls test coverage summary.\n\nInstallation and Usage\n----------------------\nThis library is available as a `package on PyPI \u003chttps://pypi.org/project/barriers\u003e`__:\n\n.. code-block:: bash\n\n    python -m pip install barriers\n\nThe library can be imported in the usual manner:\n\n.. code-block:: python\n\n    import barriers\n    from barriers import barriers\n\nExamples\n^^^^^^^^\n\n.. |barriers| replace:: ``barriers``\n.. _barriers: https://barriers.readthedocs.io/en/2.0.0/_source/barriers.html#barriers.barriers.barriers\n\n.. |globals| replace:: ``globals``\n.. _globals: https://docs.python.org/3/library/functions.html#globals\n\nConsider the function below (defined within a file ``f.py``). The body of this function contains a code block that raises an exception if either of the two inputs is a negative integer:\n\n.. code-block:: python\n\n    def f(x: int, y: int) -\u003e int:\n\n        if x \u003c 0 or y \u003c 0:\n            raise ValueError('inputs must be nonnegative')\n\n        return x + y\n\nWe can import the module above and invoke the function to observe its behavior:\n\n.. code-block:: python\n\n    \u003e\u003e\u003e from f import f\n    \u003e\u003e\u003e f(1, 2)\n    3\n    \u003e\u003e\u003e f(-1, -2)\n    Traceback (most recent call last):\n      ...\n    ValueError: inputs must be nonnegative\n\nAn instance of the |barriers|_ class should normally be introduced near the top of a Python module using a pair of statements such as those below:\n\n.. code-block:: python\n\n    \u003e\u003e\u003e from barriers import barriers\n    \u003e\u003e\u003e example = barriers(False) @ globals() # Remove marked code blocks (i.e., \"disable barriers\").\n\nThe |barriers|_ instance ``example`` defined above is a decorator that transforms any decorated function by removing any designated code blocks in the body of that function.\n\n* The ``False`` argument in the expression ``barriers(False)`` above should be interpreted to mean that **this barrier is disabled** (*i.e.*, that the marked code blocks in the bodies of functions decorated by this decorator **should be removed**). The default value for this optional argument is ``True``; this should be interpreted to mean that **this barrier is enabled** (and, thus, that marked code blocks **should not be removed** from decorated functions).\n\n* The notation ``@ globals()`` ensures that the namespace returned by |globals|_ is used when compiling the abstract syntax trees of transformed functions.\n\nConsider the modified version of ``f.py`` below. A statement can be designated for automatic removal by placing a marker -- in this case, the ``example`` variable -- on the line directly above that statement. Note that in the body of the function ``f`` defined below, the ``if`` block is immediately preceded by a line that contains the variable ``example``:\n\n.. code-block:: python\n\n    from barriers import barriers\n    example = barriers(False) @ globals()\n\n    @example\n    def f(x: int, y: int) -\u003e int:\n\n        example\n        if x \u003c 0 or y \u003c 0:\n            raise ValueError('inputs must be nonnegative')\n\n        return x + y\n\nThe decorator ``@example`` automatically removes the ``if`` block in the function above. As a result, the function does not raise an exception when it is applied to negative inputs:\n\n.. code-block:: python\n\n    \u003e\u003e\u003e from f import f\n    \u003e\u003e\u003e f(1, 2)\n    3\n    \u003e\u003e\u003e f(-1, -2)\n    -3\n\nIt is also possible to define and use individually named markers (which are created as attributes of the |barriers|_ instance):\n\n.. code-block:: python\n\n    \u003e\u003e\u003e from barriers import barriers\n    \u003e\u003e\u003e checks = barriers(types=True, bounds=False) @ globals()\n\nGiven the above definitions, it is possible to introduce named markers such as those in the variant of ``f.py`` presented below. When a marker definition has been assigned ``True``, the statements immediately below that named marker **are not removed** (*i.e.*, the marked barrier statements are enabled). When a marker definition has been assigned ``False``, the corresponding marked statements **are removed**:\n\n.. code-block:: python\n\n    from barriers import barriers\n    checks = barriers(types=True, bounds=False) @ globals()\n\n    @checks\n    def f(x: int, y: int) -\u003e int:\n    \n        checks.types\n        if not isinstance(x, int) and not isinstance(y, int):\n            raise TypeError('inputs must be integers')\n    \n        checks.bounds\n        if x \u003c 0 or y \u003c 0:\n            raise ValueError('inputs must be nonnegative')\n    \n        return x + y\n\nThe described behavior can be observed when evaluating the function:\n\n.. code-block:: python\n\n    \u003e\u003e\u003e from f import f\n    \u003e\u003e\u003e f('a', 'b')\n    Traceback (most recent call last):\n      ...\n    TypeError: inputs must be integers\n    \u003e\u003e\u003e f(-1, -2)\n    -3\n\nMany additional details and examples are presented in the `documentation \u003chttps://barriers.readthedocs.io/en/2.0.0\u003e`__.\n\nDevelopment\n-----------\nAll installation and development dependencies are fully specified in ``pyproject.toml``. The ``project.optional-dependencies`` object is used to `specify optional requirements \u003chttps://peps.python.org/pep-0621\u003e`__ for various development tasks. This makes it possible to specify additional options (such as ``docs``, ``lint``, and so on) when performing installation using `pip \u003chttps://pypi.org/project/pip\u003e`__:\n\n.. code-block:: bash\n\n    python -m pip install \".[docs,lint]\"\n\nDocumentation\n^^^^^^^^^^^^^\nThe documentation can be generated automatically from the source files using `Sphinx \u003chttps://www.sphinx-doc.org\u003e`__:\n\n.. code-block:: bash\n\n    python -m pip install \".[docs]\"\n    cd docs\n    sphinx-apidoc -f -E --templatedir=_templates -o _source .. \u0026\u0026 make html\n\nTesting and Conventions\n^^^^^^^^^^^^^^^^^^^^^^^\nAll unit tests are executed and their coverage is measured when using `pytest \u003chttps://docs.pytest.org\u003e`__ (see the ``pyproject.toml`` file for configuration details):\n\n.. code-block:: bash\n\n    python -m pip install \".[test]\"\n    python -m pytest\n\nAlternatively, all unit tests are included in the module itself and can be executed using `doctest \u003chttps://docs.python.org/3/library/doctest.html\u003e`__:\n\n.. code-block:: bash\n\n    python src/barriers/barriers.py -v\n\nStyle conventions are enforced using `Pylint \u003chttps://pylint.readthedocs.io\u003e`__:\n\n.. code-block:: bash\n\n    python -m pip install \".[lint]\"\n    python -m pylint src/barriers\n\nContributions\n^^^^^^^^^^^^^\nIn order to contribute to the source code, open an issue or submit a pull request on the `GitHub page \u003chttps://github.com/reity/barriers\u003e`__ for this library.\n\nVersioning\n^^^^^^^^^^\nThe version number format for this library and the changes to the library associated with version number increments conform with `Semantic Versioning 2.0.0 \u003chttps://semver.org/#semantic-versioning-200\u003e`__.\n\nPublishing\n^^^^^^^^^^\nThis library can be published as a `package on PyPI \u003chttps://pypi.org/project/barriers\u003e`__ via the GitHub Actions workflow found in ``.github/workflows/build-publish-sign-release.yml`` that follows the `recommendations found in the Python Packaging User Guide \u003chttps://packaging.python.org/en/latest/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/\u003e`__.\n\nEnsure that the correct version number appears in ``pyproject.toml``, and that any links in this README document to the Read the Docs documentation of this package (or its dependencies) have appropriate version numbers. Also ensure that the Read the Docs project for this library has an `automation rule \u003chttps://docs.readthedocs.io/en/stable/automation-rules.html\u003e`__ that activates and sets as the default all tagged versions.\n\nTo publish the package, create and push a tag for the version being published (replacing ``?.?.?`` with the version number):\n\n.. code-block:: bash\n\n    git tag ?.?.?\n    git push origin ?.?.?\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Freity%2Fbarriers","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Freity%2Fbarriers","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Freity%2Fbarriers/lists"}