-
Notifications
You must be signed in to change notification settings - Fork 668
feat: add asdict()
and to_json()
methods to Gitlab Objects
#1872
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
Conversation
88527fa
to
2d3dec6
Compare
as_dict()
method to the Gitlab Objectsas_dict()
method to the Gitlab Objects
2d3dec6
to
b0d55ee
Compare
as_dict()
method to the Gitlab Objectsasdict()
method to the Gitlab Objects
Codecov Report
@@ Coverage Diff @@
## main #1872 +/- ##
==========================================
- Coverage 95.41% 95.39% -0.02%
==========================================
Files 79 79
Lines 5166 5170 +4
==========================================
+ Hits 4929 4932 +3
- Misses 237 238 +1
Flags with carried forward coverage won't be shown. Click here to find out more.
|
b0d55ee
to
0975678
Compare
The more I compare this to What if we add a method like I think this would make the example in the issue quite pretty as well: with open('data.txt', 'w') as f:
f.write(src_prj.labels.list(all=True)[0].to_json()) |
Going back again, seems like the library supported both json and dict method for v3 with a custom encoder back in 2017. So maybe we could just re-add both: Lines 525 to 536 in 7011694
|
f2ed5e5
to
f229f7f
Compare
Sounds good to me. I've got |
f229f7f
to
03d9977
Compare
4a64a56
to
973e68f
Compare
asdict()
method to the Gitlab Objectsasdict()
and to_json()
methods to Gitlab Objects
ef5aed2
to
ec643b7
Compare
Very cool! |
ec643b7
to
a636938
Compare
Previously the `attributes` method would show the original values in a Gitlab Object even if they had been updated. Correct this so that the updated value will be returned. Also use copy.deepcopy() to ensure that modifying the dictionary returned can not also modify the object.
Add an `asdict()` method that returns a dictionary representation copy of the Gitlab Object. This is a copy and changes made to it will have no impact on the Gitlab Object. The `asdict()` method name was chosen as both the `dataclasses` and `attrs` libraries have an `asdict()` function which has the similar purpose of creating a dictionary represenation of an object. Also add a `to_json()` method that returns a JSON string representation of the object. Closes: #1116
a636938
to
08ac071
Compare
Add an
asdict()
method that returns a dictionary representation copyof the Gitlab Object. This is a copy and changes made to it will have
no impact on the Gitlab Object.
The
asdict()
method name was chosen as both thedataclasses
andattrs
libraries have anasdict()
function which has the similarpurpose of creating a dictionary represenation of an object.
Also add a
to_json()
method that returns a JSON stringrepresentation of the object.
Closes: #1116