Skip to content

Commit b00e1ea

Browse files
committed
Merge branch 'templates/py-type-checker-pyright'
Signed-off-by: kilo52 <[email protected]>
2 parents 77de0fb + 9059040 commit b00e1ea

31 files changed

+138
-50
lines changed

python/01_installable_script/init.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ form_python_exec_script_name;
6363

6464
form_python_use_linter;
6565

66+
form_python_use_type_checker;
67+
6668
form_python_pypi_deployment;
6769

6870
form_docs_integration;

python/01_installable_script/source/test.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ ${{VAR_SCRIPT_TEST_ISOLATED_OPT}}
1313
${{VAR_SCRIPT_TEST_LINT_HELP}}
1414
1515
[--no-virtualenv] Do not use a virtual environment for the tests.
16+
${{VAR_SCRIPT_TEST_TYPE_CHECK_HELP}}
1617
1718
[-?|--help] Show this help message.
1819
EOS
@@ -22,6 +23,7 @@ EOS
2223
${{VAR_SCRIPT_BUILD_ISOLATED_ARGFLAG}}
2324
${{VAR_SCRIPT_TEST_LINT_ARG}}
2425
ARG_NO_VIRTUALENV=false;
26+
${{VAR_SCRIPT_TEST_TYPE_CHECK_ARG}}
2527
ARG_SHOW_HELP=false;
2628

2729
${{VAR_SCRIPT_BUILD_ISOLATED_ARGARRAY}}
@@ -35,6 +37,7 @@ ${{VAR_SCRIPT_TEST_LINT_ARG_PARSE}}
3537
ARG_NO_VIRTUALENV=true;
3638
shift
3739
;;
40+
${{VAR_SCRIPT_TEST_TYPE_CHECK_ARG_PARSE}}
3841
-\?|--help)
3942
ARG_SHOW_HELP=true;
4043
shift
@@ -72,6 +75,7 @@ if [[ $ARG_NO_VIRTUALENV == false ]]; then
7275
fi
7376

7477
${{VAR_SCRIPT_TEST_LINT_CODE}}
78+
${{VAR_SCRIPT_TEST_TYPE_CHECK_CODE}}
7579

7680
logI "Running unit tests";
7781
${_PYTHON_EXEC} -m unittest;

python/02_library/init.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/bash
2-
# Copyright (C) 2024 Raven Computing
2+
# Copyright (C) 2025 Raven Computing
33
#
44
# Licensed under the Apache License, Version 2.0 (the "License");
55
# you may not use this file except in compliance with the License.
@@ -35,6 +35,8 @@ form_python_package_name;
3535

3636
form_python_use_linter;
3737

38+
form_python_use_type_checker;
39+
3840
form_python_pypi_deployment;
3941

4042
form_docs_integration;

python/02_library/source/package/generator.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,18 @@ class Generator(ABC):
88
"""Dummy abstract base class.
99
1010
Attributes:
11-
val (any): The base value used by the Generator.
11+
basis (str): The base value used by the Generator.
1212
index (int): The index used by the Generator.
1313
"""
1414

15-
def __init__(self, val):
16-
self.val = val
17-
self.index = 0
15+
def __init__(self, basis: str):
16+
self.basis: str = basis
17+
self.index: int = 0
1818

1919
@abstractmethod
20-
def generate(self):
21-
"""Generates an object of the Generator.
20+
def generate(self) -> str:
21+
"""Generates a dummy string of this Generator.
2222
2323
Returns:
24-
any: An object of the Generator
24+
str: A dummy string of the Generator
2525
"""
26-
pass

python/02_library/source/package/string_generator.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,6 @@ def __init__(self):
1111
super().__init__("${{VAR_PROJECT_SLOGAN_STRING}}")
1212

1313
def generate(self):
14-
"""Generates a dummy String of this StringGenerator.
15-
16-
Returns:
17-
A String object of this Generator
18-
"""
1914
index = self.index
2015
self.index += 1
21-
return self.val + " " + str(index)
16+
return f"{self.basis} {index}"

python/02_library/source/test.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ ${{VAR_SCRIPT_TEST_ISOLATED_OPT}}
1414
${{VAR_SCRIPT_TEST_LINT_HELP}}
1515
1616
[--no-virtualenv] Do not use a virtual environment for the tests.
17+
${{VAR_SCRIPT_TEST_TYPE_CHECK_HELP}}
1718
1819
[-?|--help] Show this help message.
1920
EOS
@@ -23,6 +24,7 @@ EOS
2324
${{VAR_SCRIPT_BUILD_ISOLATED_ARGFLAG}}
2425
${{VAR_SCRIPT_TEST_LINT_ARG}}
2526
ARG_NO_VIRTUALENV=false;
27+
${{VAR_SCRIPT_TEST_TYPE_CHECK_ARG}}
2628
ARG_SHOW_HELP=false;
2729

2830
${{VAR_SCRIPT_BUILD_ISOLATED_ARGARRAY}}
@@ -36,6 +38,7 @@ ${{VAR_SCRIPT_TEST_LINT_ARG_PARSE}}
3638
ARG_NO_VIRTUALENV=true;
3739
shift
3840
;;
41+
${{VAR_SCRIPT_TEST_TYPE_CHECK_ARG_PARSE}}
3942
-\?|--help)
4043
ARG_SHOW_HELP=true;
4144
shift
@@ -73,6 +76,7 @@ if [[ $ARG_NO_VIRTUALENV == false ]]; then
7376
fi
7477

7578
${{VAR_SCRIPT_TEST_LINT_CODE}}
79+
${{VAR_SCRIPT_TEST_TYPE_CHECK_CODE}}
7680

7781
logI "Running unit tests";
7882
${_PYTHON_EXEC} -m unittest;

python/03_library_native_ctypes/init.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/bash
2-
# Copyright (C) 2024 Raven Computing
2+
# Copyright (C) 2025 Raven Computing
33
#
44
# Licensed under the Apache License, Version 2.0 (the "License");
55
# you may not use this file except in compliance with the License.
@@ -36,6 +36,8 @@ form_python_package_name;
3636

3737
form_python_use_linter;
3838

39+
form_python_use_type_checker;
40+
3941
form_python_pypi_deployment;
4042

4143
form_docs_integration;

python/03_library_native_ctypes/source/package/comparator.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,21 @@ class Comparator(ABC):
88
"""Dummy abstract base class.
99
1010
Attributes:
11-
val (any): The base value used by the Comparator.
12-
ncalls (int): The number of calls to the compare() method of
11+
val (str): The base value used by the Comparator.
12+
ncalls (int): The number of calls to the `compare()` method of
1313
the Comparator instance.
1414
"""
1515

16-
def __init__(self, val):
17-
self.val = val
18-
self.ncalls = 0
16+
def __init__(self, val: str):
17+
self.val: str = val
18+
self.ncalls: int = 0
1919

2020
@abstractmethod
21-
def compare(self, val):
21+
def compare(self, val: str) -> int:
2222
"""Compares the specified object to the set object of this Comparator.
2323
2424
Args:
25-
val (any): The object with which to compare.
25+
val (str): The string with which to compare.
2626
2727
Returns:
2828
int: An int indicating the result of the comparison.
@@ -32,4 +32,3 @@ def compare(self, val):
3232
A positive int value if the set object is greater
3333
than the specified object.
3434
"""
35-
pass

python/03_library_native_ctypes/source/package/string_comparator.py

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
from ${{VAR_NAMESPACE_DECLARATION}}.comparator import Comparator
1010

1111

12-
def _load_native_library():
12+
def _load_native_library() -> ctypes.CDLL:
1313
"""Loads the native library on which this module depends on.
1414
1515
Returns:
16-
The ctypes CDLL native library object.
16+
CDLL: The ctypes CDLL native library object.
1717
"""
1818
libname = "msvcrt" if sys.platform.lower().startswith("win") else "c"
1919
lib = find_library(libname)
@@ -26,18 +26,18 @@ class StringComparator(Comparator):
2626
2727
This implementation only supports comparing strings containing
2828
ASCII characters.
29-
This class uses the native strcmp() C function for string comparisons.
29+
This class uses the native `strcmp()` C function for string comparisons.
3030
"""
3131

3232
# Object representing the loaded native DLL/shared library
3333
_CDLL_LIB_C = _load_native_library()
3434

35-
def __init__(self, val="${{VAR_PROJECT_SLOGAN_STRING}}"):
36-
"""Constructs a new StringComparator object for comparing
35+
def __init__(self, val: str = "${{VAR_PROJECT_SLOGAN_STRING}}"):
36+
"""Initializes a new StringComparator object for comparing
3737
strings with the specified string object.
3838
3939
Args:
40-
val: The str used for all comparisons. May not be None
40+
val (str): The str used for all comparisons. May not be `None`.
4141
"""
4242
if val is None:
4343
raise TypeError("Invalid argument. None is not allowed")
@@ -49,15 +49,15 @@ def compare(self, val):
4949
of this StringComparator.
5050
5151
Args:
52-
val: The string with which to compare, as a str.
52+
val (str): The string with which to compare.
5353
5454
Returns:
55-
An int indicating the result of the comparison.
56-
Returns 0 (zero) if both strings are equal.
57-
Returns a negative int value if the set string is less than
58-
the specified string.
59-
Returns a positive int value if the set string is greater
60-
than the specified string.
55+
int: An int indicating the result of the comparison.
56+
Returns 0 (zero) if both strings are equal.
57+
Returns a negative int value if the set string is less than
58+
the specified string.
59+
Returns a positive int value if the set string is greater
60+
than the specified string.
6161
6262
Raises:
6363
ValueError: If either the internal or specified string
@@ -70,14 +70,7 @@ def compare(self, val):
7070
return self._compare_native_0(val)
7171

7272
def _compare_native_0(self, val):
73-
"""Implementation of compare() method using native function calls.
74-
75-
Args:
76-
val: The string with which to compare, as a str.
77-
78-
Returns:
79-
An int indicating the result of the strcmp() comparison.
80-
"""
73+
"""Implementation of compare() method using native function calls."""
8174
# Convert str to bytes objects
8275
arg1 = str(self.val).encode(encoding="ascii")
8376
arg2 = str(val).encode(encoding="ascii")
@@ -87,5 +80,6 @@ def _compare_native_0(self, val):
8780
_cfunc.restype = ctypes.c_int
8881
# Call C function and convert arguments to corresponding C types
8982
res = _cfunc(ctypes.c_char_p(arg1), ctypes.c_char_p(arg2))
90-
# As the return type is a c_int, we get a Python int and return it as is
83+
# As the return type is a c_int, we get a Python int
84+
# and return it as is
9185
return res

python/03_library_native_ctypes/source/test.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ ${{VAR_SCRIPT_TEST_ISOLATED_OPT}}
1414
${{VAR_SCRIPT_TEST_LINT_HELP}}
1515
1616
[--no-virtualenv] Do not use a virtual environment for the tests.
17+
${{VAR_SCRIPT_TEST_TYPE_CHECK_HELP}}
1718
1819
[-?|--help] Show this help message.
1920
EOS
@@ -23,6 +24,7 @@ EOS
2324
${{VAR_SCRIPT_BUILD_ISOLATED_ARGFLAG}}
2425
ARG_LINT=false;
2526
ARG_NO_VIRTUALENV=false;
27+
${{VAR_SCRIPT_TEST_TYPE_CHECK_ARG}}
2628
ARG_SHOW_HELP=false;
2729

2830
${{VAR_SCRIPT_BUILD_ISOLATED_ARGARRAY}}
@@ -36,6 +38,7 @@ ${{VAR_SCRIPT_TEST_LINT_ARG_PARSE}}
3638
ARG_NO_VIRTUALENV=true;
3739
shift
3840
;;
41+
${{VAR_SCRIPT_TEST_TYPE_CHECK_ARG_PARSE}}
3942
-\?|--help)
4043
ARG_SHOW_HELP=true;
4144
shift
@@ -73,6 +76,7 @@ if [[ $ARG_NO_VIRTUALENV == false ]]; then
7376
fi
7477

7578
${{VAR_SCRIPT_TEST_LINT_CODE}}
79+
${{VAR_SCRIPT_TEST_TYPE_CHECK_CODE}}
7680

7781
logI "Running unit tests";
7882
${_PYTHON_EXEC} -m unittest;

0 commit comments

Comments
 (0)