Also, removing these large type unions and using 'Any'. I've ran all
the test cases with Python 3.7 to double check it is compatible.
If we have 'var' of type 'str | bool' and we are sure it is a string
and want to do this:
new_var = var.split(' ')
you will see warnings from type checkers because bool doesn't have a
split method. Since these type unions are so large, Any makes more sense.
Collin
From 236fe3cd421eb01c8e2afd4a095ede848313dae5 Mon Sep 17 00:00:00 2001
From: Collin Funk <collin.fu...@gmail.com>
Date: Thu, 4 Apr 2024 21:41:08 -0700
Subject: [PATCH 3/3] gnulib-tool.py: Use 'Any' instead of type unions in
GLConfig.
* pygnulib/GLConfig.py (GLConfig.__getitem__, GLConfig.dictionary)
(GLConfig.default, GLConfig.isdefault, GLConfig.values): Use 'Any' from
the typing module instead of large type unions. This silences unhelpful
warnings from type checkers.
---
ChangeLog | 8 ++++++++
pygnulib/GLConfig.py | 11 ++++++-----
2 files changed, 14 insertions(+), 5 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 6e4be3e76c..2dab49b279 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2024-04-04 Collin Funk <collin.fu...@gmail.com>
+
+ gnulib-tool.py: Use 'Any' instead of type unions in GLConfig.
+ * pygnulib/GLConfig.py (GLConfig.__getitem__, GLConfig.dictionary)
+ (GLConfig.default, GLConfig.isdefault, GLConfig.values): Use 'Any' from
+ the typing module instead of large type unions. This silences unhelpful
+ warnings from type checkers.
+
2024-04-04 Collin Funk <collin.fu...@gmail.com>
gnulib-tool.py: Fix 'consider-using-set-comprehension' warnings.
diff --git a/pygnulib/GLConfig.py b/pygnulib/GLConfig.py
index 121edf541e..1c9caa218b 100644
--- a/pygnulib/GLConfig.py
+++ b/pygnulib/GLConfig.py
@@ -21,6 +21,7 @@ from __future__ import annotations
import os
import copy
import tempfile
+from typing import Any
from . import constants
from .GLError import GLError
from pygnulib.enums import CopyAction
@@ -248,14 +249,14 @@ class GLConfig:
'''x.__repr__() <==> repr(x)'''
return '<pygnulib.GLConfig>'
- def __getitem__(self, y: str) -> str | float | int | bool | CopyAction | list[str] | None:
+ def __getitem__(self, y: str) -> Any:
'''x.__getitem__(y) <==> x[y]'''
if y in self.table:
return self.table[y]
else: # if y not in self.table
raise KeyError('GLConfig does not contain key: %s' % repr(y))
- def dictionary(self) -> dict[str, str | float | int | bool | CopyAction | list[str] | None]:
+ def dictionary(self) -> dict[str, Any]:
'''Return the configuration as a dict object.'''
return dict(self.table)
@@ -296,7 +297,7 @@ class GLConfig:
else: # if key not in self.table
raise KeyError('GLConfig does not contain key: %s' % repr(key))
- def default(self, key: str) -> str | float | int | bool | CopyAction | list[str] | None:
+ def default(self, key: str) -> Any:
'''Return default value for the given key.'''
if key in self.table:
if key == 'libname':
@@ -327,7 +328,7 @@ class GLConfig:
else: # if key not in self.table
raise KeyError('GLConfig does not contain key: %s' % repr(key))
- def isdefault(self, key: str, value: str | float | int | bool | CopyAction | list[str] | None) -> bool:
+ def isdefault(self, key: str, value: Any) -> bool:
'''Check whether the value for the given key is a default value.'''
if key in self.table:
default = self.default(key)
@@ -339,7 +340,7 @@ class GLConfig:
'''Return list of keys.'''
return list(self.table.keys())
- def values(self) -> list[str | float | int | bool | CopyAction | list[str] | None]:
+ def values(self) -> list[Any]:
'''Return list of values.'''
return list(self.table.values())
--
2.44.0