Title: Update model.py by ren-oz · Pull Request #13 · CarletonCognitiveModelingLab/python_actr · GitHub
Open Graph Title: Update model.py by ren-oz · Pull Request #13 · CarletonCognitiveModelingLab/python_actr
X Title: Update model.py by ren-oz · Pull Request #13 · CarletonCognitiveModelingLab/python_actr
Description: Cleaned up (deleted) old comments, made code PEP-8 compliant. Updated Python 2 string formatting to Python 3 f-strings. Fixed bug related to initializing children -- does not work as expected. The issue can be recreated with the following code: from python_actr import ACTR, Model env = Model() env.a1 = ACTR() print(env.get_children()) # List is empty print(env._children) # Raises AttributeError: "'Model' object has no attribute '_children'." env.a2 = ACTR() print(env.get_children()) # List has only one value print(env._children) # No exception raised, but only a2 is in children! This is resolved by moving self.__dict__[key] = value to the end of the __setattr__ method in class Model. The problem occurs because (if I am correct) whenever a class attribute of type Model is set for the first time in a parent Model instance (e.g., an environment), the parent class instance is forced into a conversion method (self._ensure_converted). During this conversion process, all Model instances in the parent namespace are also converted via: for k, v in list(self.__dict__.items()): if k[0] != '_' and k != 'parent' and isinstance(v, Model): if not v.__converted: v.__convert(parent=self) This leads to the child instance having its parent attribute set, and thus the parent _children attribute does not get set due to if getattr(value, 'parent', None) is not None: pass Interestingly, commenting out the for k, v in list(self.__dict__.items()): [...] block doesn't seem to break anything (hasn't been extensively tested though) and also resolves the issue as the children conversion happens later on in __setaatr__ along with an explicit setting of the parent _children attribute. But this is a larger block of code and must have been put in for some reason, so I'm hesitant to commit its deletion in this pull request. Future changes to consider: Ultimately, the methods in this file have low cohesion and are responsible for a lot of unrelated work. Refactoring model.py to delegate single responsibilities to other methods is something to strongly consider as it would help make maintenance easier in the event of future bugs. It should also help in developing new subclasses with less pain and ideally favour extensibility. That said, this must be done with care as much is built on top of this module so the changes could snowball. I am happy to assist in this process with pull requests if the team deems it worthwhile.
Open Graph Description: Cleaned up (deleted) old comments, made code PEP-8 compliant. Updated Python 2 string formatting to Python 3 f-strings. Fixed bug related to initializing children -- does not work as expected. The ...
X Description: Cleaned up (deleted) old comments, made code PEP-8 compliant. Updated Python 2 string formatting to Python 3 f-strings. Fixed bug related to initializing children -- does not work as expected. The ...
Opengraph URL: https://github.com/CarletonCognitiveModelingLab/python_actr/pull/13
X: @github
Domain: patch-diff.githubusercontent.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:dceeef91-e608-c1d0-2ba4-90ceccd64db6 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | 87E6:18F774:01D6:02AF:69826E4A |
| html-safe-nonce | 5955c17247cd9ac5aabb5939aa4c01525117b685e9e2379e10fdbdff13ce8e76 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4N0U2OjE4Rjc3NDowMUQ2OjAyQUY6Njk4MjZFNEEiLCJ2aXNpdG9yX2lkIjoiODMyNzc5MDU2MDQ4NDE1OTA1MCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 8092c148569d0e073eb6a225b7660df5733380a3667f8f3d06a67d175a627376 |
| hovercard-subject-tag | pull_request:879410111 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/CarletonCognitiveModelingLab/python_actr/pull/13/files |
| twitter:image | https://avatars.githubusercontent.com/u/35468537?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/35468537?s=400&v=4 |
| og:image:alt | Cleaned up (deleted) old comments, made code PEP-8 compliant. Updated Python 2 string formatting to Python 3 f-strings. Fixed bug related to initializing children -- does not work as expected. The ... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | d8cbbf00e6212b4e561a1d6db613194a319d58a2967494f7cc81cf6da3fbb985 |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/CarletonCognitiveModelingLab/python_actr git https://github.com/CarletonCognitiveModelingLab/python_actr.git |
| octolytics-dimension-user_id | 6578142 |
| octolytics-dimension-user_login | CarletonCognitiveModelingLab |
| octolytics-dimension-repository_id | 432934233 |
| octolytics-dimension-repository_nwo | CarletonCognitiveModelingLab/python_actr |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 432934233 |
| octolytics-dimension-repository_network_root_nwo | CarletonCognitiveModelingLab/python_actr |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 15d777483e72943a892af4ab5c0bbdb20215e6f3 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width