This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: open doesn't provide traceback for int argument
Type: behavior Stage: resolved
Components: Interpreter Core Versions: Python 3.2, Python 3.3, Python 3.4
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: SilentGhost, slivabox
Priority: normal Keywords:

Created on 2015-01-11 12:03 by slivabox, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
1.py slivabox, 2015-01-11 12:03
Messages (2)
msg233844 - (view) Author: Ievgen Aleinikov (slivabox) Date: 2015-01-11 12:03
HI,

I was able to gat such behaviour on python version 3.4.2 and 3.2.3
>>> for i in range(10):
...   f = open(i, "w")
...   f.close()
... 
This will close interactive session without any output.


On python 2 (2.7.9) it's not happening:
>>> for i in range(10):
...  f = open(i, "w")
...  f.close()
... 
Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
TypeError: coercing to Unicode: need string or buffer, int found
>>>

And interpreter is not closed.

If run attached 1.py we'll see following:

python2.7 1.py 
Traceback (most recent call last):
  File "1.py", line 2, in <module>
    f = open(i, "w")
TypeError: coercing to Unicode: need string or buffer, int found


python3.4 1.py -> nothing happens (echo $? -> 1)



Kind regards,
Ievgen.
msg233845 - (view) Author: SilentGhost (SilentGhost) * (Python triager) Date: 2015-01-11 12:35
As explained in the docs[1] integer is a valid argument for the open function in the python3. It is also noted that the file descriptor is going to be closed, unless closefd argument to the open function was False, when f.close() is called. This is the behaviour you're seeing. Zero or other small integers tend to point to vital files opened by interpreter or the interpreter itself, so closing them shuts the interpreter down. This is a layman explanation, so someone should be able to provide a more technical description.

In either case this is not a bug and passing random arguments to the open function is probably not what should be done in any production code. I'm closing this issue.

[1] https://docs.python.org/3/library/functions.html#open
History
Date User Action Args
2022-04-11 14:58:11adminsetgithub: 67411
2015-01-11 12:35:09SilentGhostsetstatus: open -> closed

type: behavior
components: + Interpreter Core, - IO

nosy: + SilentGhost
messages: + msg233845
resolution: not a bug
stage: resolved
2015-01-11 12:03:34slivaboxcreate