Skip to content

Conversation

@stefanvanburen
Copy link
Contributor

Noticed this method was missing while attempting to upgrade protovalidate-python to v0.4: https://github.com/bufbuild/protovalidate-python/actions/runs/16524843617/job/46735392706?pr=340#step:6:136.

Still blocked on a couple things (#113, google-re2 adding a Python 3.13 wheel), but figured I'd get this added in the meantime.

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Jul 25, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

@slott56 slott56 self-requested a review August 30, 2025 19:49
Copy link
Collaborator

@slott56 slott56 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delightful.

@slott56
Copy link
Collaborator

slott56 commented Aug 30, 2025

See #128 for a veiled feature request.

@stefanvanburen
Copy link
Contributor Author

@slott56 thanks for approving! gentle ping to get this merged since I cannot :)

return f"{self.__class__.__name__}({super().__repr__()})"

def contains(self, item: Value) -> BoolType:
return BoolType(cast(StringType, item) in self)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't passing tests (for me, or in CI) Perhaps we should do this instead?

Suggested change
return BoolType(cast(StringType, item) in self)
return BoolType(BytesType(item) in self)

Copy link
Collaborator

@hudlow hudlow Sep 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or maybe you meant for this to be cast(BytesType, item) but if so you'd want to do assert b_0.contains(b"byte") below...

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, did a bit more testing, and it seems like this is what's necessary to appease the type checker (and what's consistent with other examples of contains()):

Suggested change
return BoolType(cast(StringType, item) in self)
return BoolType(cast(bytes, item) in cast(bytes, self))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hm, I'm mostly basing this on the StringType impl; why do we need to cast to bytes instead?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stefanvanburen logically, a string is a sequence of Unicode code points and there is always an encoding choice to be made to represent it as bytes.

@hudlow hudlow merged commit 24ab9c4 into cloud-custodian:main Sep 2, 2025
8 checks passed
@stefanvanburen stefanvanburen deleted the svanburen/contains-bytestype branch September 2, 2025 20:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants