bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

gnulib-tool.py: Add type hints to classes.


From: Collin Funk
Subject: gnulib-tool.py: Add type hints to classes.
Date: Mon, 29 Apr 2024 03:43:16 -0700
User-agent: Mozilla Thunderbird

This patch adds type hints to the Python classes.

Same as previously done in GLFileTable that I wrote. The only new
thing introduced is the syntax for class variables, so this line in a
class definition:

     section_label_pattern = re.compile(...)

becomes this:

     section_label_pattern: ClassVar[re.Pattern] = re.compile(...)

That variable is shared between all GLModule objects to match the
start of sections in the module description (e.g. 'Depends-on:').

I guess it is also used for checkers to give warnings when modifying
class variables on an instance variable:

    var = GLModule(...)
    var.section_label_pattern = 'warning here'
    GLModule.section_label_pattern = 'no warning here'

But I haven't checked that. I remember finding those confusing when I
first used Python, so I think it serves as a good reminder. No harm as
far as comparability goes since it was introduced in version 3.5 [1].

I'll probably wait until late today or tomorrow to push this + the
--create-megatestdir fix [2].

[1] https://docs.python.org/3/library/typing.html#typing.ClassVarx
[2] https://lists.gnu.org/archive/html/bug-gnulib/2024-04/msg00501.html

Collin

Attachment: 0001-gnulib-tool.py-Add-type-hints-to-classes.patch
Description: Text Data


reply via email to

[Prev in Thread] Current Thread [Next in Thread]