Encapsulation in Python

Chris Angelico rosuav at gmail.com
Sat Mar 12 23:05:22 EST 2016


On Sun, Mar 13, 2016 at 2:36 PM, Rick Johnson
<rantingrickjohnson at gmail.com> wrote:
> On Saturday, March 12, 2016 at 3:10:49 PM UTC-6, Chris Angelico wrote:
>> Also, if currentModule.py is pulling foo from modX, then modZ.py is an
>> implementation detail. You don't necessarily want to go straight
>> there; tracing the chain is more likely to be the correct behaviour.
>> Suppose modX.py actually looks like this:
>>
>> if 'posix' in some_magic:
>>     import posixY as modY
>> elif 'nt' in some_magic:
>>     import ntY as modY
>> else:
>>     raise ImportError
>
> Ha, well, along with my example, this is another good
> example of a very bad design ;-). It's a terrible sin to
> import a symbol through multiple modules, but to import a
> symbol through multiple modules *AND* redefine it along the
> way, well, that should be punishable by the fatal exception.
> No judge, no jury. Just swift, and absolute, justice. :-)

Good. Go complain to the os module about how it's doing the wrong
thing. This is exactly what it does to provide os.path.

ChrisA



More information about the Python-list mailing list