Removal of Python 2 (Request for Comments)

José Matos jaomatos at gmail.com
Sat Jun 1 10:53:48 UTC 2024


On Fri, 2024-05-31 at 12:54 -0400, Richard Kimberly Heck wrote:
> I'm especially thinking of older files (say, lyx_1_5.py) that will
> not get much testing. It'd be bad to break one of those.

I know that I am revisiting this but I want to give further context to
why I am doing this.

I am testing with tools that were developed for Python 3 and this is
revealing bugs in code/even in older code.

Point in case, I am using mypy (in order to use type annotations that
can be used for type hinting).

Running this I identified two cases that are real bugs:
lyx_2_0.py:2304: error: Function "check_passthru" could always be true
in boolean context  [truthy-function]
lyx_2_0.py:2369: error: Function "check_passthru" could always be true
in boolean context  [truthy-function]

The code reads as
     if not check_passthru:
        return

but check_passthru is a function and thus the result is always true.

The code should have been
     if not check_passthru(document):
        return


I am using this to annotate both variables and functions.
So, for example, all the converter files will have something like this
(this is the easiest example for 0.6 files):

from LyX import Converter_format
# Converter_format is defined in the LyX module as
# list[tuple[int, list[Callable[[type[LyX_base]], None]]]]

supported_versions: list[str] = ["0.6"] + [f"0.6.{i}" for i in
range(5)]
convert: Converter_format = [(200, [])]
revert: Converter_format = []

In this case the Converter_format makes it explicit what is the
structure of that variable. These annotations are not used at runtime
but can be used to do static analysis of the code.

It was not possible to used this before as we wanted to also support
Python 2 where this syntax is not possible at all.
-- 
José Abílio


More information about the lyx-devel mailing list