Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a18c985

Browse filesBrowse files
authored
gh-113317, AC: Move warn() and fail() to libclinic.errors (#116770)
1 parent 3a25d9c commit a18c985
Copy full SHA for a18c985

File tree

Expand file treeCollapse file tree

3 files changed

+51
-47
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+51
-47
lines changed

‎Tools/clinic/clinic.py

Copy file name to clipboardExpand all lines: Tools/clinic/clinic.py
+1-47Lines changed: 1 addition & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,13 @@
4444
Protocol,
4545
TypeVar,
4646
cast,
47-
overload,
4847
)
4948

5049

5150
# Local imports.
5251
import libclinic
5352
import libclinic.cpp
54-
from libclinic import ClinicError
53+
from libclinic import ClinicError, fail, warn
5554

5655

5756
# TODO:
@@ -94,51 +93,6 @@ def __repr__(self) -> str:
9493
TemplateDict = dict[str, str]
9594

9695

97-
@overload
98-
def warn_or_fail(
99-
*args: object,
100-
fail: Literal[True],
101-
filename: str | None = None,
102-
line_number: int | None = None,
103-
) -> NoReturn: ...
104-
105-
@overload
106-
def warn_or_fail(
107-
*args: object,
108-
fail: Literal[False] = False,
109-
filename: str | None = None,
110-
line_number: int | None = None,
111-
) -> None: ...
112-
113-
def warn_or_fail(
114-
*args: object,
115-
fail: bool = False,
116-
filename: str | None = None,
117-
line_number: int | None = None,
118-
) -> None:
119-
joined = " ".join([str(a) for a in args])
120-
error = ClinicError(joined, filename=filename, lineno=line_number)
121-
if fail:
122-
raise error
123-
else:
124-
print(error.report(warn_only=True))
125-
126-
127-
def warn(
128-
*args: object,
129-
filename: str | None = None,
130-
line_number: int | None = None,
131-
) -> None:
132-
return warn_or_fail(*args, filename=filename, line_number=line_number, fail=False)
133-
134-
def fail(
135-
*args: object,
136-
filename: str | None = None,
137-
line_number: int | None = None,
138-
) -> NoReturn:
139-
warn_or_fail(*args, filename=filename, line_number=line_number, fail=True)
140-
141-
14296
class CRenderData:
14397
def __init__(self) -> None:
14498

‎Tools/clinic/libclinic/__init__.py

Copy file name to clipboardExpand all lines: Tools/clinic/libclinic/__init__.py
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
from .errors import (
44
ClinicError,
5+
warn,
6+
fail,
57
)
68
from .formatting import (
79
SIG_END_MARKER,
@@ -32,6 +34,8 @@
3234
__all__ = [
3335
# Error handling
3436
"ClinicError",
37+
"warn",
38+
"fail",
3539

3640
# Formatting helpers
3741
"SIG_END_MARKER",

‎Tools/clinic/libclinic/errors.py

Copy file name to clipboardExpand all lines: Tools/clinic/libclinic/errors.py
+46Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import dataclasses as dc
2+
from typing import Literal, NoReturn, overload
23

34

45
@dc.dataclass
@@ -24,3 +25,48 @@ def report(self, *, warn_only: bool = False) -> str:
2425

2526
class ParseError(ClinicError):
2627
pass
28+
29+
30+
@overload
31+
def warn_or_fail(
32+
*args: object,
33+
fail: Literal[True],
34+
filename: str | None = None,
35+
line_number: int | None = None,
36+
) -> NoReturn: ...
37+
38+
@overload
39+
def warn_or_fail(
40+
*args: object,
41+
fail: Literal[False] = False,
42+
filename: str | None = None,
43+
line_number: int | None = None,
44+
) -> None: ...
45+
46+
def warn_or_fail(
47+
*args: object,
48+
fail: bool = False,
49+
filename: str | None = None,
50+
line_number: int | None = None,
51+
) -> None:
52+
joined = " ".join([str(a) for a in args])
53+
error = ClinicError(joined, filename=filename, lineno=line_number)
54+
if fail:
55+
raise error
56+
else:
57+
print(error.report(warn_only=True))
58+
59+
60+
def warn(
61+
*args: object,
62+
filename: str | None = None,
63+
line_number: int | None = None,
64+
) -> None:
65+
return warn_or_fail(*args, filename=filename, line_number=line_number, fail=False)
66+
67+
def fail(
68+
*args: object,
69+
filename: str | None = None,
70+
line_number: int | None = None,
71+
) -> NoReturn:
72+
warn_or_fail(*args, filename=filename, line_number=line_number, fail=True)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.