[Python-Dev] PEP 549: Instance Properties (aka: module properties)
victor.stinner at gmail.com
Mon Sep 11 13:20:44 EDT 2017
2017-09-11 19:00 GMT+02:00 Chris Barker <chris.barker at noaa.gov>:
> I wish there were a property feature available almost very time I encounter
> a "get*" method in the stdlib (or any where):
> There are a heck of a lot in the os module:
> In : [s for s in dir(os) if s.startswith('get')]
This one is not a good example: it takes a parameter. You cannot
convert it to a property.
> And just yesterday I was getting annoyed by some in sysconfig:
> In : [s for s in dir(sysconfig) if s.startswith('get')]
When designing an API, when I have to choose between property and
function/method, I prefer function/method over a property when the
code is slow, especially at the first call.
I prefer to "warn" users than a call (like the first one which fills a
cache) can be slow.
Well, it's not a strong rule, sometimes I use a property even if the
first call has to fill a cache :-)
Here the sysconfig has to build an internal cache at the first call
... if I recall correctly.
More information about the Python-Dev