Skip to content

Add Option for Type Checker in Python Projects #99

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Jul 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.8.4-dev
1.9.0-dev
2 changes: 2 additions & 0 deletions python/01_installable_script/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ form_python_exec_script_name;

form_python_use_linter;

form_python_use_type_checker;

form_python_pypi_deployment;

form_docs_integration;
Expand Down
4 changes: 4 additions & 0 deletions python/01_installable_script/source/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ ${{VAR_SCRIPT_TEST_ISOLATED_OPT}}
${{VAR_SCRIPT_TEST_LINT_HELP}}

[--no-virtualenv] Do not use a virtual environment for the tests.
${{VAR_SCRIPT_TEST_TYPE_CHECK_HELP}}

[-?|--help] Show this help message.
EOS
Expand All @@ -22,6 +23,7 @@ EOS
${{VAR_SCRIPT_BUILD_ISOLATED_ARGFLAG}}
${{VAR_SCRIPT_TEST_LINT_ARG}}
ARG_NO_VIRTUALENV=false;
${{VAR_SCRIPT_TEST_TYPE_CHECK_ARG}}
ARG_SHOW_HELP=false;

${{VAR_SCRIPT_BUILD_ISOLATED_ARGARRAY}}
Expand All @@ -35,6 +37,7 @@ ${{VAR_SCRIPT_TEST_LINT_ARG_PARSE}}
ARG_NO_VIRTUALENV=true;
shift
;;
${{VAR_SCRIPT_TEST_TYPE_CHECK_ARG_PARSE}}
-\?|--help)
ARG_SHOW_HELP=true;
shift
Expand Down Expand Up @@ -72,6 +75,7 @@ if [[ $ARG_NO_VIRTUALENV == false ]]; then
fi

${{VAR_SCRIPT_TEST_LINT_CODE}}
${{VAR_SCRIPT_TEST_TYPE_CHECK_CODE}}

logI "Running unit tests";
${_PYTHON_EXEC} -m unittest;
Expand Down
4 changes: 3 additions & 1 deletion python/02_library/init.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
# Copyright (C) 2024 Raven Computing
# Copyright (C) 2025 Raven Computing
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -35,6 +35,8 @@ form_python_package_name;

form_python_use_linter;

form_python_use_type_checker;

form_python_pypi_deployment;

form_docs_integration;
Expand Down
15 changes: 7 additions & 8 deletions python/02_library/source/package/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,18 @@ class Generator(ABC):
"""Dummy abstract base class.

Attributes:
val (any): The base value used by the Generator.
basis (str): The base value used by the Generator.
index (int): The index used by the Generator.
"""

def __init__(self, val):
self.val = val
self.index = 0
def __init__(self, basis: str):
self.basis: str = basis
self.index: int = 0

@abstractmethod
def generate(self):
"""Generates an object of the Generator.
def generate(self) -> str:
"""Generates a dummy string of this Generator.

Returns:
any: An object of the Generator
str: A dummy string of the Generator
"""
pass
7 changes: 1 addition & 6 deletions python/02_library/source/package/string_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@ def __init__(self):
super().__init__("${{VAR_PROJECT_SLOGAN_STRING}}")

def generate(self):
"""Generates a dummy String of this StringGenerator.

Returns:
A String object of this Generator
"""
index = self.index
self.index += 1
return self.val + " " + str(index)
return f"{self.basis} {index}"
4 changes: 4 additions & 0 deletions python/02_library/source/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ ${{VAR_SCRIPT_TEST_ISOLATED_OPT}}
${{VAR_SCRIPT_TEST_LINT_HELP}}

[--no-virtualenv] Do not use a virtual environment for the tests.
${{VAR_SCRIPT_TEST_TYPE_CHECK_HELP}}

[-?|--help] Show this help message.
EOS
Expand All @@ -23,6 +24,7 @@ EOS
${{VAR_SCRIPT_BUILD_ISOLATED_ARGFLAG}}
${{VAR_SCRIPT_TEST_LINT_ARG}}
ARG_NO_VIRTUALENV=false;
${{VAR_SCRIPT_TEST_TYPE_CHECK_ARG}}
ARG_SHOW_HELP=false;

${{VAR_SCRIPT_BUILD_ISOLATED_ARGARRAY}}
Expand All @@ -36,6 +38,7 @@ ${{VAR_SCRIPT_TEST_LINT_ARG_PARSE}}
ARG_NO_VIRTUALENV=true;
shift
;;
${{VAR_SCRIPT_TEST_TYPE_CHECK_ARG_PARSE}}
-\?|--help)
ARG_SHOW_HELP=true;
shift
Expand Down Expand Up @@ -73,6 +76,7 @@ if [[ $ARG_NO_VIRTUALENV == false ]]; then
fi

${{VAR_SCRIPT_TEST_LINT_CODE}}
${{VAR_SCRIPT_TEST_TYPE_CHECK_CODE}}

logI "Running unit tests";
${_PYTHON_EXEC} -m unittest;
Expand Down
4 changes: 3 additions & 1 deletion python/03_library_native_ctypes/init.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
# Copyright (C) 2024 Raven Computing
# Copyright (C) 2025 Raven Computing
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -36,6 +36,8 @@ form_python_package_name;

form_python_use_linter;

form_python_use_type_checker;

form_python_pypi_deployment;

form_docs_integration;
Expand Down
15 changes: 7 additions & 8 deletions python/03_library_native_ctypes/source/package/comparator.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,21 @@ class Comparator(ABC):
"""Dummy abstract base class.

Attributes:
val (any): The base value used by the Comparator.
ncalls (int): The number of calls to the compare() method of
val (str): The base value used by the Comparator.
ncalls (int): The number of calls to the `compare()` method of
the Comparator instance.
"""

def __init__(self, val):
self.val = val
self.ncalls = 0
def __init__(self, val: str):
self.val: str = val
self.ncalls: int = 0

@abstractmethod
def compare(self, val):
def compare(self, val: str) -> int:
"""Compares the specified object to the set object of this Comparator.

Args:
val (any): The object with which to compare.
val (str): The string with which to compare.

Returns:
int: An int indicating the result of the comparison.
Expand All @@ -32,4 +32,3 @@ def compare(self, val):
A positive int value if the set object is greater
than the specified object.
"""
pass
38 changes: 16 additions & 22 deletions python/03_library_native_ctypes/source/package/string_comparator.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
from ${{VAR_NAMESPACE_DECLARATION}}.comparator import Comparator


def _load_native_library():
def _load_native_library() -> ctypes.CDLL:
"""Loads the native library on which this module depends on.

Returns:
The ctypes CDLL native library object.
CDLL: The ctypes CDLL native library object.
"""
libname = "msvcrt" if sys.platform.lower().startswith("win") else "c"
lib = find_library(libname)
Expand All @@ -26,18 +26,18 @@ class StringComparator(Comparator):

This implementation only supports comparing strings containing
ASCII characters.
This class uses the native strcmp() C function for string comparisons.
This class uses the native `strcmp()` C function for string comparisons.
"""

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

def __init__(self, val="${{VAR_PROJECT_SLOGAN_STRING}}"):
"""Constructs a new StringComparator object for comparing
def __init__(self, val: str = "${{VAR_PROJECT_SLOGAN_STRING}}"):
"""Initializes a new StringComparator object for comparing
strings with the specified string object.

Args:
val: The str used for all comparisons. May not be None
val (str): The str used for all comparisons. May not be `None`.
"""
if val is None:
raise TypeError("Invalid argument. None is not allowed")
Expand All @@ -49,15 +49,15 @@ def compare(self, val):
of this StringComparator.

Args:
val: The string with which to compare, as a str.
val (str): The string with which to compare.

Returns:
An int indicating the result of the comparison.
Returns 0 (zero) if both strings are equal.
Returns a negative int value if the set string is less than
the specified string.
Returns a positive int value if the set string is greater
than the specified string.
int: An int indicating the result of the comparison.
Returns 0 (zero) if both strings are equal.
Returns a negative int value if the set string is less than
the specified string.
Returns a positive int value if the set string is greater
than the specified string.

Raises:
ValueError: If either the internal or specified string
Expand All @@ -70,14 +70,7 @@ def compare(self, val):
return self._compare_native_0(val)

def _compare_native_0(self, val):
"""Implementation of compare() method using native function calls.

Args:
val: The string with which to compare, as a str.

Returns:
An int indicating the result of the strcmp() comparison.
"""
"""Implementation of compare() method using native function calls."""
# Convert str to bytes objects
arg1 = str(self.val).encode(encoding="ascii")
arg2 = str(val).encode(encoding="ascii")
Expand All @@ -87,5 +80,6 @@ def _compare_native_0(self, val):
_cfunc.restype = ctypes.c_int
# Call C function and convert arguments to corresponding C types
res = _cfunc(ctypes.c_char_p(arg1), ctypes.c_char_p(arg2))
# As the return type is a c_int, we get a Python int and return it as is
# As the return type is a c_int, we get a Python int
# and return it as is
return res
4 changes: 4 additions & 0 deletions python/03_library_native_ctypes/source/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ ${{VAR_SCRIPT_TEST_ISOLATED_OPT}}
${{VAR_SCRIPT_TEST_LINT_HELP}}

[--no-virtualenv] Do not use a virtual environment for the tests.
${{VAR_SCRIPT_TEST_TYPE_CHECK_HELP}}

[-?|--help] Show this help message.
EOS
Expand All @@ -23,6 +24,7 @@ EOS
${{VAR_SCRIPT_BUILD_ISOLATED_ARGFLAG}}
ARG_LINT=false;
ARG_NO_VIRTUALENV=false;
${{VAR_SCRIPT_TEST_TYPE_CHECK_ARG}}
ARG_SHOW_HELP=false;

${{VAR_SCRIPT_BUILD_ISOLATED_ARGARRAY}}
Expand All @@ -36,6 +38,7 @@ ${{VAR_SCRIPT_TEST_LINT_ARG_PARSE}}
ARG_NO_VIRTUALENV=true;
shift
;;
${{VAR_SCRIPT_TEST_TYPE_CHECK_ARG_PARSE}}
-\?|--help)
ARG_SHOW_HELP=true;
shift
Expand Down Expand Up @@ -73,6 +76,7 @@ if [[ $ARG_NO_VIRTUALENV == false ]]; then
fi

${{VAR_SCRIPT_TEST_LINT_CODE}}
${{VAR_SCRIPT_TEST_TYPE_CHECK_CODE}}

logI "Running unit tests";
${_PYTHON_EXEC} -m unittest;
Expand Down
4 changes: 3 additions & 1 deletion python/04_library_native_cext/init.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
# Copyright (C) 2024 Raven Computing
# Copyright (C) 2025 Raven Computing
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -36,6 +36,8 @@ form_python_package_name;

form_python_use_linter;

form_python_use_type_checker;

form_python_pypi_deployment;

form_docs_integration;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"""Implementation of the Comparator ABC using strings."""

try:
import ${{VAR_NAMESPACE_DECLARATION}}._string_comparator as internal_impl
import ${{VAR_NAMESPACE_DECLARATION}}._string_comparator as internal_impl # pyright: ignore [reportMissingImports]
except ModuleNotFoundError:
raise ImportError("C extension module must be compiled") from None

Expand Down
4 changes: 4 additions & 0 deletions python/04_library_native_cext/source/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ ${{VAR_SCRIPT_TEST_ISOLATED_OPT}}
${{VAR_SCRIPT_TEST_LINT_HELP}}

[--no-virtualenv] Do not use a virtual environment for the tests.
${{VAR_SCRIPT_TEST_TYPE_CHECK_HELP}}

[-?|--help] Show this help message.
EOS
Expand All @@ -23,6 +24,7 @@ EOS
${{VAR_SCRIPT_BUILD_ISOLATED_ARGFLAG}}
${{VAR_SCRIPT_TEST_LINT_ARG}}
ARG_NO_VIRTUALENV=false;
${{VAR_SCRIPT_TEST_TYPE_CHECK_ARG}}
ARG_SHOW_HELP=false;

${{VAR_SCRIPT_BUILD_ISOLATED_ARGARRAY}}
Expand All @@ -36,6 +38,7 @@ ${{VAR_SCRIPT_TEST_LINT_ARG_PARSE}}
ARG_NO_VIRTUALENV=true;
shift
;;
${{VAR_SCRIPT_TEST_TYPE_CHECK_ARG_PARSE}}
-\?|--help)
ARG_SHOW_HELP=true;
shift
Expand Down Expand Up @@ -73,6 +76,7 @@ if [[ $ARG_NO_VIRTUALENV == false ]]; then
fi

${{VAR_SCRIPT_TEST_LINT_CODE}}
${{VAR_SCRIPT_TEST_TYPE_CHECK_CODE}}

logI "Building tests";
${_PYTHON_EXEC} setup.py build;
Expand Down
4 changes: 3 additions & 1 deletion python/05_library_native_cython/init.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
# Copyright (C) 2024 Raven Computing
# Copyright (C) 2025 Raven Computing
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -36,6 +36,8 @@ form_python_package_name;

form_python_use_linter;

form_python_use_type_checker;

form_python_pypi_deployment;

form_docs_integration;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"""Implementation of the Finder ABC using strings."""

try:
import ${{VAR_NAMESPACE_DECLARATION}}._index_finder as internal_impl
import ${{VAR_NAMESPACE_DECLARATION}}._index_finder as internal_impl # pyright: ignore [reportMissingImports]
except ModuleNotFoundError:
raise ImportError("C extension module must be compiled with Cython") from None

Expand Down
Loading