Skip to content

Commit

Permalink
[typing] add missing type annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmylai committed Mar 19, 2020
1 parent cce934a commit 8e8aa06
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 11 deletions.
2 changes: 1 addition & 1 deletion libcst/_nodes/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def config_for_parsing(self) -> "PartialParserConfig":
default_newline=self.default_newline,
)

def get_docstring(self, clean=True) -> Optional[str]:
def get_docstring(self, clean: bool = True) -> Optional[str]:
"""
Returns a :func:`inspect.cleandoc` cleaned docstring if the docstring is available, ``None`` otherwise.
"""
Expand Down
8 changes: 4 additions & 4 deletions libcst/_nodes/statement.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import re
from abc import ABC, abstractmethod
from dataclasses import dataclass
from typing import Optional, Sequence, Union
from typing import Optional, Pattern, Sequence, Union

from libcst._add_slots import add_slots
from libcst._maybe_sentinel import MaybeSentinel
Expand Down Expand Up @@ -50,7 +50,7 @@
from libcst._visitors import CSTVisitorT


_INDENT_WHITESPACE_RE = re.compile(r"[ \f\t]+", re.UNICODE)
_INDENT_WHITESPACE_RE: Pattern[str] = re.compile(r"[ \f\t]+", re.UNICODE)


class BaseSuite(CSTNode, ABC):
Expand Down Expand Up @@ -1633,7 +1633,7 @@ def _codegen_impl(self, state: CodegenState) -> None:
state.add_token(":")
self.body._codegen(state)

def get_docstring(self, clean=True) -> Optional[str]:
def get_docstring(self, clean: bool = True) -> Optional[str]:
"""
When docstring is available, returns a :func:`inspect.cleandoc` cleaned docstring.
Otherwise, returns ``None``.
Expand Down Expand Up @@ -1782,7 +1782,7 @@ def _codegen_impl(self, state: CodegenState) -> None: # noqa: C901
state.add_token(":")
self.body._codegen(state)

def get_docstring(self, clean=True) -> Optional[str]:
def get_docstring(self, clean: bool = True) -> Optional[str]:
"""
Returns a :func:`inspect.cleandoc` cleaned docstring if the docstring is available, ``None`` otherwise.
"""
Expand Down
2 changes: 1 addition & 1 deletion libcst/tests/test_tabs.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ class ExpandTabsTest(UnitTest):
("\tsuffix", " suffix"),
]
)
def test_expand_tabs(self, input, output) -> None:
def test_expand_tabs(self, input: str, output: str) -> None:
self.assertEqual(expand_tabs(input), output)
4 changes: 2 additions & 2 deletions libcst/tests/test_type_enforce.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class MyExampleChildClass(MyExampleClass):
pass


class WeirdSubclassOfList(List):
class WeirdSubclassOfList(List[int]):
pass


Expand Down Expand Up @@ -130,7 +130,7 @@ class TypeEnforcementTest(UnitTest):
(MyExampleClassWithMetaclass(), Any),
]
)
def test_basic_pass(self, value, expected_type) -> None:
def test_basic_pass(self, value: object, expected_type: object) -> None:
self.assertTrue(
is_value_of_type(value, expected_type),
f"value {value!r} was supposed to be of type {expected_type!r}",
Expand Down
13 changes: 10 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,29 @@
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.

from __future__ import annotations

import importlib.util
from os import path
from typing import TYPE_CHECKING

import setuptools


if TYPE_CHECKING:
from importlib.machinery import ModuleSpec
from types import ModuleType

# Grab the readme so that our package stays in sync with github.
this_directory = path.abspath(path.dirname(__file__))
this_directory: str = path.abspath(path.dirname(__file__))
with open(path.join(this_directory, "README.rst"), encoding="utf-8") as f:
long_description = f.read()

# Grab the version constant so that libcst.tool stays in sync with this package.
spec = importlib.util.spec_from_file_location(
spec: ModuleSpec = importlib.util.spec_from_file_location(
"version", path.join(this_directory, "libcst/_version.py")
)
version = importlib.util.module_from_spec(spec)
version: ModuleType = importlib.util.module_from_spec(spec)
# pyre-ignore Pyre doesn't know about importlib entirely.
spec.loader.exec_module(version)
# pyre-ignore Pyre has no way of knowing that this constant exists.
Expand Down
1 change: 1 addition & 0 deletions stubs/hypothesmith.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# pyre-placeholder-stub
1 change: 1 addition & 0 deletions stubs/setuptools.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# pyre-placeholder-stub

0 comments on commit 8e8aa06

Please sign in to comment.