cloudtools / awacs

Python library for AWS Access Policy Language creation
BSD 2-Clause "Simplified" License
396 stars 102 forks source link

Update to_json Indent Type Annotation #262

Open jdmoldenhauer opened 1 year ago

jdmoldenhauer commented 1 year ago

Updated the to_json methods indent type annotation on the AWSObject, and AWSHelperFn to allow for None. Added unit tests to ensure the string representation is as expected.

Sending an integer, or string to json.dumps indent parameter results in a pretty printed json string with new lines in it. Sending in None results in the most compact representation.

For example:

>>> import json
>>> json.dumps({'a': 'b'}, indent=0)
'{\n"a": "b"\n}'
>>> json.dumps({'a': 'b'}, indent=-1)
'{\n"a": "b"\n}'
>>> json.dumps({'a': 'b'}, indent='')
'{\n"a": "b"\n}'
>>> json.dumps({'a': 'b'}, indent=4)
'{\n    "a": "b"\n}'
>>> json.dumps({'a': 'b'}, indent=None)
'{"a": "b"}'

This change allows for the last option, sending in None to get the most compact representation.

I have no idea if this is a desired change, and I apologize if I should have opened an issue first. The change was so small though I figured why not just open a PR, and if this change isn't desired we can talk about it here. No worries if this isn't something desired for the code base.

Thank you!