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

Add type hints (finally) #178

Merged
merged 12 commits into from
May 20, 2024
Merged

Add type hints (finally) #178

merged 12 commits into from
May 20, 2024

Conversation

econchick
Copy link
Owner

Initial pass at type hinting - I probably didn't do everything correctly, but mypy passes 😅

DEFAULT_FILENAME = "interrogate_badge"
COLORS = {

NumberType = int | float
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This causes CI to fail as int | float is actually executed at runtime (since it's not an annotation). In this case you still have to use the <3.10 syntax:

Suggested change
NumberType = int | float
NumberType = Union[int, float]

Or, better yet, don't introduce this type alias at all and simply use int | float everywhere (it's just one more character 😉)

Comment on lines 13 to 15
DocumentableFunc = ast.AsyncFunctionDef | ast.FunctionDef
DocumentableFuncOrClass = DocumentableFunc | ast.ClassDef
DocumentableNode = DocumentableFuncOrClass | ast.Module
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks so much for your review @trag1c - I am so behind on keeping up with the changes in typing 🙈

import configparser
import os
import pathlib
import re

from typing import Any, Sequence
Copy link

@trag1c trag1c Apr 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typing.Sequence and the like are deprecated as part of PEP 585, so it'd be better to use collections.abc.Sequence for annotations

Comment on lines 316 to 344
def main(
paths: Optional[List[str]],
verbose: int,
quiet: bool,
fail_under: Union[int, float],
exclude: Tuple[str],
ignore_init_method: bool,
ignore_init_module: bool,
ignore_magic: bool,
ignore_module: bool,
ignore_nested_classes: bool,
ignore_nested_functions: bool,
ignore_overloaded_functions: bool,
ignore_private: bool,
ignore_property_decorators: bool,
ignore_setters: bool,
ignore_semiprivate: bool,
ignore_regex: Optional[List[re.Pattern[str]]],
ext: Tuple[str],
whitelist_regex: Optional[List[re.Pattern[str]]],
style: str,
output: Optional[str],
color: bool,
omit_covered_files: bool,
generate_badge: Optional[str],
badge_format: Optional[str],
badge_style: Optional[str],
config: Optional[str],
) -> None:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious: does click require these to be <3.9 annotations?

@econchick econchick merged commit 5a22acb into master May 20, 2024
20 checks passed
@econchick econchick deleted the type-hints branch May 20, 2024 15:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants