-
Notifications
You must be signed in to change notification settings - Fork 8
Switch from mypy to ty for type checking #418
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
Draft
stefanvanburen
wants to merge
1
commit into
main
Choose a base branch
from
svanburen/mypy-ty
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -74,14 +74,14 @@ def __init__(self, msg: message.Message): | |
| continue | ||
| self[field.name] = field_to_cel(self.msg, field) | ||
|
|
||
| def __getitem__(self, name): | ||
| field = self.desc.fields_by_name[name] | ||
| if field.has_presence and not self.msg.HasField(name): | ||
| def __getitem__(self, key): | ||
| field = self.desc.fields_by_name[key] | ||
| if field.has_presence and not self.msg.HasField(key): | ||
| if in_has(): | ||
| raise KeyError() | ||
| else: | ||
| return _zero_value(field) | ||
| return super().__getitem__(name) | ||
| return super().__getitem__(key) | ||
|
|
||
|
|
||
| def _msg_to_cel(msg: message.Message) -> celtypes.Value: | ||
|
|
@@ -303,7 +303,7 @@ def sub_context(self) -> "RuleContext": | |
| class Rules: | ||
| """The rules associated with a single 'rules' message.""" | ||
|
|
||
| def validate(self, ctx: RuleContext, _: message.Message): | ||
| def validate(self, ctx: RuleContext, message: message.Message): # noqa: ARG002 | ||
| """Validate the message against the rules in this rule.""" | ||
| ctx.add(Violation(rule_id="unimplemented", message="Unimplemented")) | ||
|
|
||
|
|
@@ -415,8 +415,8 @@ def __init__(self, fields: list[descriptor.FieldDescriptor], *, required: bool): | |
| self._fields = fields | ||
| self._required = required | ||
|
|
||
| def validate(self, ctx: RuleContext, msg: message.Message): | ||
| num_set_fields = sum(1 for field in self._fields if not _is_empty_field(msg, field)) | ||
| def validate(self, ctx: RuleContext, message: message.Message): | ||
| num_set_fields = sum(1 for field in self._fields if not _is_empty_field(message, field)) | ||
| if num_set_fields > 1: | ||
| ctx.add( | ||
| Violation( | ||
|
|
@@ -561,8 +561,8 @@ def __init__( | |
| # For each set field in the message, look for the private rule | ||
| # extension. | ||
| for list_field, _ in rules.ListFields(): | ||
| if validate_pb2.predefined in list_field.GetOptions().Extensions: # type: ignore | ||
| for cel in list_field.GetOptions().Extensions[validate_pb2.predefined].cel: # type: ignore | ||
| if validate_pb2.predefined in list_field.GetOptions().Extensions: | ||
| for cel in list_field.GetOptions().Extensions[validate_pb2.predefined].cel: | ||
| self.add_rule( | ||
| env, | ||
| funcs, | ||
|
|
@@ -617,11 +617,13 @@ def validate(self, ctx: RuleContext, message: message.Message): | |
| sub_ctx.add_field_path_element(element) | ||
| ctx.add_errors(sub_ctx) | ||
|
|
||
| def validate_item(self, ctx: RuleContext, val: typing.Any, *, for_key: bool = False): | ||
| self._validate_value(ctx, val, for_key=for_key) | ||
| self._validate_cel(ctx, this_value=val, this_cel=_scalar_field_value_to_cel(val, self._field), for_key=for_key) | ||
| def validate_item(self, ctx: RuleContext, value: typing.Any, *, for_key: bool = False): | ||
| self._validate_value(ctx, value, for_key=for_key) | ||
| self._validate_cel( | ||
| ctx, this_value=value, this_cel=_scalar_field_value_to_cel(value, self._field), for_key=for_key | ||
| ) | ||
|
|
||
| def _validate_value(self, ctx: RuleContext, val: typing.Any, *, for_key: bool = False): | ||
| def _validate_value(self, ctx: RuleContext, value: typing.Any, *, for_key: bool = False): | ||
|
Comment on lines
+620
to
+626
Member
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. renamed to |
||
| pass | ||
|
|
||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
tywants the names of the arguments to match when over-riding from a superclass.