{"id":16883892,"url":"https://github.com/zbraniecki/python_baseclasses","last_synced_at":"2025-03-20T05:16:37.051Z","repository":{"id":1263486,"uuid":"1202431","full_name":"zbraniecki/python_baseclasses","owner":"zbraniecki","description":"Python's Base Classes","archived":false,"fork":false,"pushed_at":"2010-12-28T07:56:16.000Z","size":100,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-25T06:41:27.463Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zbraniecki.png","metadata":{"files":{"readme":"README","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2010-12-28T07:26:10.000Z","updated_at":"2017-04-04T06:55:52.000Z","dependencies_parsed_at":"2022-08-16T12:50:17.879Z","dependency_job_id":null,"html_url":"https://github.com/zbraniecki/python_baseclasses","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zbraniecki%2Fpython_baseclasses","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zbraniecki%2Fpython_baseclasses/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zbraniecki%2Fpython_baseclasses/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zbraniecki%2Fpython_baseclasses/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zbraniecki","download_url":"https://codeload.github.com/zbraniecki/python_baseclasses/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244554126,"owners_count":20471173,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-13T16:14:38.106Z","updated_at":"2025-03-20T05:16:37.028Z","avatar_url":"https://github.com/zbraniecki.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"LazyDict is a subclass of a dict that can additionally store\nitems in a form of a stub that is expanded on the first call.\n\nSuch class may be useful in all cases where dictionary items\nare expensive to initialize and on average an application\nis using only some of the elements of the dictionary.\n\nOnce the item is requested for the first time,\nit is cached for later use.\n\nExample:\n\n    def resolver(self, key, *args, **kwargs):\n        print(\"resolving\")\n        table = kwargs.pop('table', None)\n        return QueryValue(table=table)\n\n    d = LazyDict({'a': 1})\n    d.set_stub('b', resolver, table='items')\n    \n    print(len(d))                    # 2\n    x = d['b']                       # resolving\n    x2 = d['b']                      #\n    print(isinstance(x2, QueryValue) # True\n\n\n\n\nAdditionally, LazyDict provides a method to define a resolver that\nwill be used for all stubs that do not provide its own.\n\nExample:\n\n    def resolver(self, key, *args, **kwargs):\n        print(\"resolving\")\n        table = kwargs.pop('table', None)\n        return QueryValue(table=table)\n\n    d = LazyDict({'a': 1})\n    d.set_resolver(resolver)\n    d.set_stub('b', None, table='items')\n    d.set_stub('c', None, table='people')\n    \n    print(len(d))                    # 2\n    x = d['b']                       # resolving\n    x2 = d['b']                      #\n    y = d['c']                       # resolving\n    y2 = d['c']                      #\n    print(isinstance(x2, QueryValue) # True\n    print(isinstance(y2, QueryValue) # True\n\n\nLazyDict provides exactly the same methods as dict and behaves very close to it.\nThe only difference is that in some cases it resolves its stubs.\n\nIn particular:\n\nLazyDict does not resolve any stubs when using:\n * __init__\n * __len__\n * __setitem__\n * __delitem__\n * __contains__\n * __iter__\n * clear\n * copy\n * keys\n * update\n * __repr__\n * set_stub\n * set_resolver\n\nLazyDict may resolve a single stub associated with the given key when using:\n * get\n * popitem\n * setdefault\n * pop\n\nLazyDict may resolve all stubs when using:\n * __cmp__\n * __eq__\n * __getitem__\n * items\n * values\n * resolve\n\n== Compatibility ==\n\nLazyDict is compatible with Python 2.6+ and Python 3.0+. Its test suite is\ncompatible with Python 2.7+ and Python 3.0+.\n\nMajority of code is based on Python's ABC, UserDict and OrderedDict classes.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzbraniecki%2Fpython_baseclasses","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzbraniecki%2Fpython_baseclasses","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzbraniecki%2Fpython_baseclasses/lists"}