Skip to content
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

Add __repr__ for conditions.ConditionBase #3608

Closed
1 of 2 tasks
tibbe opened this issue Feb 28, 2023 · 2 comments
Closed
1 of 2 tasks

Add __repr__ for conditions.ConditionBase #3608

tibbe opened this issue Feb 28, 2023 · 2 comments
Assignees
Labels
feature-request This issue requests a feature.

Comments

@tibbe
Copy link

tibbe commented Feb 28, 2023

Describe the feature

Add __repr__ for ConditionBase and its subclasses.

Use Case

When writing unit tests using Stubber the error messages are hard to read because if one of the parameter is a ConditionBase we can't see what kind of expression we tried to match on. For example, if we have this in a test:

stubber.add_response('query', {
    'Items': [...]
}, {
    'FilterExpression': Attr('Type').eq('X') & Attr('Type').eq('Y'),
})

A failure will say something like "FilterExpression expected conditions.And, got conditions.And" because Python's default __repr__ only outputs the class name and not the fields so Attr('Type').eq('X') & Attr('Type').eq('Y') and Attr('Type').eq('X') & Attr('Type').eq('Z') pretty-prints exactly the same.

Proposed Solution

Add __repr__ implementations to the classes derived from

class ConditionBase:

The string should contain the operator name recursively print the operands. I don't particularly care if it looks like "And(Attr('Type').eq('X'), Attr('Type').eq('Y'))" or something prettier like "Type = X AND Type = Y".

Maybe it can be done using the existing get_expression().

Other Information

No response

Acknowledgements

  • I may be able to implement this feature request
  • This feature might incur a breaking change

SDK version used

1.26.81

Environment details (OS name and version, etc.)

Mac/Linux

@tibbe tibbe added feature-request This issue requests a feature. needs-triage This issue or PR still needs to be triaged. labels Feb 28, 2023
@tim-finnigan tim-finnigan self-assigned this Mar 6, 2023
@tim-finnigan
Copy link
Contributor

Hello and thanks for the feature request. Similar issues have been opened in the past, for example: #3259. The author of that issue also created a PR (#3254) and the initial feedback there was that the logging could be improved using __repr__. However there is now a feature freeze on updates to boto3 resources (see: https://boto3.amazonaws.com/v1/documentation/api/latest/guide/resources.html). For that reason I don't think this will get prioritized.

@tim-finnigan tim-finnigan removed the needs-triage This issue or PR still needs to be triaged. label Mar 6, 2023
@tibbe
Copy link
Author

tibbe commented Mar 7, 2023

Just a small note that this isn't only for boto3 resources. It affects any code that uses e.g. Key and Attr, including boto3 clients.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request This issue requests a feature.
Projects
None yet
Development

No branches or pull requests

2 participants