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

Bugs in 0.9.2 #147

Closed
SmartAudioTools opened this issue Oct 24, 2020 · 6 comments
Closed

Bugs in 0.9.2 #147

SmartAudioTools opened this issue Oct 24, 2020 · 6 comments

Comments

@SmartAudioTools
Copy link

SmartAudioTools commented Oct 24, 2020

Hello !
Thanks for the new version !
I found to bugs in this 0.9.2 version with access to encoder attributs (there are maybe others, but i did'nt test all attributs access)

encoder indent attribut is not saved in encoder.indent :

>>> import rapidjson
>>> encoder = rapidjson.Encoder()
>>> encoder.indent
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'rapidjson.Encoder' object has no attribute 'indent'

encoder ensure_ascii is saved in sort_keys :

>>> import rapidjson
>>> encoder = rapidjson.Encoder(sort_keys = False, ensure_ascii = True)
>>> encoder.sort_keys
True
>>> encoder = rapidjson.Encoder(sort_keys = False, ensure_ascii = False)
>>> encoder.sort_keys
False
@lelit
Copy link
Contributor

lelit commented Oct 24, 2020

Thank you for the report, this went unnoticed for a long time!

lelit added a commit that referenced this issue Oct 24, 2020
This exposes the "indent_char" and "write_mode" attributes, and fixes the "sort_keys"
access that was wrongly referencing the "ensure_ascii" flag.

While on it, mentions Encoder and Decoder instance attributes in the documentation.

Fixes issue #147.
@lelit
Copy link
Contributor

lelit commented Oct 24, 2020

Fixed in v0.9.3!

@lelit lelit closed this as completed Oct 24, 2020
@SmartAudioTools
Copy link
Author

Hello!
Only the bug with encoder.sort_keys is fixed . There is still a problem accessing to encoder.indent :/

@lelit
Copy link
Contributor

lelit commented Oct 24, 2020

There's no .indent attribute: the indent parameter is overloaded, it may be either a str or an int, respectively exposed as .indent_char and .indent_count.

@SmartAudioTools
Copy link
Author

SmartAudioTools commented Oct 24, 2020

Ok ! :) I can do without, but there is no way to know if indent = None.

>>> import rapidjson
>>> encoder = rapidjson.Encoder(indent= 4)
>>> encoder.indent_char
' '
>>> encoder.indent_count
4
>>> encoder([1,2])
'[\n    1,\n    2\n]'
>>> encoder = rapidjson.Encoder(indent= None)
>>> encoder.indent_char
' '
>>> encoder.indent_count
4
>>> encoder([1,2])
'[1,2]'

@lelit
Copy link
Contributor

lelit commented Oct 24, 2020

You can inspect the write_mode attribute:

>>> import rapidjson
>>> e = rapidjson.Encoder()
>>> e.indent_char
' '
>>> e.indent_count
4
>>> e.write_mode
0
>>> e.write_mode == rapidjson.WM_COMPACT
True
>>> e = rapidjson.Encoder(indent=4)
>>> e.indent_char
' '
>>> e.indent_count
4
>>> e.write_mode
1
>>> e.write_mode == rapidjson.WM_PRETTY
True

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

No branches or pull requests

2 participants