On Fri, Aug 07, 2020 at 12:22:28PM +1200, Greg Ewing wrote:
> On 7/08/20 2:47 am, David Mertz wrote:
> >The only difference is that in the usual existing style, 'a' doesn't
> >know that it's called "a". You and Steven have both, basically, said
> >"Why would you possibly care about that?"
>
> I
On Thu, Aug 06, 2020 at 04:01:47PM -, redrad...@gmail.com wrote:
> I see lots of use-cases for property decorators ...
We have had property decorators since version Python 2.2 which was 18
years ago. We know that there are many wonderful use-cases for things
like this. What you are not expl
On Thu, Aug 06, 2020 at 04:03:39PM -, redrad...@gmail.com wrote:
> No it is not possible to have something like this:
> ```python
> def function(cls):
> # Where is cls is Neuron class object
> pass
>
> class Neuron:
> activation = function(Neuron)
> ```
Correct. And it isn't pos
On 7/08/20 2:47 am, David Mertz wrote:
The only difference is that in the usual existing style, 'a' doesn't
know that it's called "a". You and Steven have both, basically, said
"Why would you possibly care about that?"
I've only really been thinking about attributes, but I suppose
it might be
No it is not possible to have something like this:
```python
def function(cls):
# Where is cls is Neuron class object
pass
class Neuron:
activation = function(Neuron)
```
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe
Also instead of making all class as dataclass, it would be possible to make
only some properties as instance properties:
```python
class Client:
bank = Bank()
@instance
name = Name()
print(f'Client.bank is {Client.bank}')
client = Client()
print(f'client.name is {client.name}')
```
_
Actually in example:
```python
class MyClass:
@my_property
name = arg
class MyClass:
def name(self):
...
def see_name(self):
...
```
I have done mistake ... of course it will not be like this ...
What I wanted to show that @my_property could add more complex behav
On Thu, Aug 6, 2020 at 2:52 AM Greg Ewing
wrote:
> On 6/08/20 6:42 am, David Mertz wrote:
> @unit("meter") a = 3 # a = unit("meter")("a", 3)
> @unit("foot") b = 4 # b = unit("foot")("b", 4)
>
> This still doesn't explain why the decorator syntax would be
> significantly better than j
Maybe I’m lacking context, but I don’t understand the proposal. Can you
explain the semantics and syntax you have in mind in more detail? How do
you get from the first example (@my_property etc.) to the second (def name,
def set_name)?
—Guido
On Thu, Aug 6, 2020 at 01:13 wrote:
> I think a prop
On Thu, 6 Aug 2020 at 00:14, Guido van Rossum wrote:
> On Wed, Aug 5, 2020 at 7:06 PM Steven D'Aprano
> wrote:
>
>> *blinks*
>>
>> When did this happen?
>>
>> I'm on Python-Ideas, Python-Dev, and I get announcements of new issues
>> on the bug tracker, and I don't recall ever seeing this feature
On Thu, Aug 06, 2020 at 08:11:50AM -, redrad...@gmail.com wrote:
> I think a property decorator can be useful, because you consider the simplest
> case with:
We already have `property`, which can be used as a decorator.
> ```python
> class MyClass:
> @my_property
> name = arg
> ```
On Thu, Aug 06, 2020 at 09:57:59AM +0200, Dominik Vilsmeier wrote:
> It seems that the OP has many such transformations and wants to use
> decorators to define a pipeline of transformations:
>
> @foo
> @bar
> @baz
> something = initial_value
>
> instead of
>
> something = fo
On Thu, Aug 6, 2020 at 6:16 PM wrote:
>
> I think a property decorator can be useful, because you consider the simplest
> case with:
> ```python
> class MyClass:
> @my_property
> name = arg
> ```
> but consider it can generate the following code:
> ```python
> class MyClass:
> def nam
I think a property decorator can be useful, because you consider the simplest
case with:
```python
class MyClass:
@my_property
name = arg
```
but consider it can generate the following code:
```python
class MyClass:
def name(self):
...
def see_name(self):
...
```
On 06.08.20 04:58, Guido van Rossum wrote:
On Wed, Aug 5, 2020 at 6:42 PM Steven D'Aprano mailto:st...@pearwood.info>> wrote:
On Wed, Aug 05, 2020 at 06:15:22PM -0700, Guido van Rossum wrote:
> On Wed, Aug 5, 2020 at 5:55 PM Steven D'Aprano
mailto:st...@pearwood.info>> wrote:
>
On 6/08/20 6:42 am, David Mertz wrote:
@unit("meter") a = 3 # a = unit("meter")("a", 3)
@unit("foot") b = 4 # b = unit("foot")("b", 4)
This still doesn't explain why the decorator syntax would be
significantly better than just calling the function directly.
meters = unit("meter")
feet = uni
On Wed, Aug 5, 2020 at 7:06 PM Steven D'Aprano wrote:
> *blinks*
>
> When did this happen?
>
> I'm on Python-Ideas, Python-Dev, and I get announcements of new issues
> on the bug tracker, and I don't recall ever seeing this feature
> discussed.
>
Oddly I barely recall it either, even though acco
On Wed, Aug 5, 2020 at 6:42 PM Steven D'Aprano wrote:
> On Wed, Aug 05, 2020 at 06:15:22PM -0700, Guido van Rossum wrote:
> > On Wed, Aug 5, 2020 at 5:55 PM Steven D'Aprano
> wrote:
>
> > > That require two different rules for decorators:
> > >
> > > @decorator over a `class name` or `def name`
On Thu, Aug 06, 2020 at 11:22:38AM +1000, Chris Angelico wrote:
> On Thu, Aug 6, 2020 at 11:11 AM Steven D'Aprano wrote:
> > [Dominik Vilsmeier]:
> > > > That should be possible by doing `fred = my_property(42)` and defining
> > > > `__set_name__` on the `my_property` class.
> >
> > Just because y
On Wed, Aug 05, 2020 at 06:15:22PM -0700, Guido van Rossum wrote:
> On Wed, Aug 5, 2020 at 5:55 PM Steven D'Aprano wrote:
> > That require two different rules for decorators:
> >
> > @decorator over a `class name` or `def name` statement:
> >
> > - execute the statement
> > - bind `name = decorat
On Thu, Aug 6, 2020 at 11:11 AM Steven D'Aprano wrote:
> [Dominik Vilsmeier]:
> > > That should be possible by doing `fred = my_property(42)` and defining
> > > `__set_name__` on the `my_property` class.
>
> Just because you define your own dunder method (which you shouldn't do,
> since dunders ar
On Wed, Aug 05, 2020 at 02:42:34PM -0400, David Mertz wrote:
> Here's something I think could be more useful (again, I'm +0 at best
> myself).
>
> >>> @unit("meter") a = 3 # a = unit("meter")("a", 3)
Why does the measurement "3 metres" need to know that it is bound to the
target name "a"?
If
On Wed, Aug 5, 2020 at 5:55 PM Steven D'Aprano wrote:
> On Wed, Aug 05, 2020 at 10:40:02PM +1200, Greg Ewing wrote:
>
> > A considerable number of moons ago, I suggested that
> >
> > @my_property
> > fred = 42
> >
> > should expand to
> >
> > fred = my_property("fred", 42)
>
>
> That
On Wed, Aug 05, 2020 at 03:35:15PM +0200, Marco Sulla wrote:
[Greg Ewing]
> > > A considerable number of moons ago, I suggested that
> > >
> > > @my_property
> > > fred = 42
> > >
> > > should expand to
> > >
> > > fred = my_property("fred", 42)
> > >
> > > The point being to give the
On Wed, Aug 05, 2020 at 10:40:02PM +1200, Greg Ewing wrote:
> A considerable number of moons ago, I suggested that
>
> @my_property
> fred = 42
>
> should expand to
>
> fred = my_property("fred", 42)
That require two different rules for decorators:
@decorator over a `class name`
On 6/08/20 1:35 am, Marco Sulla wrote:
I suppose that what Greg Ewing suggests is a way to define a sort of
custom simple statement.
you could write
@print
"Hello"
My suggestion was only for decorating assignments to a bare name,
so that wouldn't have been legal.
But that was long before __s
On Wed, Aug 5, 2020 at 3:40 PM Ethan Furman wrote:
> On 8/5/20 11:11 AM, Jonathan Goble wrote:
>
> > That's literally useless, because after running that there is nothing
> > stopping you from doing:
> >
> > >>> a = 10
> >
> > or even:
> >
> > >>> a = "python has no constants"
> >
> > And now a
On Wed, Aug 5, 2020 at 2:25 PM Jonathan Fine wrote:
> Real world examples where it would be useful are generally worth much more
> than invented examples.
>
I agree that @const is not really a useful "value decorator." I was just
picking up the example that occurred up-thread.
Here's something
On 8/5/20 11:11 AM, Jonathan Goble wrote:
That's literally useless, because after running that there is nothing
stopping you from doing:
>>> a = 10
or even:
>>> a = "python has no constants"
And now a has a value different from 5.
There is nothing even remotely resembling const-ness to t
All,
" And Python can't do that, and that's probably a good thing."
Johnathan, you are right, I emailed this list a year or so ago with a way
to overload assignment and lookup (i.e. what happens when you >>> a) and it
was discussed for a while, but ultimately there were reasons (that I
largely agr
If you really want something like this, you can today write:
>>> def wibble(fn):
... return ', '.join(fn())
>>> @wibble
... def ():
... return 'APPLES'
>>>
'A, P, P, L, E, S'
This allows you to use a decorator, if that's really what you want to do.
On Wed, Aug 5, 2020 at 2:03 PM Ricky Teachey wrote:
>
> And btw this works:
>
> >>> class const(int):
> ... def __new__(cls, name, val):
> ... obj = super().__new__(cls, val)
> ... obj.name = name
> ... return obj
> ... def about(self):
> ... print(self.nam
On 8/5/20 10:54 AM, David Mertz wrote:
I'm not advocating it, and I'm not the one that came up with it. But my
impression is that it is intended to mean:
a = const('a', 5)
This doesn't seem completely pointless:
class const():
... def __init__(self, name, val):
... self.name = name
...
On Wed, Aug 5, 2020 at 1:54 PM David Mertz wrote:
> On Wed, Aug 5, 2020 at 1:27 PM Ricky Teachey wrote:
>
>> On Wed, Aug 5, 2020 at 11:41 AM Marco Sulla
>> wrote:
>>
>>> On Wed, 5 Aug 2020 at 15:53, Ricky Teachey wrote:
>>> from mypython import *
>>> @const a = 5
>>>
>>
>> I'm probably dim bu
On Wed, Aug 5, 2020 at 1:27 PM Ricky Teachey wrote:
> On Wed, Aug 5, 2020 at 11:41 AM Marco Sulla
> wrote:
>
>> On Wed, 5 Aug 2020 at 15:53, Ricky Teachey wrote:
>> from mypython import *
>> @const a = 5
>>
>
> I'm probably dim but I have no idea what that is supposed to mean or do.
> Is this
On Wed, Aug 5, 2020 at 11:41 AM Marco Sulla
wrote:
> On Wed, 5 Aug 2020 at 15:53, Ricky Teachey wrote:
> > How about this?
> >
> > @print(sep="\n")
> > 1, 2, 3
>
> If you consider @print as a function decorator, it's quite a problem.
> But I was thinking mainly about a sort of "decorator" for th
On Wed, 5 Aug 2020 at 15:53, Ricky Teachey wrote:
> How about this?
>
> @print(sep="\n")
> 1, 2, 3
If you consider @print as a function decorator, it's quite a problem.
But I was thinking mainly about a sort of "decorator" for the parser
and/or the AST compiler.
This could allow you to have, for
On Wed, Aug 5, 2020 at 9:38 AM Marco Sulla
wrote:
> On Wed, 5 Aug 2020 at 13:29, Dominik Vilsmeier
> wrote:
> >
> > On 05.08.20 12:40, Greg Ewing wrote:
> > > A considerable number of moons ago, I suggested that
> > >
> > > @my_property
> > > fred = 42
> > >
> > > should expand to
> > >
On Wed, 5 Aug 2020 at 13:29, Dominik Vilsmeier wrote:
>
> On 05.08.20 12:40, Greg Ewing wrote:
> > A considerable number of moons ago, I suggested that
> >
> > @my_property
> > fred = 42
> >
> > should expand to
> >
> > fred = my_property("fred", 42)
> >
> > The point being to give the
On 05.08.20 12:40, Greg Ewing wrote:
On 5/08/20 9:13 pm, Serhiy Storchaka wrote:
the code can be written as
class Neuron:
activation = linear_activation(activation)
I do not see reasons to introduce special syntax for this very specific
code.
A considerable number of moons ago
On 5/08/20 9:13 pm, Serhiy Storchaka wrote:
the code can be written as
class Neuron:
activation = linear_activation(activation)
I do not see reasons to introduce special syntax for this very specific
code.
A considerable number of moons ago, I suggested that
@my_property
But I can do the same thing with class methods ... but anyway it was introduced
method decorators to simplify development and add extra power ...
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@
On Wed, Aug 5, 2020 at 8:01 PM wrote:
>
> It could work if we extend syntax like this:
> ```python
> class Neuron:
> activation # By default creates activation with None value\
Why not just "activation = None"?
> activation = linear_activation(activation)
> ```
> and then we could apply
It could work if we extend syntax like this:
```python
class Neuron:
activation # By default creates activation with None value
activation = linear_activation(activation)
```
and then we could apply as may decorators as needed:
```python
class Neuron:
activation # By default creates act
05.08.20 10:36, redrad...@gmail.com пише:
> Decorator will do the same thing as general decorator
So the code
class Neuron:
@linear_activation
activation
would be equivalent to the following code?
class Neuron:
activation
activation = linear_activation(ac
Also there is maybe some addition parameter like self:
```python
class Neuron:
@instance_property
activation
def __init__(self):
# automatically created
pass
...
def instance_property(name, property, self, *args):
# Create property on instance
```
Decorator will do the same thing as general decorator
For example it could be implemented like this:
```python
class linear_activation:
def __init(self, name, property):
...
def linear_activation(name, property):
...
```
___
Python-i
Disagree, because for example what if I want custom property with two or three
decorators ?
Like this:
```python
class Neuron:
@softmax_activation(weights=["w0", "w1"])
@linear_activation
activation
def __init__(self):
self.w0 = [...]
self.w1 = [...]
...
```
o
When one needs a custom property, the easy, readable, and that already
works way to create then
is just to create an instance of the their class and assign the instance to
the desired
class attribute. All the class have to do is to have the methods that
identify it as a descriptor: "__get__" and "_
On Tue, Aug 4, 2020 at 6:09 PM wrote:
>
> Hi all,
>
> Seems like this topic was previously raised, but what if we add possibility
> to decorate non function properties in class:
>
> ```python
> class Neuron:
> @linear_activation
> activation
> ```
What would that decoration do, exactly?
50 matches
Mail list logo