The binding operator, and what gets bound to what

Ned Batchelder ned at nedbatchelder.com
Fri Dec 5 07:56:26 EST 2014


On 12/5/14 7:34 AM, Steven D'Aprano wrote:
> Ned Batchelder wrote:
>
>> On 12/5/14 4:53 AM, Steven D'Aprano wrote:
>>> Oh, I learned something new: strictly speaking, this is implementation-
>>> dependent and not guaranteed to work in the future!
>>>
>>> def func():
>>>       global math
>>>       import math
>>
>> I don't think this is implementation-dependent.
>
> The docs say that it is:
>
> https://docs.python.org/3/reference/simple_stmts.html#the-global-statement
>
>      Names listed in a global statement MUST NOT [emphasis added] be
>      defined as formal parameters or in a for loop control target,
>      class definition, function definition, or import statement.
>
>      CPython implementation detail: The current implementation does not
>      enforce the two restrictions, but programs should not abuse this
>      freedom, as future implementations may enforce them or silently
>      change the meaning of the program.

Ah, good.  TIL! :)

-- 
Ned Batchelder, http://nedbatchelder.com




More information about the Python-list mailing list