freeze_support: type annotate

This commit is contained in:
Ran Benita 2020-06-25 15:15:08 +03:00
parent 8f8f472379
commit 97a11726e2
1 changed files with 14 additions and 5 deletions

View File

@ -2,9 +2,13 @@
Provides a function to report all internal modules for using freezing tools Provides a function to report all internal modules for using freezing tools
pytest pytest
""" """
import types
from typing import Iterator
from typing import List
from typing import Union
def freeze_includes(): def freeze_includes() -> List[str]:
""" """
Returns a list of module names used by pytest that should be Returns a list of module names used by pytest that should be
included by cx_freeze. included by cx_freeze.
@ -17,7 +21,9 @@ def freeze_includes():
return result return result
def _iter_all_modules(package, prefix=""): def _iter_all_modules(
package: Union[str, types.ModuleType], prefix: str = "",
) -> Iterator[str]:
""" """
Iterates over the names of all modules that can be found in the given Iterates over the names of all modules that can be found in the given
package, recursively. package, recursively.
@ -29,10 +35,13 @@ def _iter_all_modules(package, prefix=""):
import os import os
import pkgutil import pkgutil
if type(package) is not str: if isinstance(package, str):
path, prefix = package.__path__[0], package.__name__ + "."
else:
path = package path = package
else:
# Type ignored because typeshed doesn't define ModuleType.__path__
# (only defined on packages).
package_path = package.__path__ # type: ignore[attr-defined]
path, prefix = package_path[0], package.__name__ + "."
for _, name, is_package in pkgutil.iter_modules([path]): for _, name, is_package in pkgutil.iter_modules([path]):
if is_package: if is_package:
for m in _iter_all_modules(os.path.join(path, name), prefix=name + "."): for m in _iter_all_modules(os.path.join(path, name), prefix=name + "."):