[Python-ideas] Proposal for special name and qualname symbols
Franklin? Lee
leewangzhong+python at gmail.com
Fri Jun 10 15:31:20 EDT 2016
(API bikeshedding follows.)
In `@public` => `public(__LHS__, value)`, I'm a little bothered by
__LHS__ being the first argument. The first argument in a regular
decorator is the value.
Instead, how about this?
SEVEN = public(7, <some_keyword>=__LHS__)
... where the keyword is, for example, `name` or `target`. I thought
about `__name__`, too, but that sort of implies the name will be
attached to the object, which is true for `namedtuple` but not for
`public`.
Now the problem with that is, the assignment is now reversed.
(I'm not so bothered, somehow, that __LHS__ is magically substituted in.)
----
By the way, should these LHSs also have API?
- `indexable[index] = value`
- `obj.attrname = value`
- `first, *middle, last = value`
- ... and more, if we get unpacking generalizations like dict
unpacking and pattern-match.
(`obj` and `indexable` can be expressions, but that's not an issue.)
How should these be passed? Or should they just be disallowed?
Here's an ugly straw man proposal, using `decorator(name, value)`:
- `decorator((indexable.__setitem__, index), value)`
- `decorator((obj.__setattr__, attrname), value)`
- `decorator(['first', ..., 'middle', 'last'], value)`
Another (ugly) possibility, using kw params and `functools.partial`:
- `decorator(value, target=partial(indexable.__setitem__, index))`
- `decorator(value, target=partial(obj.__setattr__, attrname))`
- `decorator(value, name=['first', 'middle', 'last'], splat=1)`
Possible usecases:
???
On Fri, Jun 10, 2016 at 12:42 PM, Barry Warsaw <barry at python.org> wrote:
> On Jun 08, 2016, at 09:30 PM, Eric V. Smith wrote:
>
>>SEVEN = public(__LHS__, 7)
>>a_bar = public(__LHS__, Bar())
>
> Yes, if we had __LHS__ that's how I'd write it.
>
>>Although this might be a different version of public (or not!).
>
> It would be, because public() wouldn't then need to poke values into the
> module globals. It would just have to return the second argument and put the
> first argument in __all__. Tools like pyflakes would stop complaining too.
> Win!
>
> -Barry
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
More information about the Python-ideas
mailing list