comtypes icon indicating copy to clipboard operation
comtypes copied to clipboard

SyntaxError on parsing some of the applications docstrings

Open pshv opened this issue 1 year ago • 4 comments

com.CreateObject('Visio.Application') returns SyntaxError starting from 1.1.13:

File "xxxxxxxxx\.tox\py39\lib\site-packages\comtypes\gen\_00021A98_0000_0000_C000_000000000046_0_4_16.py", line 20214 """A running instance of Visio. ProgId: "Visio.Application"""" SyntaxError: EOL while scanning string literal

Very likely this issue might also reproduce for some other applications that uses the same formatting of docstrings. Also, for a comparison, here's how the same line looks on 1.1.11:

'A running instance of Visio. ProgId: "Visio.Application"'

pshv avatar Aug 08 '22 09:08 pshv

Perhaps the causes are these.

https://github.com/enthought/comtypes/blob/096bfde508bc32466e3fac18790fc93bdaa3cc37/comtypes/tools/codegenerator.py#L660-L661 https://github.com/enthought/comtypes/blob/096bfde508bc32466e3fac18790fc93bdaa3cc37/comtypes/tools/codegenerator.py#L724-L725 https://github.com/enthought/comtypes/blob/096bfde508bc32466e3fac18790fc93bdaa3cc37/comtypes/tools/codegenerator.py#L801-L802

If only changing them to single quotes as before, it might also cause a SyntaxError by the source containing specific letters, like ' or \.

A better escaping method is needed.

junkmd avatar Aug 08 '22 13:08 junkmd

@pshv

Please try this (replace .../comtypes/tools/codegenerator.py). https://github.com/junkmd/comtypes/blob/fe273542dd878d54ea58add6ccd4935951f9ad9d/comtypes/tools/codegenerator.py

I don't have Visio in my environment, so please try if it works in yours.

junkmd avatar Aug 10 '22 08:08 junkmd

@junkmd works well for me with patched codegenerator you provided, thanks!

pshv avatar Aug 10 '22 10:08 pshv

To solve this problem, I PRed #338.

In addition to the previous change, the indentation is also handled within the function.

junkmd avatar Aug 10 '22 11:08 junkmd

@pshv 1.1.14 is out. Please try.

vasily-v-ryabov avatar Aug 19 '22 09:08 vasily-v-ryabov

Works well on 1.1.14, closing the issue. Thanks @junkmd @vasily-v-ryabov

pshv avatar Aug 19 '22 14:08 pshv