Skip to content

Commit 44ea96f

Browse files
committed
fixes
1 parent 25e7a8f commit 44ea96f

File tree

2 files changed

+40
-14
lines changed

2 files changed

+40
-14
lines changed

firebase-dataconnect/ci/notify_issue.py

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,58 +12,70 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
from __future__ import annotations
16+
1517
import argparse
1618
import dataclasses
1719
import logging
1820
import sys
1921
import typing
20-
from collections.abc import Sequence
22+
from typing import override
23+
24+
if typing.TYPE_CHECKING:
25+
from collections.abc import Sequence
26+
from typing import Never, TextIO
27+
28+
from _typeshed import SupportsWrite
2129

2230
type ExitCode = int
2331

24-
def main(args: Sequence[str], stdout: typing.TextIO, stderr: typing.TextIO) -> ExitCode:
32+
33+
def main(args: Sequence[str], stdout: TextIO, stderr: TextIO) -> ExitCode:
2534
try:
2635
parsed_args = parse_args(args[0], args[1:], stdout)
2736
except MyArgumentParser.Error as e:
2837
if e.exit_code != 0:
2938
print(f"ERROR: invalid command-line arguments: {e}", file=stderr)
30-
print(f"Run with --help for help", file=stderr)
39+
print("Run with --help for help", file=stderr)
3140
return e.exit_code
3241

42+
print(f"Successfully parsed arguments: {parsed_args!r}")
3343
return 0
3444

45+
3546
@dataclasses.dataclass(frozen=True)
3647
class GetIssueNumberCommand:
3748
github_ref: str
3849
github_event_name: str
3950
default_github_issue: int
4051

52+
4153
@dataclasses.dataclass(frozen=True)
4254
class ParsedArgs:
4355
log_level: int
4456
command: GetIssueNumberCommand
4557

46-
class MyArgumentParser(argparse.ArgumentParser):
4758

48-
def __init__(self, prog: str, stdout: typing.TextIO) -> None:
59+
class MyArgumentParser(argparse.ArgumentParser):
60+
def __init__(self, prog: str, stdout: SupportsWrite[str]) -> None:
4961
super().__init__(prog=prog, usage="%(prog)s <command> [options]")
5062
self.stdout = stdout
5163

52-
@typing.override
53-
def exit(self, status: int = 0, message: str | None = None) -> typing.Never:
64+
@override
65+
def exit(self, status: int = 0, message: str | None = None) -> Never:
5466
raise self.Error(exit_code=status, message=message)
5567

56-
@typing.override
57-
def error(self, message: str) -> typing.Never:
68+
@override
69+
def error(self, message: str) -> Never:
5870
self.exit(2, message)
5971

60-
@typing.override
61-
def print_usage(self, file: typing.TextIO | None = None) -> None:
72+
@override
73+
def print_usage(self, file: SupportsWrite[str] | None = None) -> None:
6274
file = file if file is not None else self.stdout
6375
super().print_usage(file)
6476

65-
@typing.override
66-
def print_help(self, file: typing.TextIO | None =None) -> None:
77+
@override
78+
def print_help(self, file: SupportsWrite[str] | None = None) -> None:
6779
file = file if file is not None else self.stdout
6880
super().print_help(file)
6981

@@ -73,9 +85,19 @@ def __init__(self, exit_code: ExitCode, message: str | None) -> None:
7385
self.exit_code = exit_code
7486

7587

76-
def parse_args(prog: str, args: Sequence[str], stdout: typing.TextIO) -> ExitCode:
88+
def parse_args(prog: str, args: Sequence[str], stdout: TextIO) -> ParsedArgs:
7789
arg_parser = MyArgumentParser(prog, stdout)
7890
parsed_args = arg_parser.parse_args(args)
91+
print(f"parsed_args: {parsed_args!r}")
92+
return ParsedArgs(
93+
log_level=logging.INFO,
94+
command=GetIssueNumberCommand(
95+
github_ref="sample_github_ref",
96+
github_event_name="sample_github_event_name",
97+
default_github_issue=123456,
98+
),
99+
)
100+
79101

80102
if __name__ == "__main__":
81103
try:

firebase-dataconnect/ci/pyproject.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ indent-width = 2
1414
select = ["ALL"]
1515
ignore = [
1616
"D100", # Missing docstring in public module
17+
"D101", # Missing docstring in public class
18+
"D103", # Missing docstring in public function
19+
"D106", # Missing docstring in public nested class
20+
"D107", # Missing docstring in `__init__`
1721
"D211", # no-blank-line-before-class
1822
"D212", # multi-line-summary-second-line
1923
"T201", # print` found

0 commit comments

Comments
 (0)