-
-
Notifications
You must be signed in to change notification settings - Fork 1
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
Would it be possible to move _create_node_from_attributes to a public API? #3
Comments
I can make a PR for that. |
from copy import copy
def _to_dict(self):
return_dict = copy(self.__dict__)
return_dict.update({"type": self.__class__.__name__}) # or self.__class__.__name__.lower()
print(return_dict)
print(self.__dict__) Then @classmethod
def _from_dict(cls, dict):
node = cls()
dict.pop("type")
node.__dict__ = copy(dict)
return node After such changes, this is how nodes will be serialised and deserialised: from osm_easy_api import Api, Node
api = Api("https://www.openstreetmap.org")
node = api.elements.get(Node, 25733488)
dict = node._to_dict()
node_from_dict = Node._from_dict(dict)
print(node == node_from_dict) # True
print(id(node) == id(node_from_dict)) # False What do you think about this solution? |
I like it! Though (unless I am mistaken) (and ideally for an example |
Looking at my code again - to enable caching of changesets it seems to be useful also there... Though at least for now it seems I will get away with caching subset of data. |
Changing the key only in the dictionary you get is enough or is it better to consider changing it in the whole package code? |
key in dictionary that is produced, that is supplied, and property name really should match ideally also name used by API and in all package contextes would also match |
Done. Will be added soon as I resolve bug #4 . Renaming user_id, changeset_id, latitude and longitude should be discussed. I have added the ability to create discussions for this purpose. |
https://github.com/docentYT/osm_easy_api/blob/main/src/osm_easy_api/diff/diff_parser.py#LL79C2-L79C2
This would be useful tool for deserializing cached API responses.
As pickling cannot be safely used in this case, I am using
to save responses in a database.
The text was updated successfully, but these errors were encountered: