Despite being introduced on Python 3.6, the original implementation
was too limited: it doesn't accept anything but the argument.
Even on python 3.10.12, support was still limited, as more complex
operations cause SyntaxError:
Exception occurred:
File ".../linux/Documentation/sphinx/kernel_abi.py", line 48, in <module>
from get_abi import AbiParser
File ".../linux/scripts/get_abi.py", line 525
msg += f"{part}\n{"-" * len(part)}\n\n"
^
SyntaxError: f-string: expecting '}'
Replace f-strings by normal string concatenation when it doesn't
work on Python 3.6.
Reported-by: Akira Yokosawa <akiyks@gmail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
---
scripts/get_abi.py | 16 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)
diff --git a/scripts/get_abi.py b/scripts/get_abi.py
index 543bed397c8c..e6e94f721fff 100755
--- a/scripts/get_abi.py
+++ b/scripts/get_abi.py
@@ -522,7 +522,7 @@ class AbiParser:
if cur_part and cur_part != part:
part = cur_part
- msg += f"{part}\n{"-" * len(part)}\n\n"
+ msg += part + "\n"+ "-" * len(part) +"\n\n"
msg += f".. _{key}:\n\n"
@@ -546,7 +546,7 @@ class AbiParser:
msg += f"Defined on file :ref:`{base} <{ref[1]}>`\n\n"
if wtype == "File":
- msg += f"{names[0]}\n{"-" * len(names[0])}\n\n"
+ msg += names[0] +"\n" + "-" * len(names[0]) +"\n\n"
desc = v.get("description")
if not desc and wtype != "File":
@@ -570,7 +570,8 @@ class AbiParser:
users = v.get("users")
if users and users.strip(" \t\n"):
- msg += f"Users:\n\t{users.strip("\n").replace('\n', '\n\t')}\n\n"
+ users = users.strip("\n").replace('\n', '\n\t')
+ msg += f"Users:\n\t{users}\n\n"
ln = v.get("line_no", 1)
@@ -596,7 +597,9 @@ class AbiParser:
elif len(lines) == 1:
f.append(f"{fname}:{lines[0]}")
else:
- f.append(f"{fname} lines {", ".join(str(x) for x in lines)}")
+ m = fname + "lines "
+ m += ", ".join(str(x) for x in lines)
+ f.append(m)
self.log.warning("%s is defined %d times: %s", what, len(f), "; ".join(f))
@@ -644,10 +647,11 @@ class AbiParser:
if users:
print(f"Users:\t\t\t{users}")
- print(f"Defined on file{'s'[:len(files) ^ 1]}:\t{", ".join(files)}")
+ print("Defined on file(s):\t" + ", ".join(files))
if desc:
- print(f"\n{desc.strip("\n")}\n")
+ desc = desc.strip("\n")
+ print(f"\n{desc}\n")
if not found_keys:
print(f"Regular expression /{expr}/ not found.")
--
2.48.1
Mauro Carvalho Chehab <mchehab+huawei@kernel.org> writes:
> Despite being introduced on Python 3.6, the original implementation
> was too limited: it doesn't accept anything but the argument.
The original implementation *of f-strings* ?
> Even on python 3.10.12, support was still limited, as more complex
> operations cause SyntaxError:
>
> Exception occurred:
> File ".../linux/Documentation/sphinx/kernel_abi.py", line 48, in <module>
> from get_abi import AbiParser
> File ".../linux/scripts/get_abi.py", line 525
> msg += f"{part}\n{"-" * len(part)}\n\n"
> ^
> SyntaxError: f-string: expecting '}'
>
> Replace f-strings by normal string concatenation when it doesn't
> work on Python 3.6.
>
> Reported-by: Akira Yokosawa <akiyks@gmail.com>
> Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
So I'm curious ... later in the series, you make 3.9 the minimal version
for the kernel. Given that, is there value in adding compatibility for
older versions here?
Thanks,
jon
Hi,
Jonathan Corbet wrote:
> Mauro Carvalho Chehab <mchehab+huawei@kernel.org> writes:
>
>> Despite being introduced on Python 3.6, the original implementation
>> was too limited: it doesn't accept anything but the argument.
>
> The original implementation *of f-strings* ?
>
>> Even on python 3.10.12, support was still limited, as more complex
>> operations cause SyntaxError:
>>
>> Exception occurred:
>> File ".../linux/Documentation/sphinx/kernel_abi.py", line 48, in <module>
>> from get_abi import AbiParser
>> File ".../linux/scripts/get_abi.py", line 525
>> msg += f"{part}\n{"-" * len(part)}\n\n"
>> ^
>> SyntaxError: f-string: expecting '}'
>>
>> Replace f-strings by normal string concatenation when it doesn't
>> work on Python 3.6.
>>
>> Reported-by: Akira Yokosawa <akiyks@gmail.com>
You might want to add
Closes: https://lore.kernel.org/2d4d3fd1-5fe2-4d18-9085-73f9ff930c2d@gmail.com/
>> Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
>
> So I'm curious ... later in the series, you make 3.9 the minimal version
> for the kernel. Given that, is there value in adding compatibility for
> older versions here?
I think rewording the summary to
"scripts/get_abi.py: make it backward-compatible with Python <3.11"
would resolve Jon's confusion.
I haven't looked into python3'changelog, but it might be
"... backward-compatible with Python <3.12".
Mauro, which python3 release extended the f-string implementation?
Thanks, Akira
Em Wed, 5 Feb 2025 11:37:52 +0900
Akira Yokosawa <akiyks@gmail.com> escreveu:
> Hi,
>
> Jonathan Corbet wrote:
> > Mauro Carvalho Chehab <mchehab+huawei@kernel.org> writes:
> >
> >> Despite being introduced on Python 3.6, the original implementation
> >> was too limited: it doesn't accept anything but the argument.
> >
> > The original implementation *of f-strings* ?
Yes. IMO, even the original version of f-strings is better than the legacy
way of using '"string" % (tuple)' or "str.format".
Besides that, there aren't many places where it uses expressions inside
f-strings.
> >
> >> Even on python 3.10.12, support was still limited, as more complex
> >> operations cause SyntaxError:
> >>
> >> Exception occurred:
> >> File ".../linux/Documentation/sphinx/kernel_abi.py", line 48, in <module>
> >> from get_abi import AbiParser
> >> File ".../linux/scripts/get_abi.py", line 525
> >> msg += f"{part}\n{"-" * len(part)}\n\n"
> >> ^
> >> SyntaxError: f-string: expecting '}'
> >>
> >> Replace f-strings by normal string concatenation when it doesn't
> >> work on Python 3.6.
> >>
> >> Reported-by: Akira Yokosawa <akiyks@gmail.com>
>
> You might want to add
>
> Closes: https://lore.kernel.org/2d4d3fd1-5fe2-4d18-9085-73f9ff930c2d@gmail.com/
>
> >> Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
> >
> > So I'm curious ... later in the series, you make 3.9 the minimal version
> > for the kernel. Given that, is there value in adding compatibility for
> > older versions here?
No because 3.9 is still not enough to accept a valid Python expression on f-strings.
This arrived only on Python 3.12[1]:
"Expression components inside f-strings can now be any valid Python expression"
So, with this patch, doc build can be using Python 3.6. Still, it makes
sense to move minimal version to 3.9 due to the current status of other
Python scripts.
[1] https://docs.python.org/3/whatsnew/3.12.html#pep-701-syntactic-formalization-of-f-strings
> I think rewording the summary to
>
> "scripts/get_abi.py: make it backward-compatible with Python <3.11"
>
> would resolve Jon's confusion.
Sure, but IMO it is still valuable to say somewhere that the script
was tested and it is known to work since Python 3.6.
>
> I haven't looked into python3'changelog, but it might be
> "... backward-compatible with Python <3.12".
> Mauro, which python3 release extended the f-string implementation?
See above. I only did a quick check, but it sounds that 3.12 is the
one that finally implemented f-strings properly in a similar way to
what Perl 5 does with $'expression' inside strings.
Thanks,
Mauro
Mauro Carvalho Chehab wrote:
> Em Wed, 5 Feb 2025 11:37:52 +0900
> Akira Yokosawa <akiyks@gmail.com> escreveu:
[...]
>> I think rewording the summary to
>>
>> "scripts/get_abi.py: make it backward-compatible with Python <3.11"
>>
>> would resolve Jon's confusion.
>
> Sure, but IMO it is still valuable to say somewhere that the script
> was tested and it is known to work since Python 3.6.
>
If you want "3.6" in the summary phrase, how about
"scripts/get_abi.py: make it backward-compatible with Python <3.12 >=3.6"
?
Thanks, Akira
Mauro Carvalho Chehab wrote:
> Despite being introduced on Python 3.6, the original implementation
> was too limited: it doesn't accept anything but the argument.
>
> Even on python 3.10.12, support was still limited, as more complex
> operations cause SyntaxError:
>
> Exception occurred:
> File ".../linux/Documentation/sphinx/kernel_abi.py", line 48, in <module>
> from get_abi import AbiParser
> File ".../linux/scripts/get_abi.py", line 525
> msg += f"{part}\n{"-" * len(part)}\n\n"
> ^
> SyntaxError: f-string: expecting '}'
>
> Replace f-strings by normal string concatenation when it doesn't
> work on Python 3.6.
>
> Reported-by: Akira Yokosawa <akiyks@gmail.com>
> Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Tested-by: Akira Yokosawa <akiyks@gmail.com>
Thanks.
© 2016 - 2025 Red Hat, Inc.