Question about math.pi is mutable

Chris Angelico rosuav at gmail.com
Sun Nov 8 19:04:26 EST 2015


On Mon, Nov 9, 2015 at 11:00 AM, Ben Finney <ben+python at benfinney.id.au> wrote:
> BartC <bc at freeuk.com> writes:
>
>> Is this typical Python code? Creating global objects in other modules
>> (or writing all over essential data structures in a library module).
>
> Not “creating global objects”, but changing the referent of a name in
> some other module. Yes, that's quite a common technique. Does that
> surprise you?

Changing the referent of an existing name, definitely. Creating new
names, not so much. You don't often reach into another module and
create a new attribute.

Testing/mocking is a completely separate consideration (eg you can
inject a shadow for a built-in name); if some Python implementation
has a fast path that gets defeated by "module.int = MagicInt", and it
causes the tests to run slower, so be it. Other than that, I can't
think of many cases (actually, can't think of any, off hand) where you
inject names into other modules.

ChrisA



More information about the Python-list mailing list