On 1/19/2011 7:34 AM, Victor Stinner wrote:
Hi,

I patched Python 3.2 to support modules with non-ASCII paths (*). It
works well on all operating systems. But the task is not completly
done:

(a) Python 3 doesn't support non-ASCII module names (b) Python 3
doesn't support unencodable characters in the module path

I would like to know if we need to support that. Terry J. Reedy
wrote (issue #10828): "I think bugs in core syntax should have high
priority. I appreciate your work toward fixing it."

I am a little shocked at the so-far tepid response to (a), so let me
defend and explain my claim that it is a bug.

In the simplest case (from 6.11. The import statement and 2.3. Identifiers and keywords)

import_stmt ::= "import" module
module      ::= indentifier
identifier  ::= <appropriate Unicode start and continue chars>

There is nothing, nothing, about any restriction on identifiers.

The rest of 6.11 discusses the complex import algorithm but leaves out the simple semantics that cover 99% of cases (import a ???.py file in a directory on sys.path), and never mentions ".py".

So lets go to Tutorial 6. Modules which does explain the simple case: "A module is a file containing Python definitions and statements. The file name is the module name with the suffix .py appended." So, if xyz is a legal identifier and xyx.py exists on sys.path, it is reasonable from the docs to expect 'import xyz' to work. (Sys.path is memtioned in the reference.)

But we now have the following possibility:

Let xyz.py be

def double(x): return 2*x

if __name__=="__main__":
  if double(2) == 4: print("test passed")

We run the file, get "test passed", and write zyx.py:

import xyz
...

We run zyx and Python says "No module named xyz".

Bad, and quite puzzling to anyone who does not understand the subtle difference between running and importing a file.

--
Terry Jan Reedy

_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to