{"html_url": "https://github.com/simonw/sqlite-utils/issues/191#issuecomment-718170295", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/191", "id": 718170295, "node_id": "MDEyOklzc3VlQ29tbWVudDcxODE3MDI5NQ==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2020-10-28T19:50:16Z", "updated_at": "2020-10-28T19:50:16Z", "author_association": "OWNER", "body": "I think I made a mistake when I designed the initial decorator. I should have had it work like this:\r\n\r\n```python\r\n@db.register_function()\r\ndef reverse_string(s):\r\n return \"\".join(reversed(list(s)))\r\n```\r\nAs this leaves open the option to add new parameters in the future.\r\n\r\nTo avoid breaking backwards compatibility I'll use the hack that detects the argument this time, but in the future I'll try to remember to always design decorators to be called like `@decorator()`.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 731740458, "label": "Idea: @db.register_function(deterministic=True)"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/sqlite-utils/issues/191#issuecomment-718168730", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/191", "id": 718168730, "node_id": "MDEyOklzc3VlQ29tbWVudDcxODE2ODczMA==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2020-10-28T19:47:20Z", "updated_at": "2020-10-28T19:47:20Z", "author_association": "OWNER", "body": "https://stackoverflow.com/a/3931903 looks useful:\r\n```python\r\ndef trace(*args):\r\n def _trace(func):\r\n def wrapper(*args, **kwargs):\r\n print enter_string\r\n func(*args, **kwargs)\r\n print exit_string\r\n return wrapper\r\n if len(args) == 1 and callable(args[0]):\r\n # No arguments, this is the decorator\r\n # Set default values for the arguments\r\n enter_string = 'entering'\r\n exit_string = 'exiting'\r\n return _trace(args[0])\r\n else:\r\n # This is just returning the decorator\r\n enter_string, exit_string = args\r\n return _trace\r\n```\r\nCan improve that code with `functools.wraps`.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 731740458, "label": "Idea: @db.register_function(deterministic=True)"}, "performed_via_github_app": null}