Bug 147057 - Wrong Python version (seems to be 3.8, but doesn't know 3.6 feature)
Summary: Wrong Python version (seems to be 3.8, but doesn't know 3.6 feature)
Status: RESOLVED NOTABUG
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: LibreOffice (show other bugs)
Version:
(earliest affected)
7.1.8.1 release
Hardware: All Windows (All)
: medium normal
Assignee: Not Assigned
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-01-29 14:06 UTC by peter.88213
Modified: 2022-01-30 10:46 UTC (History)
1 user (show)

See Also:
Crash report or crash signature:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description peter.88213 2022-01-29 14:06:12 UTC
Description:
The Python installation is in a subdirectory called "python-core-3.8.8", so I assumed that Python 3.8 is embedded.  
However, the embedded Python does not support the "f-string" formatting feature introduced with Python 3.6.
How to find out which Python grammar actually applies to LO macros?

Here is a Python 3.6 string formatting example that does not work with LO embedded Python:

state = 'not dead'
opinion = f'This bird is {state}'

However, this old style code works with LO embedded Python:

state = 'not dead'
opinion = 'This bird is {}'.format(state)



Steps to Reproduce:
1.Put an f-string in a message window (see example above)
2.e.g. f'This bird is {state}'
3.Execute macro

Actual Results:
Display: 
This bird is {state}

Expected Results:
Correct display is:
This bird is not dead


Reproducible: Always


User Profile Reset: No



Additional Info:
In Eclipse PyDev, the f-string code is marked as error if I set the embedded LO Python interpreter. This means, its grammar seems not to comply with Python version 3.6+
Comment 1 Ming Hua 2022-01-29 14:26:46 UTC
(In reply to peter.88213 from comment #0)
> The Python installation is in a subdirectory called "python-core-3.8.8", so
> I assumed that Python 3.8 is embedded.  
> However, the embedded Python does not support the "f-string" formatting
> feature introduced with Python 3.6.
The 7.1.8 version of LibreOffice (which you specified in the Version field) indeed has python 3.8.8 embedded.

> state = 'not dead'
> opinion = f'This bird is {state}'
This f-string works fine for me with LO 7.1.7 on Windows 10, when directly run in a Windows terminal (cmd.exe):

C:\Programs\LibreOffice\7.1.7\program>.\python.exe
Python 3.8.8rc1 (default, Oct 27 2021, 21:26:25) [MSC v.1928 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> state = 'not dead'
>>> opinion = f'This bird is {state}'
>>> print( opinion )
This bird is not dead

So something is wrong with either your Eclipse setup or your macro.  Please describe your setup in more details and provide a macro example, or rather, seek help in user-support forums and come back when you are sure the problem exists in the LibreOffice program/framework itself instead of your local setup.
Comment 2 peter.88213 2022-01-29 17:27:27 UTC
Thank you so much for the quick response, Ming Hua. Following your advice, I could verify the Python version number and make sure that f-strings are basically working on the command line. Before filing my bug report, I already tried that, but with C:\Program Files\LibreOffice\program\python-core-3.8.8\bin\python.exe which is not working at all on my system.

Please close the issue. I think you are right and the problem might have its source in my eclipse setup. Developing LO macros with eclipse is quite tricky because I haven't found a way to establish the UNO bindings yet.

Is there a reference list showing which Python version comes with which LO release?
Comment 3 QA Administrators 2022-01-30 03:46:26 UTC Comment hidden (obsolete)
Comment 4 Ming Hua 2022-01-30 05:39:01 UTC
(In reply to peter.88213 from comment #2)
> Please close the issue. I think you are right and the problem might have its
> source in my eclipse setup. Developing LO macros with eclipse is quite
> tricky because I haven't found a way to establish the UNO bindings yet.
There are some information about using an IDE with LibreOffice's python on wiki [1], but nothing about Eclipse.  Admittedly the documentation about this area is rather sparse.

> Is there a reference list showing which Python version comes with which LO
> release?
Not that I know of.  One can always look into the source code repository and deduce this information from git log, but that's not easy.  And it isn't very useful anyway, because (1) it only shows the version of bundled python, which is usually the case for Windows, but many Linux distributions build LibreOffice with system's python and don't bundle it, therefore the python version will just be the distribution's choice for the whole system; and (2) the bundled python is just a subset of the official upstream python and many modules of the standard library are stripped, so it's a bit unreliable to predict which python feature is available just by looking at the bundled python version number.

1. https://wiki.documentfoundation.org/Macros/Python_Design_Guide
Comment 5 peter.88213 2022-01-30 10:46:27 UTC
Thank you for the information. 
Keep up the good work.