Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: A desperate lunge for on-topic-ness

Reply
Thread Tools

Re: A desperate lunge for on-topic-ness

 
 
Joshua Landau
Guest
Posts: n/a
 
      10-23-2012
On 23/10/2012, Dennis Lee Bieber <(E-Mail Removed)> wrote:
> On Mon, 22 Oct 2012 16:02:34 -0600, Ian Kelly <(E-Mail Removed)>
> declaimed the following in gmane.comp.python.general:
>
>> On my wishlist for Python is a big, fat SyntaxError for any variable
>> that could be interpreted as either local or nonlocal and is not
>> explicitly declared as either. It would eliminate this sort of
>> confusion entirely and make code that shadows nonlocal variables much
>> more readable.
>>

> Which now makes code dependent upon changes to some imported modules
> if someone is foolish enough to use the
>
> from xyz import *
>
> notation...
>
> I'd be very displeased if working code with local names suddenly
> fails because some third-party package was updated.
>
> Yes, I prefer not to use the "from...*" notation, but how many
> tutorials (especially of GUI toolkits, with their dozens of constants)
> illustrate using the wildcard?


I'm not particularly fond (or disliking) of the proposal, but we
already make changes to the structure of locals/globals and so forth
when someone does "from <something> import *". Disabling checks when
it is used is totally reasonable.

Additionally, "SyntaxError: import * only allowed at module level".
This means, as far as I grasp, one should never *manage* to create an
ambiguity here. Ian already stated this idea should (due to
neccessity) be disabled for possible globals.
 
Reply With Quote
 
 
 
 
Ian Kelly
Guest
Posts: n/a
 
      10-23-2012
On Mon, Oct 22, 2012 at 7:39 PM, Dennis Lee Bieber
<(E-Mail Removed)> wrote:
> On Mon, 22 Oct 2012 16:02:34 -0600, Ian Kelly <(E-Mail Removed)>
> declaimed the following in gmane.comp.python.general:
>
>> On my wishlist for Python is a big, fat SyntaxError for any variable
>> that could be interpreted as either local or nonlocal and is not
>> explicitly declared as either. It would eliminate this sort of
>> confusion entirely and make code that shadows nonlocal variables much
>> more readable.
>>

> Which now makes code dependent upon changes to some imported modules
> if someone is foolish enough to use the
>
> from xyz import *
>
> notation...


It's already a SyntaxError to use a wildcard import anywhere other
than the module level, so its use can only affect global variables.
 
Reply With Quote
 
 
 
 
Steven D'Aprano
Guest
Posts: n/a
 
      10-23-2012
On Tue, 23 Oct 2012 10:50:11 -0600, Ian Kelly wrote:

>> if someone is foolish enough to use the
>>
>> from xyz import *
>>
>> notation...

>
> It's already a SyntaxError to use a wildcard import anywhere other than
> the module level, so its use can only affect global variables.


In Python 3.x.

In Python 2.x, which includes the most recent version of three of the
four "big implementations" (PyPy, Jython, IronPython) it is still legal,
at least in theory.

I haven't tested PyPy, but IronPython 2.6 allows wildcard imports inside
functions without even a warning. Bizarrely, Jython 2.5 *appears* to
allow them with only a warning, but they don't take:

steve@runes:~$ jython
Jython 2.5.1+ (Release_2_5_1, Aug 4 2010, 07:18:19)
[OpenJDK Client VM (Sun Microsystems Inc.)] on java1.6.0_18
Type "help", "copyright", "credits" or "license" for more information.
>>> def test():

.... from math import *
.... return cos
....
<stdin>:2: SyntaxWarning: import * only allowed at module level
>>> test()

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 3, in test
NameError: global name 'cos' is not defined


So, legal or not, they're definitely something you want to avoid.


--
Steven
 
Reply With Quote
 
Ian Kelly
Guest
Posts: n/a
 
      10-23-2012
On Tue, Oct 23, 2012 at 4:34 PM, Steven D'Aprano
<(E-Mail Removed)> wrote:
> On Tue, 23 Oct 2012 10:50:11 -0600, Ian Kelly wrote:
>
>>> if someone is foolish enough to use the
>>>
>>> from xyz import *
>>>
>>> notation...

>>
>> It's already a SyntaxError to use a wildcard import anywhere other than
>> the module level, so its use can only affect global variables.

>
> In Python 3.x.
>
> In Python 2.x, which includes the most recent version of three of the
> four "big implementations" (PyPy, Jython, IronPython) it is still legal,
> at least in theory.


If we're talking about making changes to the language, then we're
clearly talking about Python 3.x and beyond. There are no more major
releases planned for 2.x.
 
Reply With Quote
 
Steven D'Aprano
Guest
Posts: n/a
 
      10-24-2012
On Tue, 23 Oct 2012 17:24:34 -0600, Ian Kelly wrote:

> On Tue, Oct 23, 2012 at 4:34 PM, Steven D'Aprano
> <(E-Mail Removed)> wrote:
>> On Tue, 23 Oct 2012 10:50:11 -0600, Ian Kelly wrote:
>>
>>>> if someone is foolish enough to use the
>>>>
>>>> from xyz import *
>>>>
>>>> notation...
>>>
>>> It's already a SyntaxError to use a wildcard import anywhere other
>>> than the module level, so its use can only affect global variables.

>>
>> In Python 3.x.
>>
>> In Python 2.x, which includes the most recent version of three of the
>> four "big implementations" (PyPy, Jython, IronPython) it is still
>> legal, at least in theory.

>
> If we're talking about making changes to the language, then we're
> clearly talking about Python 3.x and beyond. There are no more major
> releases planned for 2.x.


In what way does "it is ALREADY a SyntaxError" [emphasis added] refer to
making future changes to the language?

My point is that for probably 80% or more of Python users, it is not the
case that wildcard imports in functions are already a syntax error.
Anyone using CPython 2.x, PyPy, Jython or IronPython have such a syntax
error to look forward to in the future, but not now. Until then, they
have to deal with syntax warnings, implementation-dependent behaviour,
and as far as I can see, an outright language bug in Jython, but no
syntax errors.


--
Steven
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
A desperate lunge for on-topic-ness Zero Piraeus Python 24 10-19-2012 10:16 PM
Re: A desperate lunge for on-topic-ness Jean-Michel Pichavant Python 2 10-19-2012 05:59 PM
Re: A desperate lunge for on-topic-ness Mark Lawrence Python 0 10-18-2012 09:12 AM
Re: A desperate lunge for on-topic-ness Demian Brecht Python 0 10-18-2012 06:52 AM
Re: A desperate lunge for on-topic-ness Chris Angelico Python 0 10-18-2012 06:13 AM



Advertisments