| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| Expand Up | @@ -530,12 +530,11 @@ class PythonLanguage(Language): | |
| checksum_line = "#/*[{dsl_name} end generated code: {arguments}]*/" | ||
|
|
||
|
|
||
| ParamGroup = Iterable["Parameter"] | ||
| ParamTuple = tuple["Parameter", ...] | ||
|
|
||
|
|
||
| def permute_left_option_groups( | ||
| l: Sequence[ParamGroup] | ||
| l: Sequence[Iterable[Parameter]] | ||
| ) -> Iterator[ParamTuple]: | ||
| """ | ||
| Given [(1,), (2,), (3,)], should yield: | ||
| Expand All | @@ -552,7 +551,7 @@ def permute_left_option_groups( | |
|
|
||
|
|
||
| def permute_right_option_groups( | ||
| l: Sequence[ParamGroup] | ||
| l: Sequence[Iterable[Parameter]] | ||
| ) -> Iterator[ParamTuple]: | ||
| """ | ||
| Given [(1,), (2,), (3,)], should yield: | ||
| Expand All | @@ -569,9 +568,9 @@ def permute_right_option_groups( | |
|
|
||
|
|
||
| def permute_optional_groups( | ||
| left: Sequence[ParamGroup], | ||
| required: ParamGroup, | ||
| right: Sequence[ParamGroup] | ||
| left: Sequence[Iterable[Parameter]], | ||
| required: Iterable[Parameter], | ||
| right: Sequence[Iterable[Parameter]] | ||
| ) -> tuple[ParamTuple, ...]: | ||
| """ | ||
| Generator function that computes the set of acceptable | ||
| Expand Down Expand Up | @@ -1374,7 +1373,11 @@ def group_to_variable_name(group: int) -> str: | |
| adjective = "left_" if group < 0 else "right_" | ||
| return "group_" + adjective + str(abs(group)) | ||
|
|
||
| def render_option_group_parsing(self, f, template_dict): | ||
| def render_option_group_parsing( | ||
| self, | ||
| f: Function, | ||
| template_dict: TemplateDict | ||
| ) -> None: | ||
| # positional only, grouped, optional arguments! | ||
| # can be optional on the left or right. | ||
| # here's an example: | ||
| Expand All | @@ -1398,11 +1401,11 @@ def render_option_group_parsing(self, f, template_dict): | |
| if isinstance(parameters[0].converter, self_converter): | ||
| del parameters[0] | ||
|
|
||
| group = None | ||
| group: list[Parameter] | None = None | ||
| left = [] | ||
| right = [] | ||
| required = [] | ||
| last = unspecified | ||
| required: list[Parameter] = [] | ||
| last: int | Literal[Sentinels.unspecified] = unspecified | ||
|
|
||
| for p in parameters: | ||
| group_id = p.group | ||
| Expand All | @@ -1415,6 +1418,7 @@ def render_option_group_parsing(self, f, template_dict): | |
| group = required | ||
| else: | ||
| right.append(group) | ||
| assert group is not None | ||
|
Comment thread
Copy link
Copy Markdown
Member
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. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityThis is fine for now, but I feel like there's probably a simpler way of writing the code immediately above that would be easier to understand and not require this assertion here for mypy
Sorry, something went wrong.
All reactions
Copy link
Copy Markdown
Contributor
Author
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. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityYes. We should accumulate these smells in the modernising-issue, so we don't forget. Or we can just grep for asserts.
Sorry, something went wrong.
AlexWaygood reacted with thumbs up emoji
All reactions
|
||
| group.append(p) | ||
|
|
||
| count_min = sys.maxsize | ||
| Expand All | @@ -1433,19 +1437,21 @@ def render_option_group_parsing(self, f, template_dict): | |
| continue | ||
|
|
||
| group_ids = {p.group for p in subset} # eliminate duplicates | ||
| d = {} | ||
| d: dict[str, str | int] = {} | ||
| d['count'] = count | ||
| d['name'] = f.name | ||
| d['format_units'] = "".join(p.converter.format_unit for p in subset) | ||
|
|
||
| parse_arguments = [] | ||
| parse_arguments: list[str] = [] | ||
| for p in subset: | ||
| p.converter.parse_argument(parse_arguments) | ||
| d['parse_arguments'] = ", ".join(parse_arguments) | ||
|
|
||
| group_ids.discard(0) | ||
| lines = [self.group_to_variable_name(g) + " = 1;" for g in group_ids] | ||
| lines = "\n".join(lines) | ||
| lines = "\n".join([ | ||
| self.group_to_variable_name(g) + " = 1;" | ||
| for g in group_ids | ||
| ]) | ||
|
Comment thread
erlend-aasland marked this conversation as resolved.
|
||
|
|
||
| s = """\ | ||
| case {count}: | ||
| Expand Down | ||
| Back | FazBrowse Home | New Git URL |
Uh oh!
There was an error while loading. Please reload this page.