cucumber / gherkin

A parser and compiler for the Gherkin language.
MIT License
160 stars 48 forks source link

Update Python example to latest API #203

Closed kieran-ryan closed 5 months ago

kieran-ryan commented 6 months ago

🤔 What's changed?

Updated the Python example for compatibility with the latest API of the package.

⚡️ What's your motivation?

Fix Python example so is working and runnable.

See the compiler.py module for API reference.

Current example, using previous API:

from gherkin.parser import Parser
from gherkin.pickles.compiler import compile

parser = Parser()
gherkin_document = parser.parse("Feature: ...")
pickles = compile(gherkin_document)
Traceback (most recent call last):
  File "/Users/<user>/projects/python/repository/script.py", line 2, in <module>
    from gherkin.pickles.compiler import compile
ImportError: cannot import name 'compile' from 'gherkin.pickles.compiler' (/Users/<user>/projects/python/repository/venv/lib/python3.10/site-packages/gherkin/pickles/compiler.py)

Updated example runs without issue:

from gherkin.parser import Parser
from gherkin.pickles.compiler import Compiler

parser = Parser()
gherkin_document = parser.parse("Feature: ...")
pickles = Compiler().compile(gherkin_document)

🏷️ What kind of change is this?

♻️ Anything particular you want feedback on?

NA.

📋 Checklist: