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 15:37:12 -0700
User-agent: Mozilla Thunderbird

Hi Bruno,

On 4/21/24 2:43 PM, Bruno Haible wrote:
> Hmm. It's valid code that will work at runtime. I would understand a
> "warning", if the tool cannot prove that the code is safe. But "error"?
> That's too severe. It's again time for a bug report or two, I would say.

Haha, yes maybe "error" is a bit more scary than it should be. It
isn't a bug though, just limitations on type checking a dynamic
language.

I haven't checked but I believe you could use 'dict' which would be
equivalent to 'dict[Any, Any]' or even 'dict[str, Any]'. The latter
*should* turn off type checking for the value at dict['key'] [1].

There are ways to remove types from the union, called "narrowing", but
they wouldn't make much sense when we know a specific dictionary key
will have a certain type [2].

Sorry for the not-so great explanations. I am still learning about the
type hinting and type checking stuff. Overall I think it is a good
decision though. In the past I remember finding large Python code hard
to follow without them.

> Nah. I think the better cure of the problem is to abandon the 'dict' type
> here. That is, create a proper Python class GLFileTable with five attributes.
> In this situation, the five attributes are not constrained to have the same
> type.

I agree. I think that would make things more clear anyways. Maybe I
will find an opportunity there to remove the duplicate rewrite_files
functions.

[1] 
https://mypy.readthedocs.io/en/stable/dynamic_typing.html#operations-on-any-values
[2] 
https://mypy.readthedocs.io/en/stable/type_narrowing.html#type-narrowing-expressions

Collin



reply via email to

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