Skip to content
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

Enable mypy type checking #61

Open
delucchi-cmu opened this issue Mar 23, 2023 · 0 comments
Open

Enable mypy type checking #61

delucchi-cmu opened this issue Mar 23, 2023 · 0 comments
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@delucchi-cmu
Copy link
Contributor

While updating copier, I tried to enable type checking, but ran into some issues. I've disabled it for now, but the issues should be addressed so we can have type-checking going forward.

1 - Multiple conftest files

Initial module discovery is unhappy that we have multiple files named conftest.py

$ mypy ./src ./tests --ignore-missing-imports
tests/hipscat/io/conftest.py: error: Duplicate module named "conftest" (also at "tests/hipscat/catalog/conftest.py")
tests/hipscat/io/conftest.py: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#mapping-file-paths-to-modules for more info
tests/hipscat/io/conftest.py: note: Common resolutions include: a) using `--exclude` to avoid checking one of them, b) adding `__init__.py` somewhere, c) using `--explicit-package-bases` or adjusting MYPYPATH
Found 1 error in 1 file (errors prevented further checking)

Can address by

  • write fixtures in separate files for code organization, and import into a single conftest.py
  • combining all fixtures into single conftest.py
  • only checking the ./src directory

2 - Warnings:

$ mypy ./src --ignore-missing-imports
src/hipscat/io/paths.py:50: error: Argument 1 to "int" has incompatible type "Optional[int]"; expected "Union[str, bytes, bytearray, memoryview, array[Any], mmap, _CData, PickleBuffer, SupportsInt, SupportsIndex, SupportsTrunc]"  [arg-type]
src/hipscat/io/file_io/file_io.py:93: error: Incompatible default for argument "metadata_collector" (default has type "None", argument has type "List[Any]")  [assignment]
src/hipscat/io/file_io/file_io.py:93: note: PEP 484 prohibits implicit Optional. Accordingly, mypy has changed its default to no_implicit_optional=True
src/hipscat/io/file_io/file_io.py:93: note: Use https://github.com/hauntsaninja/no_implicit_optional to automatically upgrade your codebase
src/hipscat/catalog/pixel_node.py:55: error: Cannot determine type of "hp_order"  [has-type]
src/hipscat/catalog/pixel_node.py:62: error: Need type annotation for "children" (hint: "children: List[<type>] = ...")  [var-annotated]
src/hipscat/catalog/pixel_node.py:108: error: Need type annotation for "leaf_descendants" (hint: "leaf_descendants: List[<type>] = ...")  [var-annotated]
src/hipscat/pixel_math/pixel_margins.py:21: error: Need type annotation for "_suffixes" (hint: "_suffixes: Dict[<type>, <type>] = ...")  [var-annotated]
src/hipscat/io/write_metadata.py:136: error: Need type annotation for "hips_structure" (hint: "hips_structure: Dict[<type>, <type>] = ...")  [var-annotated]
src/hipscat/catalog/catalog_parameters.py:14: error: Incompatible default for argument "input_paths" (default has type "None", argument has type "List[str]")  [assignment]
src/hipscat/catalog/catalog_parameters.py:14: note: PEP 484 prohibits implicit Optional. Accordingly, mypy has changed its default to no_implicit_optional=True
src/hipscat/catalog/catalog_parameters.py:14: note: Use https://github.com/hauntsaninja/no_implicit_optional to automatically upgrade your codebase
src/hipscat/catalog/catalog.py:11: error: Incompatible default for argument "catalog_path" (default has type "None", argument has type "str")  [assignment]
src/hipscat/catalog/catalog.py:11: note: PEP 484 prohibits implicit Optional. Accordingly, mypy has changed its default to no_implicit_optional=True
src/hipscat/catalog/catalog.py:11: note: Use https://github.com/hauntsaninja/no_implicit_optional to automatically upgrade your codebase
Found 9 errors in 7 files (checked 19 source files)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
Status: No status
Development

No branches or pull requests

1 participant