GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — gh-90562: Improve zero argument support for `super()` in dataclasses when `slots=True` by Bobronium · Pull Request #124692 · python/cpython Conversation
|
| _seen.add(id(obj)) | ||
|
|
||
| _depth += 1 | ||
| if _depth > 2: |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Why are depth 1 and 2 special? What is this test (and _depth in general) trying to accomplish? Please add comments explaining what's going on here, it's not at all clear from the code.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Added an explanation and few test cases for this behaviour. Caught two bugs in the process \o/
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| ): | ||
| # we don't want to inspect custom descriptors just yet | ||
| # there's still a chance we'll encounter a pure function | ||
| # or a property |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Please add a comment explaining why encountering a pure function or property means we don't have to inspect custom descriptors.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Hmm, there's already an explanation above:
Lines 1336 to 1339 in 3b65acf
| # original class. We can break out of this loop as soon as we | |
| # make an update, since all closures for a class will share a | |
| # given cell. First we try to find a pure function/properties, | |
| # and then fallback to inspecting custom descriptors. |
Would you like me to add clarification for this case specifically?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Ah, you're right. Maybe change the comment to "... fallback to inspecting custom descriptors if no pure function or property is found".
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Makes sense. I've added clarification in both places to be extra clear.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Great find, thanks a lot for your work! 👍
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
| return None | ||
|
|
||
| for attr in dir(obj): | ||
| value = getattr(obj, attr, None) |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
This case is always complex, since getattr can evaluate properties and other objects. There are two ways of hanling this case:
I am not quite sure which one is better here.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Thanks for bringing this to my attention!
After some hacking, I've decided to go with the third option: removing any possibility of user defined code execution.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
This looks OK to me; I'll let @ericvsmith give it final approval/merge.
I don't love that we've opened the door to an infinite fractal of complexity here; at some point it would probably be better to bite the bullet and introduce a __classcell__ attribute on classes that allows reliably finding this cell in O(1) time.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
I agree that the complexity is unfortunate. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Good idea. I've changed the implementation to use |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@carljm, friendly ping :) |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
As I mentioned above, I would rather have @ericvsmith approve/merge this, since it was his review comments you addressed. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I've been busy, but it's on my list of things to do. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
This PR is stale because it has been open for 30 days with no activity. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Co-authored-by: sobolevn <[email protected]>
This uses builtins.dir, which will trigger custom __getattibute__ if any, and will trigger __get__ on __dict__ descriptor.
5bfea4d to
5a7037b
Compare
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.