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: queue.Queue() does not validate the maxsize argument
Type: enhancement Stage:
Components: Library (Lib) Versions: Python 3.4
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: rhettinger Nosy List: Alex.Willmer, rhettinger
Priority: normal Keywords:

Created on 2015-09-05 17:12 by Alex.Willmer, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (2)
msg249914 - (view) Author: Alex Willmer (Alex.Willmer) * Date: 2015-09-05 17:12
The maxsize argument when initializing a Queue is expected to be an int (technically anything that can be compared to an int). However the class takes any value. In Python 3 this throws "TypeError: unorderable types" once e.g. .put() is called.

On the basis that errors should not pass silent, should maxsize be checked for compatibility at initialization time? e.g.

Desired:

>>> import queue
>>> q = queue.Queue(range(10))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.5/queue.py", line nnn, in __init__()
    ...
TypeError: 'range' object cannot be interpreted as an integer


Actual:

Python 3.5.0rc2 (default, Aug 25 2015, 20:29:07) 
[GCC 5.2.1 20150825] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import queue
>>> q = queue.Queue(range(10)) # Silently accepts an invalid maxsize
>>> q.put('foo')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.5/queue.py", line 127, in put
    if self.maxsize > 0:
TypeError: unorderable types: range() > int()
msg249929 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2015-09-05 21:38
The norm for pure python code is to duck type when objects are used rather than when they are passed in.

The Queue module is very old and for the most part, its straight-forward design has worked out well (i.e. there aren't any real usability issues in actual practice).

Accordingly, I'm going to decline the request.
History
Date User Action Args
2022-04-11 14:58:20adminsetgithub: 69197
2015-09-05 21:38:44rhettingersetstatus: open -> closed

type: behavior -> enhancement
assignee: rhettinger

nosy: + rhettinger
messages: + msg249929
resolution: rejected
2015-09-05 17:12:53Alex.Willmercreate