FCNTL module deprecation warning

Tim Peters tim.one at comcast.net
Tue Jul 15 21:27:01 EDT 2003


[Tony Meyer]
> Strange.  I get the warning on 2.2.3 and 2.3b2, except in 2.3b2 IDLE,
> which successfully imports fcntl (odd).  (long cut'n'pastes below).

Not in my 2.3b2 IDLE (installed from the released binary installer):

Python 2.3b2 (#43, Jun 29 2003, 16:43:04) [MSC v.1200 32 bit (Intel)] on
win32
Type "copyright", "credits" or "license()" for more information.
IDLE 1.0b2
>>> import fcntl

Traceback (most recent call last):
  File "<pyshell#0>", line 1, in -toplevel-
    import fcntl
ImportError: No module named fcntl
>>>


> Do you have the PYTHONCASEOK envar set?

Absolutely not.  That envar is for desperate backward compatibility problems
on junk systems, where the user doesn't care about portable import
semantics.


> (This doesn't seem to make any difference to me, but from the
> explanation I didn't think it would).

To the contrary, setting PYTHONCASEOK radically changes behavior here!
Indeed, it's the only explanation I can think of for this:


> Python 2.3b2 (#43, Jun 29 2003, 16:43:04) [MSC v.1200 32 bit (Intel)]
> on win32
> Type "help", "copyright", "credits" or "license" for more information.
>>> import fcntl
c:\progra~1\python23\lib\fcntl.py:7: DeprecationWarning: the FCNTL module is
dep recated; please use fcntl DeprecationWarning)


There isn't (or at least shouldn't be) any file named fcntl.py anywhere in
your Python installation.  FCNTL.py, yes, but not fcntl.py (or .dll, or
.pyd, etc).  The deprecation warning you showed there comes from FCNTL.py
(open it up and look at line 7):

warnings.warn("the FCNTL module is deprecated; please use fcntl",
              DeprecationWarning)

Therefore, when you did "import fcntl", it actually opened FCNTL.py.  That's
what happens if you set PYTHONCASEOK -- case distinctions are ignored on
Windows then, violating Python's intended behavior.

The reason the later

from fcntl import *

in FCNTL.py doesn't cause infinite recursion then is subtle, but intended
behavior.  Note that this module doesn't blow up with infinite recursion
either if you import it:

C:\Code\python\PCbuild>type fooey.py
print "a bunch of junk"
import fooey

C:\Code\python\PCbuild>

The short course is that Python arranges for recursive imports "to work", so
that circular imports are possible (for the careful).

Here:

C:\Python23>set PYTHONCASEOK=1

C:\Python23>python
Python 2.3b2 (#43, Jun 29 2003, 16:43:04) [MSC v.1200 32 bit (Intel)] on
 win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import fcntl
C:\PYTHON23\lib\fcntl.py:7: DeprecationWarning: the FCNTL module is
deprecated; please use fcntl
  DeprecationWarning)
>>> print fcntl.__file__
C:\PYTHON23\lib\fcntl.pyc
>>>

fcntl.__file__ gives the name of the file Python believes the .pyc file was
compiled from.  Because PYTHONCASEOK is set, the case given in the import
statement was believed (bit ignored for purposes of searching for it).
There certainly isn't any file named fcntl.py here, though:

C:\Python23>dir/b lib\fc*
FCNTL.py
FCNTL.pyc

C:\Python23>


Python works as designed if that envar is left unset:

C:\Python23>set PYTHONCASEOK=

C:\Python23>python
Python 2.3b2 (#43, Jun 29 2003, 16:43:04) [MSC v.1200 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import fcntl
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
ImportError: No module named fcntl
>>>






More information about the Python-list mailing list