bug-gnulib
[Top][All Lists]
Advanced

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

Re: gnulib-tool.py: Update type hints and docstring.


From: Collin Funk
Subject: Re: gnulib-tool.py: Update type hints and docstring.
Date: Sun, 21 Apr 2024 11:43:07 -0700
User-agent: Mozilla Thunderbird

On 4/21/24 4:07 AM, Bruno Haible wrote:
> Also, what about the type of filetable? It is described as
> 
>   dict[str, list[str]]
> 
> but I think it is more
> 
>   dict[str, list[str | tuple[str, str]]]
> 
> right?

Good catch. I think the one you have written is correct because of the
filetable['old'] and filetable['new'] which both have
[(rewritten, original), ...].

Using union types like that is annoying with type checkers though. For
example, using that type hint and this line of code in
GLImport.execute():

       if [ file
             for file in filetable['all']
             if file.startswith('doc/') ]:

I see this warning under 'startswith' from Pyright:

  /home/collin/.local/src/gnulib/pygnulib/GLImport.py:1020:22 - error: Cannot 
access attribute "startswith" for class "tuple[str, str]"
    Attribute "startswith" is unknown (reportAttributeAccessIssue)

or with mypy:

  GLImport.py:1020: error: Item "tuple[str, ...]" of "str | tuple[str, str]" 
has no attribute "startswith"  [union-attr]

It might just be more beneficial to use 'Any' for complex unions like
that. You could ignore warnings like:

       if [ file
             for file in filetable['all']
             if file.startswith('doc/') ]: # type: ignore

but that feels annoying for variables used frequently like that filetable.

Collin



reply via email to

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