Skip to content

Commit d801576

Browse files
committed
MNT: Fix mypy errors
1 parent 7cf9888 commit d801576

File tree

3 files changed

+25
-20
lines changed

3 files changed

+25
-20
lines changed

pdoc/__init__.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ def _pep224_docstrings(doc_obj: Union['Module', 'Class'], *,
267267
# Maybe raise exceptions with appropriate message
268268
# before using cleaned doc_obj.source
269269
_ = inspect.findsource(doc_obj.obj)
270-
tree = ast.parse(doc_obj.source) # type: ignore
270+
tree = ast.parse(doc_obj.source)
271271
except (OSError, TypeError, SyntaxError) as exc:
272272
# Don't emit a warning for builtins that don't have source available
273273
is_builtin = getattr(doc_obj.obj, '__module__', None) == 'builtins'
@@ -345,7 +345,7 @@ def get_name(assign_node):
345345
def get_indent(line):
346346
return len(line) - len(line.lstrip())
347347

348-
source_lines = doc_obj.source.splitlines() # type: ignore
348+
source_lines = doc_obj.source.splitlines()
349349
assign_line = source_lines[assign_node.lineno - 1]
350350
assign_indent = get_indent(assign_line)
351351
comment_lines = []
@@ -451,7 +451,7 @@ def _toposort(graph: Mapping[T, Set[T]]) -> Generator[T, None, None]:
451451
assert not graph, f"A cyclic dependency exists amongst {graph!r}"
452452

453453

454-
def link_inheritance(context: Context = None):
454+
def link_inheritance(context: Optional[Context] = None):
455455
"""
456456
Link inheritance relationsships between `pdoc.Class` objects
457457
(and between their members) of all `pdoc.Module` objects that
@@ -491,7 +491,7 @@ class Doc:
491491
"""
492492
__slots__ = ('module', 'name', 'obj', 'docstring', 'inherits')
493493

494-
def __init__(self, name: str, module, obj, docstring: str = None):
494+
def __init__(self, name: str, module, obj, docstring: str = ''):
495495
"""
496496
Initializes a documentation object, where `name` is the public
497497
identifier name, `module` is a `pdoc.Module` object where raw
@@ -566,7 +566,7 @@ def qualname(self) -> str:
566566
return getattr(self.obj, '__qualname__', self.name)
567567

568568
@lru_cache()
569-
def url(self, relative_to: 'Module' = None, *, link_prefix: str = '',
569+
def url(self, relative_to: Optional['Module'] = None, *, link_prefix: str = '',
570570
top_ancestor: bool = False) -> str:
571571
"""
572572
Canonical relative URL (including page fragment) for this
@@ -624,8 +624,10 @@ class Module(Doc):
624624
__slots__ = ('supermodule', 'doc', '_context', '_is_inheritance_linked',
625625
'_skipped_submodules')
626626

627-
def __init__(self, module: Union[ModuleType, str], *, docfilter: Callable[[Doc], bool] = None,
628-
supermodule: 'Module' = None, context: Context = None,
627+
def __init__(self, module: Union[ModuleType, str], *,
628+
docfilter: Optional[Callable[[Doc], bool]] = None,
629+
supermodule: Optional['Module'] = None,
630+
context: Optional[Context] = None,
629631
skip_errors: bool = False):
630632
"""
631633
Creates a `Module` documentation object given the actual
@@ -1010,7 +1012,7 @@ class Class(Doc):
10101012
"""
10111013
__slots__ = ('doc', '_super_members')
10121014

1013-
def __init__(self, name: str, module: Module, obj, *, docstring: str = None):
1015+
def __init__(self, name: str, module: Module, obj, *, docstring: Optional[str] = None):
10141016
assert inspect.isclass(obj)
10151017

10161018
if docstring is None:
@@ -1317,7 +1319,7 @@ class Function(Doc):
13171319
"""
13181320
__slots__ = ('cls',)
13191321

1320-
def __init__(self, name: str, module: Module, obj, *, cls: Class = None):
1322+
def __init__(self, name: str, module: Module, obj, *, cls: Optional[Class] = None):
13211323
"""
13221324
Same as `pdoc.Doc`, except `obj` must be a
13231325
Python function object. The docstring is gathered automatically.
@@ -1419,7 +1421,8 @@ def return_annotation(self, *, link=None) -> str:
14191421
s = re.sub(r'[\w\.]+', partial(_linkify, link=link, module=self.module), s)
14201422
return s
14211423

1422-
def params(self, *, annotate: bool = False, link: Callable[[Doc], str] = None) -> List[str]:
1424+
def params(self, *, annotate: bool = False,
1425+
link: Optional[Callable[[Doc], str]] = None) -> List[str]:
14231426
"""
14241427
Returns a list where each element is a nicely formatted
14251428
parameter of this function. This includes argument lists,
@@ -1589,7 +1592,7 @@ class Variable(Doc):
15891592
__slots__ = ('cls', 'instance_var')
15901593

15911594
def __init__(self, name: str, module: Module, docstring, *,
1592-
obj=None, cls: Class = None, instance_var: bool = False):
1595+
obj=None, cls: Optional[Class] = None, instance_var: bool = False):
15931596
"""
15941597
Same as `pdoc.Doc`, except `cls` should be provided
15951598
as a `pdoc.Class` object when this is a class or instance

pdoc/html_helpers.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import traceback
1010
from contextlib import contextmanager
1111
from functools import partial, lru_cache
12-
from typing import Callable, Match
12+
from typing import Callable, Match, Optional
1313
from warnings import warn
1414
import xml.etree.ElementTree as etree
1515

@@ -408,8 +408,9 @@ def handleMatch(self, m, data):
408408

409409

410410
def to_html(text: str, *,
411-
docformat: str = None,
412-
module: pdoc.Module = None, link: Callable[..., str] = None,
411+
docformat: Optional[str] = None,
412+
module: Optional[pdoc.Module] = None,
413+
link: Optional[Callable[..., str]] = None,
413414
latex_math: bool = False):
414415
"""
415416
Returns HTML of `text` interpreted as `docformat`. `__docformat__` is respected
@@ -433,8 +434,9 @@ def to_html(text: str, *,
433434

434435

435436
def to_markdown(text: str, *,
436-
docformat: str = None,
437-
module: pdoc.Module = None, link: Callable[..., str] = None):
437+
docformat: Optional[str] = None,
438+
module: Optional[pdoc.Module] = None,
439+
link: Optional[Callable[..., str]] = None):
438440
"""
439441
Returns `text`, assumed to be a docstring in `docformat`, converted to markdown.
440442
`__docformat__` is respected

pdoc/test/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,10 @@ def run(*args, **kwargs) -> int:
7070
params = list(filter(None, chain.from_iterable(params))) # type: ignore
7171
_args = cli.parser.parse_args([*params, *args]) # type: ignore
7272
try:
73-
returncode = cli.main(_args)
74-
return returncode or 0
73+
cli.main(_args)
74+
return 0
7575
except SystemExit as e:
76-
return e.code
76+
return bool(e.code)
7777

7878

7979
@contextmanager
@@ -953,7 +953,7 @@ def test_test_Function_params_python38_specific(self):
953953
self.assertEqual(func.params(), ['a', '/'])
954954

955955
def test_Function_return_annotation(self):
956-
def f() -> typing.List[typing.Union[str, pdoc.Doc]]: pass
956+
def f() -> typing.List[typing.Union[str, pdoc.Doc]]: return []
957957
func = pdoc.Function('f', DUMMY_PDOC_MODULE, f)
958958
self.assertEqual(func.return_annotation(), 'List[Union[str,\N{NBSP}pdoc.Doc]]')
959959

0 commit comments

Comments
 (0)