[Python-ideas] Making the stdlib consistent again

Matthias welp boekewurm at gmail.com
Mon Aug 1 11:35:48 EDT 2016


On 1 August 2016 at 16:23, Chris Angelico <rosuav at gmail.com> wrote:
>On Mon, Aug 1, 2016 at 11:31 PM, Matthias welp <boekewurm at gmail.com> wrote:
>>> Now, suppose that the "external function" switches to use the name
>>> collections.DefaultDict. The above code will break, unless the two
>>> names defaultdict and DefaultDict are updated in parallel somehow to
>>> both point to MyMockClass. How do you propose we support that?
>>
>> This would be fixed with the 'aliasing variable names'-solution.
>>
>
> Not sure I follow; are you proposing that module attributes be able to
> say "I'm the same as that guy over there"? That could be done with
> descriptor protocol (think @property, where you can write a
> getter/setter that has the actual value in a differently-named public
> attribute), but normally, modules don't allow that, as you need to
> mess with the class not the instance. But there have been numerous
> proposals to make that easier for module authors, one way or another.
> That would make at least some things easier - the mocking example
> would work that way - but it'd still mean people have to grok more
> than one name when reading code, and it'd most likely mess with
> people's expectations in tracebacks etc (the function isn't called
> what I thought it was called). Or is that not what you mean by
> aliasing?

By aliasing I meant that the names of the fuctions/variables/
classes (variables) are all using the same value pointer/location.
That could mean that in debugging the name of the variable
is used as the name of the function. e.g. debugging get_int
results in 'in get_int(), line 5' but it's original getint results in
'in getint(), line 5'. Another option is 'in get_int(), line 5 of getint()'
if you want to retain the source location and name.

It could be descriptors for Python library implementations, but in C
it could be implemented as a pointer to <VariableContents> instead of
a struct containing <VariableContents>, or it could compile(?) to use
the same reference.

I am not familiar enough  with the structure of CPython and
how it's variable lookups are built, but these are just a few ideas.

-Matthias
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20160801/4e6ec9c3/attachment.html>


More information about the Python-ideas mailing list