-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Avoid raising bare Exception #6
base: main
Are you sure you want to change the base?
Changes from all commits
092ace3
8c5e475
412a290
dfcfd3b
59e4332
3875bcb
f4e4014
cad0347
eb3f2a6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Copyright (c) Meta Platforms, Inc. and affiliates. | ||
# | ||
# This source code is licensed under the MIT license found in the | ||
# LICENSE file in the root directory of this source tree. | ||
|
||
|
||
class CSTLogicError(Exception): | ||
pass |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
|
||
from typing import Any, List, Optional, Sequence, Union | ||
|
||
from libcst._excep import CSTLogicError | ||
from libcst._exceptions import PartialParserSyntaxError | ||
from libcst._maybe_sentinel import MaybeSentinel | ||
from libcst._nodes.expression import ( | ||
|
@@ -121,7 +122,7 @@ def add_param( | |
# Example code: | ||
# def fn(*abc, *): ... | ||
# This should be unreachable, the grammar already disallows it. | ||
raise Exception( | ||
raise ValueError( | ||
"Cannot have multiple star ('*') markers in a single argument " | ||
+ "list." | ||
) | ||
|
@@ -136,7 +137,7 @@ def add_param( | |
# Example code: | ||
# def fn(foo, /, *, /, bar): ... | ||
# This should be unreachable, the grammar already disallows it. | ||
raise Exception( | ||
raise ValueError( | ||
"Cannot have multiple slash ('/') markers in a single argument " | ||
+ "list." | ||
) | ||
Comment on lines
+140
to
143
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. style: Consider using |
||
|
@@ -168,7 +169,7 @@ def add_param( | |
# Example code: | ||
# def fn(**kwargs, trailing=None) | ||
# This should be unreachable, the grammar already disallows it. | ||
raise Exception("Cannot have any arguments after a kwargs expansion.") | ||
raise ValueError("Cannot have any arguments after a kwargs expansion.") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. style: Consider using |
||
elif ( | ||
isinstance(param.star, str) and param.star == "*" and param.default is None | ||
): | ||
|
@@ -181,7 +182,7 @@ def add_param( | |
# Example code: | ||
# def fn(*first, *second): ... | ||
# This should be unreachable, the grammar already disallows it. | ||
raise Exception( | ||
raise ValueError( | ||
"Expected a keyword argument but found a starred positional " | ||
+ "argument expansion." | ||
) | ||
Comment on lines
+185
to
188
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. style: Consider using |
||
|
@@ -197,13 +198,13 @@ def add_param( | |
# Example code: | ||
# def fn(**first, **second) | ||
# This should be unreachable, the grammar already disallows it. | ||
raise Exception( | ||
raise ValueError( | ||
"Multiple starred keyword argument expansions are not allowed in a " | ||
+ "single argument list" | ||
) | ||
Comment on lines
+201
to
204
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. style: Consider using |
||
else: | ||
# The state machine should never end up here. | ||
raise Exception("Logic error!") | ||
raise CSTLogicError("Logic error!") | ||
|
||
return current_param | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: Consider using
ParserSyntaxError
instead ofValueError
for consistency with other parsing errors