Hello,

On Fri, 18 Dec 2020 12:29:10 +1300
Greg Ewing <greg.ew...@canterbury.ac.nz> wrote:

> On 18/12/20 7:01 am, Paul Sokolovsky wrote:
> > Now, what if you have an object attribute which stores a callable
> > (no matter is it's bound method, a function, a class, or whatever)?
> > 
> > You will need to call it as "(obj.callable_ref)(arg, kw=val)".  
> 
> So, in strict mode, this:
> 
> import random
> n = random.choice([1,2,3])
> 
> would have to be written:
> 
> import random
> n = (random.choice)([1,2,3])
> 
> I would find that quite unpleasant.

Surely no, as we touched in the other email. That's how "quick
2-clause idea" differs from "full spec". First one presents the main
idea (being able to call methods based on just type namespace, not on
combined instance + type namespaces), whereas "full spec" would need to
consider "all other cases too".

So, it's already clear that mod.func() syntax will continue to work as
before. I don't foresee any problems with implementing that, do you?
Generally, the semantic changes discussed affect *only* user-defined
classes. Module objects, being builtin, aren't affected by new
semantic aspect, so I would expect zero changes at all would be
required to them in that regard. I'm basing on the architecture
of MicroPython-based VM/object model. Again, if you foresee any issues
with e.g. CPython, let me know, I can check that.

Beyond modules, there're other cases to consider. E.g., I said that an
instance attribute cannot shadow class'es *method* of the same name, you
can reasonably ask "what about other class fields?". And I'd say "needs
to be considered." I'd err on the side of banning any shadowing, but I
have to admit I did use a pattern like that more than once myself:

class Foo:
    option = "default" 


o1 = Foo()
print(o1.option)
o2 = Foo()
o2.option = "overriden"
Foo.option = "change default for all objs which didn't override it"


I personally wouldn't consider it end of the world to switch that to:

def get_option(self):
    if hasattr(self, "option"):
        return self.option 
    else:
        return self.__class__.option


But certainly requires more consideration and actual looking at the
good corpus of code to see how common is that.

> -- 
> Greg


-- 
Best regards,
 Paul                          mailto:pmis...@gmail.com
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/EJ3OIOBZAYJMI3ELIDNUQ4JMB5CVANZC/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to