Skip to content

Apparent incompatibility with bytes objects in Python 3 #18

@bkovitz

Description

@bkovitz

I just tried installing dparser 1.31 under Python 3.7.6 and Swig 3.0.8 and ran into this error when running make test in the python directory:

    running test tests/test2.py
Traceback (most recent call last):
  File "tests/test2.py", line 53, in <module>
    if Parser().parse('1  +2* (3+ 4+5)', ambiguity_fn=ambiguity_func,
  File "/home/bkovitz/github/dparser/python/build/lib.linux-x86_64-3.7/dparser.py", line 290, in __init__
    self.tables.load_tables(grammar_str, self.filename, make_grammar_file)
  File "/home/bkovitz/github/dparser/python/build/lib.linux-x86_64-3.7/dparser.py", line 190, in load_tables
    dparser_swigc.make_tables(grammar_str, filename.encode())
TypeError: in method 'make_tables', argument 1 of type 'char *'

The problem appears to be that dparser.py is passing a bytes object but the Swig wrapper expects an ordinary string. Perhaps this is an incompatibility with Python 3 (which made bytes objects distinct from strings)?

I got the tests to pass by editing dparser.py to call .decode('ascii') on various arguments passed through Swig, like this (line 190):

        dparser_swigc.make_tables(grammar_str.decode('ascii'), filename.encode().decode('ascii'))

in a few places. I can submit a pull request with these changes if you like, but I don't know enough to say if this is the correct solution or not (especially for Python 2).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions