{"action":"opened","issue":{"url":"https://api.github.com/repos/python-variants/variants/issues/24","repository_url":"https://api.github.com/repos/python-variants/variants","labels_url":"https://api.github.com/repos/python-variants/variants/issues/24/labels{/name}","comments_url":"https://api.github.com/repos/python-variants/variants/issues/24/comments","events_url":"https://api.github.com/repos/python-variants/variants/issues/24/events","html_url":"https://github.com/python-variants/variants/issues/24","id":302116511,"number":24,"title":"Inject the primary variant into the variant context?","user":{"login":"pganssle","id":1377457,"avatar_url":"https://avatars0.githubusercontent.com/u/1377457?v=4","gravatar_id":"","url":"https://api.github.com/users/pganssle","html_url":"https://github.com/pganssle","followers_url":"https://api.github.com/users/pganssle/followers","following_url":"https://api.github.com/users/pganssle/following{/other_user}","gists_url":"https://api.github.com/users/pganssle/gists{/gist_id}","starred_url":"https://api.github.com/users/pganssle/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pganssle/subscriptions","organizations_url":"https://api.github.com/users/pganssle/orgs","repos_url":"https://api.github.com/users/pganssle/repos","events_url":"https://api.github.com/users/pganssle/events{/privacy}","received_events_url":"https://api.github.com/users/pganssle/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-03-04T20:02:42Z","updated_at":"2018-03-04T20:02:42Z","closed_at":null,"author_association":"CONTRIBUTOR","body":"Might be useful to rename the current `variant` decorator to `staticvariant` and have `variant` bind the primary variant to the variant context, e.g.:\r\n\r\n```python\r\n@variants.primary\r\ndef func():\r\n    for i in range(25):\r\n        yield i\r\n\r\n@func.variant('as_list')\r\ndef func(pfunc):\r\n    return list(pfunc())\r\n```\r\n\r\nThis would be similar to the `cls` variable in `classmethod`. I'm not totally convinced it's useful, though, because `primary` will basically always just be `func`. There's no notion of instantiation or inheritance in functions. I think the main reason this would be useful is if you were planning on defining a variants hierarchy under one name, then you were to later assign that name, globally, to something else. Under the current version, variants referencing one another looks like this:\r\n\r\n```python\r\n@variants.primary\r\ndef divide(x, y):\r\n    return x / y\r\n\r\n@divide.variant('round')\r\ndef divide(x, y):\r\n    return round(divide(x, y))\r\n```\r\n\r\nNow imagine later you do:\r\n\r\n```python\r\ndivide_variants = divide\r\n\r\ndef divide(x, y):\r\n    divide_variants.round(x, y)\r\n```\r\n\r\nSince `divide` is not bound in the local scope of the `divide.round` variant, this will cause an infinite recursion. I think that this scenario is rare enough that for now users can just work around it, and maybe we can add a keyword argument to the `variant` decorator like `bind_primary=False` to enable this behavior. Still, I'm interested to hear if anyone can think of another reason why eagerly binding the primary variant would be useful in this scenario."}}
{"actor":{"display_login":"pganssle"}}