from typing import Union
import pathlib


def name_modules(
    folder: Union[str, pathlib.Path],
    recursive: bool = False) -> list[str]:  
    """Returns list of python module names in 'folder'.
    
    Args:
        folder (Union[str, pathlib.Path]): path of folder to examine.
        recursive (bool): whether to include subfolders. Defaults to False.
        
    Returns
        list[str]: a list of python module names in 'folder'.
        
    """
    kwargs = {'folder': folder, 'suffix': '.py', 'recursive': recursive}
    paths = [p.stem for p in get_paths(**kwargs)] # type: ignore
    return [str(p) for p in paths]