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: Add new parameter format for converter function w/ position number
Type: enhancement Stage:
Components: Interpreter Core Versions: Python 3.4
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: docs@python, ronaldoussoren, techtonik
Priority: low Keywords:

Created on 2013-06-20 06:24 by techtonik, last changed 2022-04-11 14:57 by admin.

Messages (8)
msg191502 - (view) Author: anatoly techtonik (techtonik) Date: 2013-06-20 06:24
(<type 'int'>, '0755')
(<type 'int'>, '0644')
Traceback (most recent call last):
  File "./tools/bootstrap.py", line 185, in extract_zip
    os.fchmod(outfile, unixperm)
TypeError: an integer is required


Here the integer that is required is not `unixperm`, but `outfile`.
msg191524 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2013-06-20 14:55
os.chmod is implemented in posixmodule.c and the argument parsing code can be found at http://hg.python.org/cpython/file/3acbb23c73bc/Modules/posixmodule.c#l2605 . You will notice that the argument parsing is specified as "O&i|$O&p". That means the first argument is parsed as a Python object which is passed through a converter function and the second argument is required to be an integer. That converter function can be found at http://hg.python.org/cpython/file/3acbb23c73bc/Modules/posixmodule.c#l681. Looking at that code doesn't suggest that TypeError is raised with that message.

What were the exact arguments you passed into os.chmod() that triggered the exception?
msg191529 - (view) Author: anatoly techtonik (techtonik) Date: 2013-06-20 17:35
>>> v = open("VERSION")
>>> import os
>>> os.fchmod(v, 0664)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: an integer is required
msg191533 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2013-06-20 19:10
That's expected with that kind of argument. os.fchmod() and os.chmod() only accept a path as a string or a file descriptor as an integer as specified in the docs: http://docs.python.org/3/library/os.html#os.chmod
msg191541 - (view) Author: anatoly techtonik (techtonik) Date: 2013-06-20 22:02
Right. This report is about improving error message. It doesn't say what is expected where. If you have a call like:

    os.fchmod(outfile, unixperm)

it is easy to assume that unixperm is not integer, while in fact the problem is in outfile. This could not be actual for Python 3, but it seems that there is bug with it as well.

>>> v = open("VERSION")
>>> import os
>>> os.fchmod(v, 0664)
  File "<stdin>", line 1
    os.fchmod(v, 0664)
                    ^
SyntaxError: invalid token
>>>
msg191543 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2013-06-20 22:54
That is not a documentation bug (i.e. a problem with what is written at docs.python.org), this is a feature request to try to improve the exception message. That would require adding a new parameter format (http://docs.python.org/3/c-api/arg.html?highlight=pyarg_parse#other-objects) which allows for a converter function which also takes the positional number and/or keyword argument that the converter function was called for.
msg191577 - (view) Author: anatoly techtonik (techtonik) Date: 2013-06-21 13:29
This is more sophisticated that I thought. Thank for the explanation.
msg191585 - (view) Author: Ronald Oussoren (ronaldoussoren) * (Python committer) Date: 2013-06-21 14:42
I don't think that a new parameter format is sufficient. For the message in this call the new parameter isn't even needed, you'd "just" have to ensure that enough information is available in convertsimple to create a more useful message.

That said, that is far from a trivial change, more so because the PyArg_Parse family of functions can parse fairly complicated argument structures in one go (such as using ``PyArg_Parse(args, "(si)", &host, port)`` to unpack the tuple in the first (and only) argument).
History
Date User Action Args
2022-04-11 14:57:47adminsetgithub: 62469
2020-03-06 20:19:38brett.cannonsetnosy: - brett.cannon
2013-06-21 14:42:10ronaldoussorensetnosy: + ronaldoussoren
messages: + msg191585
2013-06-21 13:29:13techtoniksetmessages: + msg191577
2013-06-20 22:54:33brett.cannonsetpriority: normal -> low

assignee: docs@python ->
components: + Interpreter Core, - Documentation, Library (Lib)
title: Clarify which integer is required in os.chmod() exception -> Add new parameter format for converter function w/ position number
type: enhancement
versions: - Python 2.7, Python 3.3
messages: + msg191543
2013-06-20 22:02:59techtoniksetstatus: closed -> open
versions: + Python 2.7, Python 3.3
messages: + msg191541

assignee: docs@python
components: + Documentation
resolution: not a bug ->
2013-06-20 19:10:27brett.cannonsetstatus: open -> closed
resolution: not a bug
messages: + msg191533
2013-06-20 17:35:45techtoniksetstatus: pending -> open

messages: + msg191529
2013-06-20 14:55:29brett.cannonsetstatus: open -> pending

assignee: docs@python -> (no value)
components: + Library (Lib), - Documentation
versions: - Python 2.6, Python 3.1, Python 2.7, Python 3.2, Python 3.3, Python 3.5
nosy: + brett.cannon

messages: + msg191524
2013-06-20 06:24:57techtonikcreate