Skip to content

Commit

Permalink
ci: Add missing types
Browse files Browse the repository at this point in the history
  • Loading branch information
pawamoy committed Nov 13, 2021
1 parent 53767c0 commit ae236e1
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 35 deletions.
26 changes: 14 additions & 12 deletions src/griffe/dataclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def __init__(self, lineno: int | None, endlineno: int | None) -> None:
self.lineno: int | None = lineno
self.endlineno: int | None = endlineno

def as_dict(self, **kwargs) -> dict[str, Any]:
def as_dict(self, **kwargs: Any) -> dict[str, Any]:
"""Return this decorator's data as a dictionary.
Parameters:
Expand Down Expand Up @@ -162,6 +162,7 @@ def __init__(
self.kind: ParameterKind | None = kind
self.default: str | None = default

def as_dict(self, **kwargs: Any) -> dict[str, Any]:
"""Return this parameter's data as a dictionary.
Parameters:
Expand Down Expand Up @@ -376,7 +377,7 @@ def path(self) -> str:
return self.name
return ".".join((self.parent.path, self.name))

def as_dict(self, full: bool = False, **kwargs) -> dict[str, Any]:
def as_dict(self, full: bool = False, **kwargs: Any) -> dict[str, Any]:
"""Return this object's data as a dictionary.
Parameters:
Expand Down Expand Up @@ -419,7 +420,7 @@ class Module(Object):

kind = Kind.MODULE

def __init__(self, *args, filepath: Path, **kwargs) -> None:
def __init__(self, *args: Any, filepath: Path, **kwargs: Any) -> None:
"""Initialize the module.
Parameters:
Expand Down Expand Up @@ -492,7 +493,7 @@ def is_namespace_subpackage(self) -> bool:
or self.parent.is_namespace_subpackage # type: ignore # modules parents are always modules
)

def as_dict(self, **kwargs) -> dict[str, Any]: # type: ignore
def as_dict(self, **kwargs: Any) -> dict[str, Any]: # type: ignore
"""Return this module's data as a dictionary.
Parameters:
Expand All @@ -513,10 +514,10 @@ class Class(Object):

def __init__(
self,
*args,
*args: Any,
bases: list[str] | None = None,
decorators: list[Decorator] | None = None,
**kwargs,
**kwargs: Any,
) -> None:
"""Initialize the class.
Expand All @@ -530,7 +531,7 @@ def __init__(
self.bases = bases or []
self.decorators = decorators or []

def as_dict(self, **kwargs) -> dict[str, Any]: # type: ignore
def as_dict(self, **kwargs: Any) -> dict[str, Any]: # type: ignore
"""Return this class' data as a dictionary.
Parameters:
Expand All @@ -552,10 +553,11 @@ class Function(Object):

def __init__(
self,
*args: Any,
parameters: Parameters | None = None,
returns: str | None = None,
decorators: list[Decorator] | None = None,
**kwargs,
**kwargs: Any,
) -> None:
"""Initialize the function.
Expand All @@ -571,7 +573,7 @@ def __init__(
self.returns = returns
self.decorators = decorators or []

def as_dict(self, **kwargs) -> dict[str, Any]: # type: ignore
def as_dict(self, **kwargs: Any) -> dict[str, Any]: # type: ignore
"""Return this function's data as a dictionary.
Parameters:
Expand All @@ -594,10 +596,10 @@ class Attribute(Object):

def __init__(
self,
*args,
*args: Any,
value: str | None = None,
annotation: str | None = None,
**kwargs,
**kwargs: Any,
) -> None:
"""Initialize the function.
Expand All @@ -611,7 +613,7 @@ def __init__(
self.value: str | None = value
self.annotation: str | None = annotation

def as_dict(self, **kwargs) -> dict[str, Any]: # type: ignore
def as_dict(self, **kwargs: Any) -> dict[str, Any]: # type: ignore
"""Return this function's data as a dictionary.
Parameters:
Expand Down
8 changes: 4 additions & 4 deletions src/griffe/docstrings/dataclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def __init__(self, kind: DocstringSectionKind, value: Any, title: str | None = N
self.value: Any = value
self.title: str | None = title

def as_dict(self, **kwargs) -> dict[str, Any]:
def as_dict(self, **kwargs: Any) -> dict[str, Any]:
"""Return this section's data as a dictionary.
Parameters:
Expand Down Expand Up @@ -75,7 +75,7 @@ def __init__(self, *, kind: str, contents: str) -> None:
self.kind: str = kind
self.contents: str = contents

def as_dict(self, **kwargs) -> dict[str, Any]:
def as_dict(self, **kwargs: Any) -> dict[str, Any]:
"""Return this admonition's data as a dictionary.
Parameters:
Expand Down Expand Up @@ -108,7 +108,7 @@ def __init__(self, *, description: str, annotation: str | None = None) -> None:
self.description: str = description
self.annotation: str | None = annotation

def as_dict(self, **kwargs) -> dict[str, Any]:
def as_dict(self, **kwargs: Any) -> dict[str, Any]:
"""Return this element's data as a dictionary.
Parameters:
Expand Down Expand Up @@ -168,7 +168,7 @@ def __init__(self, name: str, *, description: str, annotation: str | None = None
self.name: str = name
self.value: str | None = value

def as_dict(self, **kwargs) -> dict[str, Any]:
def as_dict(self, **kwargs: Any) -> dict[str, Any]:
"""Return this element's data as a dictionary.
Parameters:
Expand Down
2 changes: 1 addition & 1 deletion src/griffe/docstrings/google.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ def _is_empty_line(line) -> bool:

def parse( # noqa: WPS231
docstring: Docstring,
**options,
**options: Any,
) -> list[DocstringSection]:
"""Parse a docstring.
Expand Down
2 changes: 1 addition & 1 deletion src/griffe/docstrings/numpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ def _read_examples_section(docstring: Docstring, offset: int) -> tuple[Docstring

def parse( # noqa: WPS231
docstring: Docstring,
**options,
**options: Any,
) -> list[DocstringSection]:
"""Parse a docstring.
Expand Down
4 changes: 2 additions & 2 deletions src/griffe/docstrings/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from __future__ import annotations

import enum
from typing import TYPE_CHECKING
from typing import TYPE_CHECKING, Any

from griffe.docstrings.dataclasses import DocstringSection
from griffe.docstrings.google import parse as parse_google
Expand All @@ -23,7 +23,7 @@ class Parser(enum.Enum):
}


def parse(docstring: Docstring, docstring_parser: Parser, **options) -> list[DocstringSection]:
def parse(docstring: Docstring, parser: Parser, **options: Any) -> list[DocstringSection]:
"""Parse the docstring.
Parameters:
Expand Down
11 changes: 2 additions & 9 deletions src/griffe/docstrings/rst.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from __future__ import annotations

from dataclasses import dataclass, field
from typing import TYPE_CHECKING, Any, Callable, FrozenSet, TypedDict
from typing import TYPE_CHECKING, Any, Callable, FrozenSet

from griffe.docstrings.dataclasses import (
DocstringAttribute,
Expand Down Expand Up @@ -54,13 +54,6 @@ def matches(self, line: str) -> bool:
return any(line.startswith(f":{name}") for name in self.names)


class AttributesDict(TypedDict):
"""Attribute details."""

docstring: str
annotation: str | None


@dataclass
class ParsedDirective:
"""Directive information that has been parsed from a docstring."""
Expand All @@ -86,7 +79,7 @@ class ParsedValues:
return_type: str | None = None


def parse(docstring: Docstring, **options) -> list[DocstringSection]:
def parse(docstring: Docstring, **options: Any) -> list[DocstringSection]:
"""Parse an RST-styled docstring.
Parameters:
Expand Down
12 changes: 6 additions & 6 deletions src/griffe/encoders.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ class Encoder(json.JSONEncoder):

def __init__(
self,
*args,
*args: Any,
full: bool = False,
docstring_parser: Parser = Parser.google,
docstring_options: dict[str, Any] = None,
**kwargs
docstring_parser: Parser | None = Parser.google,
docstring_options: dict[str, Any] | None = None,
**kwargs: Any
) -> None:
"""Initialize the encoder.
Expand All @@ -46,13 +46,13 @@ def __init__(
you don't need the full data as it can be infered again
using the base data. If you want to feed a non-Python
tool instead, dump the full data.
docstring_parser: The docstring parser to use.
docstring_parser: The docstring parser to use. By default, no parsing is done.
docstring_options: Additional docstring parsing options.
**kwargs: See [`json.JSONEncoder`][].
"""
super().__init__(*args, **kwargs)
self.full: bool = full
self.docstring_parser: Parser = docstring_parser
self.docstring_parser: Parser | None = docstring_parser
self.docstring_options: dict[str, Any] = docstring_options or {}

def default(self, obj: Any) -> Any: # noqa: WPS212
Expand Down

0 comments on commit ae236e1

Please sign in to comment.