{"id":46791,"library":"weakrefmethod","title":"weakrefmethod","description":"A WeakMethod class for storing bound methods using weak references. Current version 1.0.3, infrequently updated.","status":"active","version":"1.0.3","language":"python","source_language":"en","source_url":"http://github.com/twang817/weakrefmethod","tags":["weakref","WeakMethod","bound methods","weak references"],"install":[{"cmd":"pip install weakrefmethod","lang":"bash","label":"Install weakrefmethod"}],"dependencies":[],"imports":[{"note":"stdlib weakref does not export WeakMethod; only weakrefmethod provides it.","wrong":"from weakref import WeakMethod","symbol":"WeakMethod","correct":"from weakrefmethod import WeakMethod"}],"quickstart":{"code":"from weakrefmethod import WeakMethod\n\nclass MyClass:\n    def method(self):\n        return 'hello'\n\nobj = MyClass()\nwm = WeakMethod(obj.method)\nprint(wm() if wm() is not None else 'dead')","lang":"python","description":"Create a weak reference to a bound method; call returns the method result or None if the object is garbage collected."},"warnings":[{"fix":"Ensure the argument is a bound method: obj.method, not Class.method.","message":"WeakMethod only works on bound methods (instance.method). Passing an unbound method or a regular function will raise TypeError.","severity":"gotcha","affected_versions":"all"},{"fix":"Use wm() to call, not wm (which is a WeakMethod instance).","message":"The WeakMethod object is not callable directly in the sense of a proxy; to call the underlying method you must call wm() which returns the bound method or None.","severity":"gotcha","affected_versions":"all"},{"fix":"","message":"No deprecated features as of 1.0.3; API is stable.","severity":"deprecated","affected_versions":"all"}],"env_vars":null,"search_vec":"'1.0.3':14 'bound':7,19 'class':4 'current':12 'infrequ':15 'method':8,20 'refer':11,22 'store':6 'updat':16 'use':9 'version':13 'weak':10,21 'weakmethod':3,18 'weakref':17 'weakrefmethod':1","created_at":"2026-06-07T13:01:38.973825+00:00","updated_at":"2026-06-07T13:01:38.973825+00:00","problems":[{"fix":"Ensure you pass a bound method from a Python-defined class. Alternatively, use weakref.WeakMethod from Python 3.4+ stdlib if on Python 3.4+.","cause":"Passing an unbound function or a method from a C extension that does not support weak references.","error":"TypeError: cannot create weak reference to 'method' object"},{"fix":"Run 'pip install weakrefmethod' and ensure you are using the correct Python interpreter.","cause":"Package not installed or Python environment not correct.","error":"ImportError: No module named 'weakrefmethod'"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"http://github.com/twang817/weakrefmethod","github":"http://github.com/twang817/weakrefmethod","docs":null,"changelog":null,"pypi":null,"npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["devops"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-29","last_verified":"2026-06-29","next_check":"2026-07-29","install_tag":null}}