Thanks to visit codestin.com
Credit goes to github.com

Skip to content

gh-107906 Remove unused maxsize argument from _init method of queue.Queue #107907

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

shailshouryya
Copy link
Contributor

@shailshouryya shailshouryya commented Aug 13, 2023

Closes #107906

See message in commit bacae73 for details.

@shailshouryya
Copy link
Contributor Author

I think this PR could skip the news entry since this is just a refactoring change - or would this still need an entry?

@shailshouryya
Copy link
Contributor Author

shailshouryya commented Aug 13, 2023

This shouldn't have broken anything, but it looks like some seemingly unrelated things were passing in the useless maxsize argument: https://github.com/python/cpython/actions/runs/5845780591/job/15850226459?pr=107907#step:19:113
following the fixes for #107907 (comment), this should start passing again since the failure was due to the inherited LifoStack still using expecting the maxsize argument in the overridden _init method.

@shailshouryya
Copy link
Contributor Author

shailshouryya commented Aug 13, 2023

Taking a look at https://github.com/urllib3/urllib3 to see if this can be updated - will post here again once that is resolved.

Update: it looks like the failure I linked to above wasn't actually a failure in the urllib3 package, but a failure in the queue.LifoStack class that inherited from queue.Queue. Following the fixes in commit e5094ab, this should start passing again since the failure was due to the inherited LifoStack still using expecting the maxsize argument in the overridden _init method.

@shailshouryya
Copy link
Contributor Author

shailshouryya commented Aug 13, 2023

It looks like PriorityQueue

cpython/Lib/queue.py

Lines 229 to 232 in ee40b3e

def _init(self, maxsize):
self.queue = []
def _qsize(self):

and LifoQueue

cpython/Lib/queue.py

Lines 245 to 248 in ee40b3e

def _init(self, maxsize):
self.queue = []
def _qsize(self):

inherited this maxsize argument and their corresponding tests _init methods also need to be updated (current failures: https://github.com/python/cpython/actions/runs/5845780591/job/15850226050?pr=107907#step:8:1056)

@sunmy2019
Copy link
Member

I think you should also take care of asyncio.queues.Queue and its subclasses.

@shailshouryya
Copy link
Contributor Author

Following commit e5094ab, all tests except for the Hypothesis tests on Ubuntu GitHub Action job now pass. I'm not sure why this specific test is failing, since the error message

  File "/home/runner/work/cpython/cpython-ro-srcdir/Lib/queue.py", line 36, in __init__
    self._init()
TypeError: LifoQueue._init() missing 1 required positional argument: '_'

points to

cpython/Lib/queue.py

Lines 34 to 36 in ee40b3e

def __init__(self, maxsize=0):
self.maxsize = maxsize
self._init(maxsize)

... but commits bacae73 and e5094ab should address this. I also tried looking through the raw logs of the GitHub Action job, but nothing obvious seemed to pop out to me suggesting the test failed to build properly, which I initially suspected to be causing the test failure. (I'm not familiar with the build process for the GitHub Action jobs, though, so I might have missed something.)

@hugovk
Copy link
Member

hugovk commented Aug 13, 2023

I think this PR could skip the news entry since this is just a refactoring change - or would this still need an entry?

This needs a news entry because it's changing code which is potentially used.

(There's discussion in the issue whether this change should be made.)

@rhettinger
Copy link
Contributor

Closing for the reasons listed in the associated issue. This is an unnecessary breaking change that overrides the intentional design decision of the original author (Guido).

@rhettinger rhettinger closed this Aug 13, 2023
@brandonardenwalli
Copy link
Contributor

Ok, so I am here after #107906 (comment), and this is little more helpful but still not fully clear to me.

I look to https://github.com/python/cpython/commits/ee40b3e20d9b8d62a9b36b777dff42db1e9049d5/Lib/queue.py then https://github.com/python/cpython/commits/f260e443ac07bc794fc9409096679b94528868e2/Lib/Queue.py?browsing_rename_history=true&new_path=Lib/queue.py&original_branch=ee40b3e20d9b8d62a9b36b777dff42db1e9049d5 and find this 9022fce. In 9022fce I see

	# Initialize a queue object with a given maximum size
	# (If maxsize is <= 0, the maximum size is infinite)
	def init(self, maxsize):
		import thread
		self._init(maxsize)

and then look at

	def _init(self, maxsize):
		self.maxsize = maxsize
		self.queue = []

which to me makes sense so far. However, when I look at the current code https://github.com/python/cpython/blob/ee40b3e20d9b8d62a9b36b777dff42db1e9049d5/Lib/queue.py, I see

    def __init__(self, maxsize=0):
        self.maxsize = maxsize
        self._init(maxsize)

so the code today no longer do anything with maxsize inside of _init

    def _init(self, maxsize):
        self.queue = deque()

since init now do the

        self.maxsize = maxsize

itself. After all this, I am confused about:

  1. Why to keep maxsize in _init? If I understand correct based on what I learn so far, code having anything that is not used should be remove to avoid confusing other people. In this code, the maxsize is no used in _init, so to me it makes sense to remove. Also, this to me is obvious cause some confusion, so this would be useul to remove.
  2. What is purpose of _init? It to me looks like _init does not really do much that the init can do itself. Also, I read that convention is to make _ (underascore) in front of something if it means to tell people not to use that thing or not to make dependent on that thing with _ so why is this a dependent here?
  3. Did meaning of _ change? I wonder this since 9022fce is show to be committed on on Aug 25, 1992, which is quite an old thing, and possible that meaning from then to now change?

I think I may be looking in something wrong again, so @gvanrossum can you please make explanation if you have some time? It is probably that I should be looking somewhere else and the explanation is obvious, but a newbie like me is having trouble finding it.

Also @shailshouryya I just read about some hypothesis issue at #107862 that talk of the tests not always being the same, so maybe that is the problem that you may be talk of here?

@gvanrossum
Copy link
Member

I'm sorry @brandonardenwalli, it looks like you need more mentoring than I can provide. This issue has absolutely nothing to do with the question I answered previously, so my conclusion is that you're likely just flailing. Sorry.

FWIW the _init() method is essentially an ad-hoc semi-public API for subclasses to override, so I don't want to change it.

@brandonardenwalli
Copy link
Contributor

Ok, thanks for the reply! By the way, when you say this is not related to "question I answered previously" you are referring to the issue from yesterday about the issue of Tier 2 interpreters? Just making double check to make sure.

FWIW the _init() method is essentially an ad-hoc semi-public API for subclasses to override, so I don't want to change it.

Ok, I think that is useful enough. Thank you!

@gvanrossum
Copy link
Member

Yes that question. Which you started by quoting. And I don’t recall answering any other questions from you.

@shailshouryya
Copy link
Contributor Author

Thanks for linking that hypothesis issue, that was an interesting read! Also, in addition to going through the issues with the "Easy" label here, you might also like https://github.com/codecrafters-io/build-your-own-x and https://github.com/practical-tutorials/project-based-learning if you like doing things hands-on. Alternatively, if you like watching videos, I would recommend going on YouTube and searching for something like make XYZ in python (or any other language), or browsing through https://www.infoq.com/presentations/.

Best of luck, and have fun :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unused maxsize argument in _init method of queue.Queue
7 participants