From 6352d838c5bfad794076eb4792b6ae71aa03f6f3 Mon Sep 17 00:00:00 2001 From: Brandon Thomas Date: Thu, 30 Jun 2022 18:28:22 -0400 Subject: [PATCH] type checking config --- tts/pyproject.toml | 5 +++ tts/pyrightconfig.json | 39 +++++++++++++++++++ tts/setup.cfg | 7 ++++ tts/text/input_parsing/parser.py | 13 ++++--- tts/text/normalization/BaseNormalization.py | 2 +- .../normalization/EnglishNormalization.py | 2 +- .../normalization/SpanishNormalization.py | 2 +- 7 files changed, 62 insertions(+), 8 deletions(-) create mode 100644 tts/pyproject.toml create mode 100644 tts/pyrightconfig.json create mode 100644 tts/setup.cfg diff --git a/tts/pyproject.toml b/tts/pyproject.toml new file mode 100644 index 0000000..df6211e --- /dev/null +++ b/tts/pyproject.toml @@ -0,0 +1,5 @@ +# For pytest + +[build-system] +requires = ["setuptools>=42", "wheel"] +build-backend = "setuptools.build_meta" diff --git a/tts/pyrightconfig.json b/tts/pyrightconfig.json new file mode 100644 index 0000000..6e33b41 --- /dev/null +++ b/tts/pyrightconfig.json @@ -0,0 +1,39 @@ +{ + "include": [ + "text/" + ], + + "exclude": [ + ".git/", + "**/*test_*.py", + "**/node_modules", + "**/__pycache__", + "NeMo/", + "hifi-gan/", + "hifigan/", + "nemo/", + "phonetics", + "python/", + "tacotron2/", + "temp/", + "waveglow/" + ], + + "ignore": [ + "tacotron2/", + "**/*test_*.py" + ], + + "defineConstant": { + }, + + "venvPath": "python/", + + "reportMissingImports": true, + "reportMissingTypeStubs": true, + + "pythonVersion": "3.6", + "pythonPlatform": "Linux", + + "typeCheckingMode": "strict" + } \ No newline at end of file diff --git a/tts/setup.cfg b/tts/setup.cfg new file mode 100644 index 0000000..b2dccda --- /dev/null +++ b/tts/setup.cfg @@ -0,0 +1,7 @@ +# For pytest + +[metadata] +name = tts + +[options] +packages = find: \ No newline at end of file diff --git a/tts/text/input_parsing/parser.py b/tts/text/input_parsing/parser.py index c9de079..9fad52d 100644 --- a/tts/text/input_parsing/parser.py +++ b/tts/text/input_parsing/parser.py @@ -5,25 +5,28 @@ treated independently. Inspired by and including code from original Tacotron2 by Keith Ito. """ +# pyright: strict + import re +from typing import List, Union # Regular expression matching text enclosed in curly braces: _curly_re = re.compile(r'(.*?)\{(.+?)\}(.*)') class ArpabetSequence: - def __init__(self, sequence): + def __init__(self, sequence: str): self.sequence = sequence class GraphemeSquence: - def __init__(self, sequence): + def __init__(self, sequence: str): self.sequence = sequence -def parse_grapheme_and_arpabet_sequence(input_text): +def parse_grapheme_and_arpabet_sequence(input_text: str) -> List[Union[ArpabetSequence, GraphemeSquence]]: """ - Parse a string into an array of ArpabetSequence and GraphemeSequence so that each + Parse a string into a list of ArpabetSequence and GraphemeSequence so that each subsequence can be treated independently. """ - sequence = [] + sequence : List[Union[ArpabetSequence, GraphemeSquence]] = [] # Check for curly braces and treat their contents as ARPAbet: while len(input_text): diff --git a/tts/text/normalization/BaseNormalization.py b/tts/text/normalization/BaseNormalization.py index 2dd7aea..81e3133 100644 --- a/tts/text/normalization/BaseNormalization.py +++ b/tts/text/normalization/BaseNormalization.py @@ -1,5 +1,5 @@ class BaseNormalization: - def normalize(self, raw_input_text): + def normalize(self, raw_input_text: str) -> str: return raw_input_text \ No newline at end of file diff --git a/tts/text/normalization/EnglishNormalization.py b/tts/text/normalization/EnglishNormalization.py index f4fcb87..c5d93b6 100644 --- a/tts/text/normalization/EnglishNormalization.py +++ b/tts/text/normalization/EnglishNormalization.py @@ -2,5 +2,5 @@ from text.normalization.BaseNormalization import BaseNormalization class EnglishNormalization(BaseNormalization): - def normalize(self, raw_input_text): + def normalize(self, raw_input_text: str) -> str: return raw_input_text diff --git a/tts/text/normalization/SpanishNormalization.py b/tts/text/normalization/SpanishNormalization.py index 009c8e4..a8dab9e 100644 --- a/tts/text/normalization/SpanishNormalization.py +++ b/tts/text/normalization/SpanishNormalization.py @@ -2,5 +2,5 @@ from text.normalization.BaseNormalization import BaseNormalization class SpanishNormalization(BaseNormalization): - def normalize(self, raw_input_text): + def normalize(self, raw_input_text: str) -> str: return raw_input_text