jorisschellekens / borb

borb is a library for reading, creating and manipulating PDF files in python.
https://borbpdf.com/
Other
3.4k stars 147 forks source link

BUG: Python version 3.6 does not support parenthesized context expressions #184

Closed yathon closed 11 months ago

yathon commented 11 months ago

Describe the bug

Traceback (most recent call last): File "/.../src/main.py", line 5, in from borb.pdf import PDF File "/.../venv/lib/python3.6/site-packages/borb/pdf/init.py", line 107, in from .canvas.layout.geography.map_of_europe import MapOfEurope File "/.../venv/lib/python3.6/site-packages/borb/pdf/canvas/layout/geography/map_of_europe.py", line 16, in from borb.pdf.canvas.layout.geography.map import Map File "/.../venv/lib/python3.6/site-packages/borb/pdf/canvas/layout/geography/map.py", line 67 with (open(geojson_file, "r") as json_file_handle): ^ SyntaxError: invalid syntax

Env

OS: MacOS Sonoma 14.1.1 Python: Python 3.6.8 DevTool: Pycharm 2022.3

Sources code

#!chapter_005/src/snippet_002.py
# import typing
# from borb.pdf import Document
from borb.pdf import PDF

def main():
    # read the Document
    # doc: typing.Optional[Document] = None
    with open("../doc/test.pdf", "rb") as in_file_handle:
        doc = PDF.loads(in_file_handle)

    # check whether we have read a Document
    assert doc is not None

    # print the \Author key from the \Info dictionary
    print("Author: %s" % doc.get_document_info().get_author())

if __name__ == "__main__":
    main()

Remark

Is the example code outdated or is Python 3.6 no longer supported?

yathon commented 11 months ago

Python3.7.9: Python version 3.7 does not support parenthesized context expressions

The same error as Python3.6.8.

    # /.../venv/lib/python3.7/site-packages/borb/pdf/canvas/layout/geography/map.py
    # read map
    with (open(geojson_file, "r") as json_file_handle):
                                                       ^
jorisschellekens commented 11 months ago

In the dev repo, I added a workflow that will automatically run a single test, in multiple python versions. I saw that this failed (same error as the one you have) and fixed the error. You can expect support for version 3.7 and upwards.

image