[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: gnulib-tool.py: Fix some unbound variables.
From: |
Collin Funk |
Subject: |
Re: gnulib-tool.py: Fix some unbound variables. |
Date: |
Wed, 10 Apr 2024 05:38:22 -0700 |
User-agent: |
Mozilla Thunderbird |
Hi Bruno,
On 4/9/24 12:04 PM, Bruno Haible wrote:
> A better fix would be revisit this 'verifier'. Either an enum with 3 possible
> values, or (better) a function GLModule -> bool. And call it 'moduleFilter'
> rather than 'verifier'.
How does this patch look?
This method seems much clearer to me than passing 0, 1, or 2 which
have no meaning unless you have previously read the docstring.
I've type hinted it and double checked that it works with Python 3.7
and Python 3.12 on my machine. The type hinting looks something like
this [1]:
from collections.abc import Callable
def autoconfSnippets(self, ..., module_filter: Callable[[GLModule], bool])
-> str:
Meaning that 'module_filter' is a function that accepts a GLModule
object and returns a bool.
This removes a lot of repetitive lines which is nice. The conditionals
can be refactored to remove a level of nesting in a few places. I
didn't do that now since it would make the patch harder to follow.
I've just used lambda functions since these functions are just
wrappers around GLModule methods. I'm not sure if it is better to
define them in GLModuleSystem.py or something. Since you are the
lisp expert, I will trust your judgment here.
Also, now I see an annoying warning:
lambda module: True # warning under 'module'
because pyright thinks it is unused [2]. I tried omitting the 'module'
in hopes that Python would just deal with it. But it gives this:
Traceback (most recent call last):
[...]
File "/home/collin/.local/src/gnulib/pygnulib/GLEmiter.py", line 311, in
autoconfSnippets
if module_filter(module):
^^^^^^^^^^^^^^^^^^^^^
TypeError: GLImport.gnulib_comp.<locals>.<lambda>() takes 0 positional
arguments but 1 was given
Maybe I will use fixing that as an excuse to add to the HACKING file.
I meant to add information there earlier but got lazy...
[1] https://docs.python.org/3/library/typing.html#annotating-callable-objects
[2] https://github.com/microsoft/pyright
Collin
0001-gnulib-tool.py-Use-function-arguments-instead-of-mag.patch
Description: Text Data