)]}'
{"neutron/agent/linux/dhcp.py":[{"author":{"_account_id":7448,"name":"Carl Baldwin","email":"carl@ecbaldwin.net","username":"carl-baldwin"},"change_message_id":"305ae8db1b4fea59fb78814d189b8110e8d5d58f","unresolved":false,"context_lines":[{"line_number":89,"context_line":"                self[key] \u003d type(value)("},{"line_number":90,"context_line":"                    (DictModel(item) if ("},{"line_number":91,"context_line":"                        isinstance(item, dict)"},{"line_number":92,"context_line":"                        and not isinstance(item, DictModel)"},{"line_number":93,"context_line":"                    ) else item for item in value)"},{"line_number":94,"context_line":"                )"},{"line_number":95,"context_line":"            elif ("}],"source_content_type":"text/x-python","patch_set":3,"id":"AAAAU3%2F%2FjVU%3D","line":92,"updated":"2014-02-26 00:23:43.000000000","message":"This \"is dict and not is DictModel\" check is repeated twice and it makes this whole if statement considerably more difficult to read because of all of the various parentheses, newlines, and indentations.  What if you first defined this method:\n\ndef needs_upgrade(item):\n    return isinstance(item, dict) and not isinstance(item, DictModel)\n\nThen use it if the if statements.  I think that would improve readability.  Or, this might improve readability even more:\n\ndef upgrade(item):\n    if isinstance(item, dict) and not isinstance(item, DictModel):\n        return DictModel(item)\n    else:\n        return item\n\nSee comment below.","commit_id":"5d053808e3b9d5ecf7b80f5c2dc9e06e150354c4"},{"author":{"_account_id":8674,"name":"Yves-Gwenael Bourhis","email":"ygbourhis@gmail.com","username":"yves"},"change_message_id":"e24c63e68a99b6a5ada3afe5e95cb31050aed878","unresolved":false,"context_lines":[{"line_number":89,"context_line":"                self[key] \u003d type(value)("},{"line_number":90,"context_line":"                    (DictModel(item) if ("},{"line_number":91,"context_line":"                        isinstance(item, dict)"},{"line_number":92,"context_line":"                        and not isinstance(item, DictModel)"},{"line_number":93,"context_line":"                    ) else item for item in value)"},{"line_number":94,"context_line":"                )"},{"line_number":95,"context_line":"            elif ("}],"source_content_type":"text/x-python","patch_set":3,"id":"AAAAU3%2F%2Ffj4%3D","line":92,"in_reply_to":"AAAAU3%2F%2FjVU%3D","updated":"2014-02-26 10:03:12.000000000","message":"Done","commit_id":"5d053808e3b9d5ecf7b80f5c2dc9e06e150354c4"},{"author":{"_account_id":7448,"name":"Carl Baldwin","email":"carl@ecbaldwin.net","username":"carl-baldwin"},"change_message_id":"305ae8db1b4fea59fb78814d189b8110e8d5d58f","unresolved":false,"context_lines":[{"line_number":95,"context_line":"            elif ("},{"line_number":96,"context_line":"                isinstance(value, dict)"},{"line_number":97,"context_line":"                and not isinstance(value, DictModel)"},{"line_number":98,"context_line":"            ):"},{"line_number":99,"context_line":"                # Change dict instance values to DictModel instance values"},{"line_number":100,"context_line":"                self[key] \u003d DictModel(value)"},{"line_number":101,"context_line":""}],"source_content_type":"text/x-python","patch_set":3,"id":"AAAAU3%2F%2FjVI%3D","line":98,"updated":"2014-02-26 00:23:43.000000000","message":"The above comment would reduce this to a much simple elif on one line instead of four.","commit_id":"5d053808e3b9d5ecf7b80f5c2dc9e06e150354c4"},{"author":{"_account_id":8674,"name":"Yves-Gwenael Bourhis","email":"ygbourhis@gmail.com","username":"yves"},"change_message_id":"e24c63e68a99b6a5ada3afe5e95cb31050aed878","unresolved":false,"context_lines":[{"line_number":95,"context_line":"            elif ("},{"line_number":96,"context_line":"                isinstance(value, dict)"},{"line_number":97,"context_line":"                and not isinstance(value, DictModel)"},{"line_number":98,"context_line":"            ):"},{"line_number":99,"context_line":"                # Change dict instance values to DictModel instance values"},{"line_number":100,"context_line":"                self[key] \u003d DictModel(value)"},{"line_number":101,"context_line":""}],"source_content_type":"text/x-python","patch_set":3,"id":"AAAAU3%2F%2Ffjs%3D","line":98,"in_reply_to":"AAAAU3%2F%2FjVI%3D","updated":"2014-02-26 10:03:12.000000000","message":"Done","commit_id":"5d053808e3b9d5ecf7b80f5c2dc9e06e150354c4"},{"author":{"_account_id":7448,"name":"Carl Baldwin","email":"carl@ecbaldwin.net","username":"carl-baldwin"},"change_message_id":"305ae8db1b4fea59fb78814d189b8110e8d5d58f","unresolved":false,"context_lines":[{"line_number":97,"context_line":"                and not isinstance(value, DictModel)"},{"line_number":98,"context_line":"            ):"},{"line_number":99,"context_line":"                # Change dict instance values to DictModel instance values"},{"line_number":100,"context_line":"                self[key] \u003d DictModel(value)"},{"line_number":101,"context_line":""},{"line_number":102,"context_line":"    def __getattr__(self, name):"},{"line_number":103,"context_line":"        try:"}],"source_content_type":"text/x-python","patch_set":3,"id":"AAAAU3%2F%2FjTE%3D","line":100,"updated":"2014-02-26 00:23:43.000000000","message":"On second thought, the \"upgrade\" method above would not work well here because it would force setting self[key] \u003d upgrade(value) unconditionally.  I don\u0027t think that would be good.\n\nI still recommend the \"needs_upgrade\" method.","commit_id":"5d053808e3b9d5ecf7b80f5c2dc9e06e150354c4"},{"author":{"_account_id":8674,"name":"Yves-Gwenael Bourhis","email":"ygbourhis@gmail.com","username":"yves"},"change_message_id":"e24c63e68a99b6a5ada3afe5e95cb31050aed878","unresolved":false,"context_lines":[{"line_number":97,"context_line":"                and not isinstance(value, DictModel)"},{"line_number":98,"context_line":"            ):"},{"line_number":99,"context_line":"                # Change dict instance values to DictModel instance values"},{"line_number":100,"context_line":"                self[key] \u003d DictModel(value)"},{"line_number":101,"context_line":""},{"line_number":102,"context_line":"    def __getattr__(self, name):"},{"line_number":103,"context_line":"        try:"}],"source_content_type":"text/x-python","patch_set":3,"id":"AAAAU3%2F%2Ffjo%3D","line":100,"in_reply_to":"AAAAU3%2F%2FjTE%3D","updated":"2014-02-26 10:03:12.000000000","message":"Done","commit_id":"5d053808e3b9d5ecf7b80f5c2dc9e06e150354c4"},{"author":{"_account_id":8674,"name":"Yves-Gwenael Bourhis","email":"ygbourhis@gmail.com","username":"yves"},"change_message_id":"afc313688f00107bb75197b24e4269448bac8f89","unresolved":false,"context_lines":[{"line_number":106,"context_line":"        if cls._needs_upgrade(item):"},{"line_number":107,"context_line":"            # we return DictModel(item) and not cls(item) to avoid subclasses"},{"line_number":108,"context_line":"            # returning their own class. i.e.: NetModel would fail here if the"},{"line_number":109,"context_line":"            # dict instance doesn\u0027t have an \u0027id\u0027 key."},{"line_number":110,"context_line":"            return DictModel(item)"},{"line_number":111,"context_line":"        else:"},{"line_number":112,"context_line":"            return item"}],"source_content_type":"text/x-python","patch_set":4,"id":"AAAAU3%2F%2Ffg0%3D","line":109,"updated":"2014-02-26 10:08:29.000000000","message":"Note to reviewers:\nThis respects the old behaviour.\nIndeed, \u0027DictModel\u0027 was hard coded in the __init__ method.\nIt is possible to use cls \u003d self.__class__ in __init__ and classmethods for the _upgrade and _needs_upgrade method, but we would have to subclass the _upgrade and _needs_upgrade methods in NetModel to also check if the dict has an \u0027id\u0027 key, and to use their parent class if it is not the case.","commit_id":"1b0173f09d3e08f0515d6cbd63cbf4b5d539caff"},{"author":{"_account_id":2592,"name":"Mark McClain","email":"mark@mcclain.xyz","username":"markmcclain"},"change_message_id":"e5f16eb30b0f2eeec766908145979f758ca0af15","unresolved":false,"context_lines":[{"line_number":99,"context_line":"        # We do not check against cls in a classmethod here, for the reason"},{"line_number":100,"context_line":"        # explained in the _upgrade method bellow"},{"line_number":101,"context_line":"        return isinstance(item, dict) and not isinstance(item, DictModel)"},{"line_number":102,"context_line":""},{"line_number":103,"context_line":"    @classmethod"},{"line_number":104,"context_line":"    def _upgrade(cls, item):"},{"line_number":105,"context_line":"        \"\"\"Upgrade item if it needs to be upgraded.\"\"\""}],"source_content_type":"text/x-python","patch_set":7,"id":"1ae5cdf2_5791d997","line":102,"updated":"2014-06-03 11:24:00.000000000","message":"Why is this a classmethod?","commit_id":"e2ef34040e48fac235c196648604c192c4b61a6f"},{"author":{"_account_id":8674,"name":"Yves-Gwenael Bourhis","email":"ygbourhis@gmail.com","username":"yves"},"change_message_id":"cfd00535ff86fd90ab65a7f3bce0ce5c8f4421e5","unresolved":false,"context_lines":[{"line_number":99,"context_line":"        # We do not check against cls in a classmethod here, for the reason"},{"line_number":100,"context_line":"        # explained in the _upgrade method bellow"},{"line_number":101,"context_line":"        return isinstance(item, dict) and not isinstance(item, DictModel)"},{"line_number":102,"context_line":""},{"line_number":103,"context_line":"    @classmethod"},{"line_number":104,"context_line":"    def _upgrade(cls, item):"},{"line_number":105,"context_line":"        \"\"\"Upgrade item if it needs to be upgraded.\"\"\""}],"source_content_type":"text/x-python","patch_set":7,"id":"1ae5cdf2_b71cdd78","line":102,"in_reply_to":"1ae5cdf2_5791d997","updated":"2014-06-03 11:40:16.000000000","message":"Becasue it needs to call a static method of it\u0027s own class (_needs_upgrade) .\nSince _needs_upgrade does not require to be called on the instance, only a reference to the class is needed.","commit_id":"e2ef34040e48fac235c196648604c192c4b61a6f"},{"author":{"_account_id":2592,"name":"Mark McClain","email":"mark@mcclain.xyz","username":"markmcclain"},"change_message_id":"e5f16eb30b0f2eeec766908145979f758ca0af15","unresolved":false,"context_lines":[{"line_number":107,"context_line":"            # we return DictModel(item) and not cls(item) to avoid subclasses"},{"line_number":108,"context_line":"            # returning their own class. i.e.: NetModel would fail here if the"},{"line_number":109,"context_line":"            # dict instance doesn\u0027t have an \u0027id\u0027 key."},{"line_number":110,"context_line":"            return DictModel(item)"},{"line_number":111,"context_line":"        else:"},{"line_number":112,"context_line":"            return item"},{"line_number":113,"context_line":""}],"source_content_type":"text/x-python","patch_set":7,"id":"1ae5cdf2_778c1580","line":110,"updated":"2014-06-03 11:24:00.000000000","message":"Ok so the problem here is that a mix of staticmethod and classmethods are in use.  Why not just define these as inner methods of init?  Both methods are fairly self explanatory and the comments exists because of where they are defined.","commit_id":"e2ef34040e48fac235c196648604c192c4b61a6f"},{"author":{"_account_id":2592,"name":"Mark McClain","email":"mark@mcclain.xyz","username":"markmcclain"},"change_message_id":"4b64fcfedd31c803b845c093cc4149c6d67c5a38","unresolved":false,"context_lines":[{"line_number":107,"context_line":"            # we return DictModel(item) and not cls(item) to avoid subclasses"},{"line_number":108,"context_line":"            # returning their own class. i.e.: NetModel would fail here if the"},{"line_number":109,"context_line":"            # dict instance doesn\u0027t have an \u0027id\u0027 key."},{"line_number":110,"context_line":"            return DictModel(item)"},{"line_number":111,"context_line":"        else:"},{"line_number":112,"context_line":"            return item"},{"line_number":113,"context_line":""}],"source_content_type":"text/x-python","patch_set":7,"id":"AAAAXH%2F%2FRwA%3D","line":110,"updated":"2014-04-22 19:50:37.000000000","message":"return cls(item)","commit_id":"e2ef34040e48fac235c196648604c192c4b61a6f"},{"author":{"_account_id":8674,"name":"Yves-Gwenael Bourhis","email":"ygbourhis@gmail.com","username":"yves"},"change_message_id":"59653c6565f938ea3f34422829d513ac1c2d468e","unresolved":false,"context_lines":[{"line_number":107,"context_line":"            # we return DictModel(item) and not cls(item) to avoid subclasses"},{"line_number":108,"context_line":"            # returning their own class. i.e.: NetModel would fail here if the"},{"line_number":109,"context_line":"            # dict instance doesn\u0027t have an \u0027id\u0027 key."},{"line_number":110,"context_line":"            return DictModel(item)"},{"line_number":111,"context_line":"        else:"},{"line_number":112,"context_line":"            return item"},{"line_number":113,"context_line":""}],"source_content_type":"text/x-python","patch_set":7,"id":"1ae5cdf2_8bc97d28","line":110,"in_reply_to":"1ae5cdf2_778c1580","updated":"2014-06-03 12:05:54.000000000","message":"Done","commit_id":"e2ef34040e48fac235c196648604c192c4b61a6f"},{"author":{"_account_id":8674,"name":"Yves-Gwenael Bourhis","email":"ygbourhis@gmail.com","username":"yves"},"change_message_id":"888ff88eb76de0e0f921b156c611b9b9072144d4","unresolved":false,"context_lines":[{"line_number":107,"context_line":"            # we return DictModel(item) and not cls(item) to avoid subclasses"},{"line_number":108,"context_line":"            # returning their own class. i.e.: NetModel would fail here if the"},{"line_number":109,"context_line":"            # dict instance doesn\u0027t have an \u0027id\u0027 key."},{"line_number":110,"context_line":"            return DictModel(item)"},{"line_number":111,"context_line":"        else:"},{"line_number":112,"context_line":"            return item"},{"line_number":113,"context_line":""}],"source_content_type":"text/x-python","patch_set":7,"id":"AAAAXH%2F%2FNko%3D","line":110,"in_reply_to":"AAAAXH%2F%2FRwA%3D","updated":"2014-04-23 09:40:42.000000000","message":"@mark: as I explained in the comments above, cls(item) would fail with::\n\n    TypeError: __init__() takes exactly 3 arguments (2 given)\n\nif on NetModel instances we have a NetModel looking like this::\n\n    network \u003d dhcp.NetModel(True, {\u0027id\u0027: \u0027foo\u0027, \u0027a\u0027: [{\u0027b\u0027: \u0027c\u0027}]})\n\nIndeed, the NetModel constructor requires a \"use_namespaces\" parameter, and an \"id\" key in the dictionary.\n\nI can\u0027t use a static_method here because I need to call the _needs_upgrade method (which is static but \"on\" the class), but I do not need an instance method (so that\u0027s why it\u0027s a classmethod).\n\nHowever, for consistency, If I return cls(item) in this method, I should also change the _needs_upgrade method to a classmethod and check \"if not insinstance(item, cls)\" instead of \"if not isinstance(item, DictModel)\", and I should also change the last line of the __init__ method to \"self[key] \u003d self.__class__(value)\" (or use the _upgrade method but it adds overhead by an extra \"if\" test).\n\nHowever, if we are sure that NetModel is \"never\" in the form of  dhcp.NetModel(True, {\u0027id\u0027: \u0027foo\u0027, \u0027a\u0027: [{\u0027b\u0027: \u0027c\u0027}]}), I can perform all these changes.\n\nNOTE: I respected in this patch the old behavior where \"DictModel(value)\" was hard coded in the constructor instead of using \"self.__class__(value)\"\n\nThe major problem is that we can\u0027t guess by reading the DictModel and NetModel code what kind if dicts they will receive for their instantiation.\n\nIMHO we should change the unittests to a complex real-life structure instead of the very short dicts used here.\nThis current patch will help debugging by showing with a simple \"pprint\" in a pdb the structure a DictModel can have in real life, and the tests should be adapted in the near future to have real example of DictModel and NetModel in the unitests.\nThen we will change (or not) the instantiation behavior accordingly, and finally, when we know what we truly have, we will create a real object as you already mentioned before.\n\nSo wee will improve this \"step by step\".\nCurrently I fixed the python naming convention violation, and eased debugging.\nNext, we will have more representing unittests.\nThen we will adapt as you mention, or directly jump to the step where we use a real object (the debugging having helped show the structure we need).\n\nLet me know if anything was unclear.","commit_id":"e2ef34040e48fac235c196648604c192c4b61a6f"},{"author":{"_account_id":7787,"name":"Kevin Benton","email":"kevin@benton.pub","username":"blak111"},"change_message_id":"7535022ee3f9c6de7e04dbe91d7d1b205d6094ab","unresolved":false,"context_lines":[{"line_number":117,"context_line":"        self[name] \u003d value"},{"line_number":118,"context_line":""},{"line_number":119,"context_line":"    def __delattr__(self, name):"},{"line_number":120,"context_line":"        del self[name]"},{"line_number":121,"context_line":""},{"line_number":122,"context_line":""},{"line_number":123,"context_line":"class NetModel(DictModel):"}],"source_content_type":"text/x-python","patch_set":8,"id":"1ae5cdf2_ff28e087","line":120,"updated":"2014-06-04 02:43:12.000000000","message":"How are these last 3 methods different from a regular dict?","commit_id":"ffd9be07de550ec14721fa50ae0acc58f04df1b2"},{"author":{"_account_id":8674,"name":"Yves-Gwenael Bourhis","email":"ygbourhis@gmail.com","username":"yves"},"change_message_id":"f2e733bcd6664d14ec6b490a1419497f9538e9b4","unresolved":false,"context_lines":[{"line_number":117,"context_line":"        self[name] \u003d value"},{"line_number":118,"context_line":""},{"line_number":119,"context_line":"    def __delattr__(self, name):"},{"line_number":120,"context_line":"        del self[name]"},{"line_number":121,"context_line":""},{"line_number":122,"context_line":""},{"line_number":123,"context_line":"class NetModel(DictModel):"}],"source_content_type":"text/x-python","patch_set":8,"id":"1ae5cdf2_58d7254b","line":120,"in_reply_to":"1ae5cdf2_ff28e087","updated":"2014-06-04 08:09:20.000000000","message":"https://docs.python.org/2/reference/datamodel.html#customizing-attribute-access\na regular dict\u0027s __delattr__ would delete self.__dict__[name] and not slef[name]\n\nregular dicts handle \"keys\", not \"attributes\":\n\n    Python 2.7.4 (default, Sep 26 2013, 03:20:26) \n    [GCC 4.7.3] on linux2\n    Type \"help\", \"copyright\", \"credits\" or \"license\" for more information.\n    \u003e\u003e\u003e from neutron.agent.linux.dhcp import DictModel\n    \u003e\u003e\u003e dm \u003d DictModel({\u0027id\u0027: \u0027foo\u0027, \u0027a\u0027: [{\u0027b\u0027: \u0027c\u0027}]})\n    \u003e\u003e\u003e d \u003d {\u0027id\u0027: \u0027foo\u0027, \u0027a\u0027: [{\u0027b\u0027: \u0027c\u0027}]}\n    \u003e\u003e\u003e dm.a\n    [{\u0027b\u0027: \u0027c\u0027}]\n    \u003e\u003e\u003e d.a\n    Traceback (most recent call last):\n      File \"\u003cstdin\u003e\", line 1, in \u003cmodule\u003e\n    AttributeError: \u0027dict\u0027 object has no attribute \u0027a\u0027\n    \u003e\u003e\u003e d[\u0027a\u0027]\n    [{\u0027b\u0027: \u0027c\u0027}]\n    \u003e\u003e\u003e del dm.a\n    \u003e\u003e\u003e del d.a\n    Traceback (most recent call last):\n      File \"\u003cstdin\u003e\", line 1, in \u003cmodule\u003e\n    AttributeError: \u0027dict\u0027 object has no attribute \u0027a\u0027\n    \u003e\u003e\u003e del d[\u0027a\u0027]\n    \u003e\u003e\u003e dm\n    {\u0027id\u0027: \u0027foo\u0027}\n    \u003e\u003e\u003e d\n    {\u0027id\u0027: \u0027foo\u0027}\n    \u003e\u003e\u003e\n\nordinary dicts implement this:\nhttps://docs.python.org/2/reference/datamodel.html#emulating-container-types","commit_id":"ffd9be07de550ec14721fa50ae0acc58f04df1b2"}]}
