Skip to main content

Installation

make sure you are using python 3.9

pip install -U goto-label

NOTE: support for python >=3.10 is very unstable, please run the test before using.

Usage

a simple example:

from goto import with_goto
from goto import goto, label  # optional, for linter purpose

@with_goto
def x():
    goto .end
    print("this will not print")
    label .end
    print("this will print")
  • use label .NAME to define a label.
  • use goto .NAME to goto into a label.

Limitation

@with_goto
def x():
    try:
        pass
    finally:
        label .a

here we define the label "a" once. but if you run the code:

SyntaxError: ambiguous label name: 'a'. at line 10

it's not a bug, but why is it?

let's try to disassemble the code without modifying it:

  7           0 SETUP_FINALLY           10 (to 12)

  8           2 POP_BLOCK

 10           4 LOAD_GLOBAL              0 (label)
              6 LOAD_ATTR                1 (a)
              8 POP_TOP
             10 JUMP_FORWARD             8 (to 20)
        >>   12 LOAD_GLOBAL              0 (label)
             14 LOAD_ATTR                1 (a)
             16 POP_TOP
             18 RERAISE
        >>   20 LOAD_CONST               0 (None)
             22 RETURN_VALUE

because the finally block is copy pasted by python.
look at the instructions, there are two definitions of label "a".

Thanks

this project was inspired by snoack/python-goto .
since the project seems to have been discontinued, I created this.

Metadata

Release files for goto-label 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for goto-label 0.1.2
File Size Uploaded Provenance Actions
goto-label-0.1.2.tar.gz 6.3 kB Without provenance Details for goto-label-0.1.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for goto-label 0.1.2
File Interpreter ABI Platform Actions
goto_label-0.1.2-py3-none-any.whl Python 3 none any Details for goto_label-0.1.2-py3-none-any.whl

Total release size: 12.8 kB

Release files / goto-label-0.1.2.tar.gz

Download URL goto-label-0.1.2.tar.gz
Size 6.3 kB
Tags Source
SHA-256 checksum
How to use checksums
4b6a4a692a05b76ebc45a97368da3de03b51e267694707593f07d46c8e9b90dd
BLAKE2b-256 checksum
How to use checksums
f03f0b77b3763e1158db2a24226bca0694849c125284beae806be80158420dce
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

Release files / goto_label-0.1.2-py3-none-any.whl

Download URL goto_label-0.1.2-py3-none-any.whl
Size 6.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
28b9f89d309930d741fedc7fd5694518b68947121643c0bae58b00ef58b93c8f
BLAKE2b-256 checksum
How to use checksums
b539e5de82a320b19ad9abc863d8b7c89c4ee1cc3a088376822a5c3535cd0c01
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

Security for goto-label 0.1.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page