[Python-Dev] ImportError on no permission

2007-05-06 Thread Georg Brandl
Today, I got a request regarding importing semantics.

When a module file cannot be opened because of, say, lacking read permission,
the rest of sys.path will be tried, and if nothing else is found, you get
"no module named foo".

The reporter claimed, and I understand that, that this is a pain to debug and
it would be good to at least add a better message to the import error.

Now, why don't we change the semantics as follows: if a file with matching name
exists (in import.c::find_module), but opening fails, ImportError is raised
immediately with the concrete error message, and without trying the rest of
sys.path. That shouldn't cause any working and sane setup to break, or did I
overlook something obvious here?

Georg

-- 
Thus spake the Lord: Thou shalt indent with four spaces. No more, no less.
Four shall be the number of spaces thou shalt indent, and the number of thy
indenting shall be four. Eight shalt thou not indent, nor either indent thou
two, excepting that thou then proceed to four. Tabs are right out.

___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] ImportError on no permission

2007-05-06 Thread Martin v. Löwis
> Now, why don't we change the semantics as follows: if a file with matching 
> name
> exists (in import.c::find_module), but opening fails, ImportError is raised
> immediately with the concrete error message, and without trying the rest of
> sys.path. That shouldn't cause any working and sane setup to break, or did I
> overlook something obvious here?

I wonder how this would behave if a directory on sys.path was
unreadable. You might get an ImportError on *any* import, as
it tries the unreadable directory first, gets a permission error,
and immediately aborts.

Now, I think it is quite possible that you have inaccessible
directories on sys.path, e.g. when you inherit PYTHONPATH from
a parent process.

So I would rather let importing proceed, and add a note to the
error message that some files could not be read.

Regards,
Martin
___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] ImportError on no permission

2007-05-06 Thread Brett Cannon

On 5/6/07, "Martin v. Löwis" <[EMAIL PROTECTED]> wrote:


> Now, why don't we change the semantics as follows: if a file with
matching name
> exists (in import.c::find_module), but opening fails, ImportError is
raised
> immediately with the concrete error message, and without trying the rest
of
> sys.path. That shouldn't cause any working and sane setup to break, or
did I
> overlook something obvious here?

I wonder how this would behave if a directory on sys.path was
unreadable. You might get an ImportError on *any* import, as
it tries the unreadable directory first, gets a permission error,
and immediately aborts.

Now, I think it is quite possible that you have inaccessible
directories on sys.path, e.g. when you inherit PYTHONPATH from
a parent process.

So I would rather let importing proceed, and add a note to the
error message that some files could not be read.




How about an ImportWarning instead?  That way people can have either have
import halt immediately, or continue (with or without a message).

-Brett
___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] ImportError on no permission

2007-05-06 Thread Martin v. Löwis
> How about an ImportWarning instead?  That way people can have either
> have import halt immediately, or continue (with or without a message).

If I put my dislike of warnings aside: yes, that would also work.

Martin
___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] ImportError on no permission

2007-05-06 Thread Terry Reedy

""Martin v. Löwis"" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
|> Now, why don't we change the semantics as follows: if a file with 
matching name
| > exists (in import.c::find_module), but opening fails, ImportError is 
raised
| > immediately with the concrete error message, and without trying the 
rest of
| > sys.path. That shouldn't cause any working and sane setup to break, or 
did I
| > overlook something obvious here?
|
| I wonder how this would behave if a directory on sys.path was
| unreadable.

I understood Brett to be talking about a different case where the directory 
*is* readable and the target file shows up in the directory list.  In this 
limited case, stopping seems sane to me.

| You might get an ImportError on *any* import, as
| it tries the unreadable directory first, gets a permission error,
| and immediately aborts.

Not if the patch is properly and narrowly written to only apply to 
unreadable files in readable directories.

tjr



___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] ImportError on no permission

2007-05-06 Thread Georg Brandl
Martin v. Löwis schrieb:
>> Now, why don't we change the semantics as follows: if a file with matching 
>> name
>> exists (in import.c::find_module), but opening fails, ImportError is raised
>> immediately with the concrete error message, and without trying the rest of
>> sys.path. That shouldn't cause any working and sane setup to break, or did I
>> overlook something obvious here?
> 
> I wonder how this would behave if a directory on sys.path was
> unreadable. You might get an ImportError on *any* import, as
> it tries the unreadable directory first, gets a permission error,
> and immediately aborts.

That case should be handled differently, yes.
My case is that you have a file in the directory with the correct name,
but opening it fails (this obviously requires a two-step process, first
find the file, then open it).

> Now, I think it is quite possible that you have inaccessible
> directories on sys.path, e.g. when you inherit PYTHONPATH from
> a parent process.
> 
> So I would rather let importing proceed, and add a note to the
> error message that some files could not be read.

The warning idea is also fine with me, if it's limited to the above case.

Georg


-- 
Thus spake the Lord: Thou shalt indent with four spaces. No more, no less.
Four shall be the number of spaces thou shalt indent, and the number of thy
indenting shall be four. Eight shalt thou not indent, nor either indent thou
two, excepting that thou then proceed to four. Tabs are right out.

___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Pre-pre PEP for 'super' keyword

2007-05-06 Thread Delaney, Timothy (Tim)
Steve Holden wrote:

> Tim Delaney wrote:
>> BTW, one of my test cases involves multiple super calls in the same
>> method - there is a *very* large performance improvement by
>> instantiating it once. 
>> 
> And how does speed deteriorate for methods with no uses of super at
> all (which will, I suspect, be in the majority)?

Zero - in those cases, no super instance is instantiated. There is a
small one-time cost when the class is constructed in the reference
implementation (due to the need to parse the bytecode to determine if if
'super' is used) but in the final implementation that information will
be gathered during compilation.

Tim Delaney
___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


[Python-Dev] Commit Keys

2007-05-06 Thread Calvin Spealman
I lost the key I originally gave for commiting my summaries. Who do I
talk to about fixing that?

-- 
Read my blog! I depend on your acceptance of my opinion! I am interesting!
http://ironfroggy-code.blogspot.com/
___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Commit Keys

2007-05-06 Thread Neal Norwitz
On 5/6/07, Calvin Spealman <[EMAIL PROTECTED]> wrote:
> I lost the key I originally gave for commiting my summaries. Who do I
> talk to about fixing that?

Send your new key to pydotorg. -- n
___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Commit Keys

2007-05-06 Thread Martin v. Löwis
Neal Norwitz schrieb:
> On 5/6/07, Calvin Spealman <[EMAIL PROTECTED]> wrote:
>> I lost the key I originally gave for commiting my summaries. Who do I
>> talk to about fixing that?
> 
> Send your new key to pydotorg. -- n

In doing so, please indicate whether you just lost it, or somebody else
may have found it.

Regards,
Martin
___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com