<div dir="ltr"><div>On 1 August 2016 at 16:23, Chris Angelico <<a href="mailto:rosuav@gmail.com">rosuav@gmail.com</a>> wrote:<br>>On Mon, Aug 1, 2016 at 11:31 PM, Matthias welp <<a href="mailto:boekewurm@gmail.com">boekewurm@gmail.com</a>> wrote:<br>>>> Now, suppose that the "external function" switches to use the name<br>>>> collections.DefaultDict. The above code will break, unless the two<br>>>> names defaultdict and DefaultDict are updated in parallel somehow to<br>>>> both point to MyMockClass. How do you propose we support that?<br>>><br>>> This would be fixed with the 'aliasing variable names'-solution.<br>>><br>><br>> Not sure I follow; are you proposing that module attributes be able to<br>> say "I'm the same as that guy over there"? That could be done with<br>> descriptor protocol (think @property, where you can write a<br>> getter/setter that has the actual value in a differently-named public<br>> attribute), but normally, modules don't allow that, as you need to<br>> mess with the class not the instance. But there have been numerous<br>> proposals to make that easier for module authors, one way or another.<br>> That would make at least some things easier - the mocking example<br>> would work that way - but it'd still mean people have to grok more<br>> than one name when reading code, and it'd most likely mess with<br>> people's expectations in tracebacks etc (the function isn't called<br>> what I thought it was called). Or is that not what you mean by<br>> aliasing?<br><br></div><div>By aliasing I meant that the names of the fuctions/variables/<br>classes (variables) are all using the same value pointer/location.<br></div><div>That could mean that in debugging the name of the variable <br>is used as the name of the function. e.g. debugging get_int <br></div><div>results in 'in get_int(), line 5' but it's original getint results in<br></div><div>'in getint(), line 5'. Another option is 'in get_int(), line 5 of getint()' <br>if you want to retain the source location and name.<br></div><div><br>It could be descriptors for Python library implementations, but in C <br>it could be implemented as a pointer to <VariableContents> instead of <br>a struct containing <VariableContents>, or it could compile(?) to use <br>the same reference. <br><br>I am not familiar enough  with the structure of CPython and <br>how it's variable lookups are built, but these are just a few ideas.<br><br></div>-Matthias<br></div>