Created
February 11, 2019 12:07
-
-
Save haluzpav/628477bdeee8e33ed40e07c2b786c2dd to your computer and use it in GitHub Desktop.
Jsons bug - strip_properties removes also privates
This file contains 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
import dataclasses | |
import jsons | |
@dataclasses.dataclass | |
class C: | |
name: str | |
_private = 'underwear' | |
@property | |
def caps_name(self): | |
return self.name.upper() | |
c = C('grandma') | |
print(jsons.dump(c, strip_privates=False, strip_properties=False)) # default | |
# >>> {'_private': 'underwear', 'caps_name': 'GRANDMA', 'name': 'grandma'} | |
# OK | |
print(jsons.dump(c, strip_privates=False, strip_properties=True)) | |
# >>> {'name': 'grandma'} | |
# expected: {'_private': 'underwear', 'name': 'grandma'} | |
print(jsons.dump(c, strip_privates=True, strip_properties=False)) | |
# >>> {'caps_name': 'GRANDMA', 'name': 'grandma'} | |
# OK | |
print(jsons.dump(c, strip_privates=True, strip_properties=True)) | |
# >>> {'name': 'grandma'} | |
# OK |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment