Skip to content
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

gh-58211: Add tests for __self__ attribute of builtins functions #113575

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

adorilson
Copy link
Contributor

@adorilson adorilson commented Dec 29, 2023

Although there was an inconclusive discussion in #58211, this PR adds tests to __self__ in built-in callables as it work currently.

If was accepted, after PR #113574 is merged we can fix the documentation too (just avoid conflict).

adorilson and others added 3 commits December 29, 2023 19:34
The check about the f argument type was removed in this commit:
python@2c94aa5

Thanks for Pedro Arthur Duarte (pedroarthur.jedi at gmail.com) by the help with
this bug.
…#106335)

Remove private _PyThreadState and _PyInterpreterState C API
functions: move them to the internal C API (pycore_pystate.h and
pycore_interp.h). Don't export most of these functions anymore, but
still export functions used by tests.

Remove _PyThreadState_Prealloc() and _PyThreadState_Init() from the C
API, but keep it in the stable API.
Copy link
Member

@AlexWaygood AlexWaygood left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This appears to me to go in the opposite direction to the consensus in #58211 -- the consensus seems to me to be that this is a misfeature that could only be confusing. That doesn't mean that we should necessarily bother changing the current behaviour unless it's actually causing a bug for somebody. But we should only add tests for things which are working in a desirable way currently -- we shouldn't cement undesirable behaviour by adding tests for it.

I'm therefore doubtful that this PR is a good idea. Instead, as I suggested in #113574 (comment), I think we should fix the documentation so that it is more vague about what the value of this attribute might be for builtin functions.

@adorilson
Copy link
Contributor Author

we shouldn't cement undesirable behaviour by adding tests for it.

Yes, I agree. (Although I'm the PR author). The big problem is where desirable behaviour is defined.
I found a PEP concern about this but didn't find it. Do you know if it exists?

Furthermore, ignoring other necessary knowledge, I think of the self as the member's owner. So, thinking about the module as the built-in functions' owner was natural.

I'm therefore doubtful that this PR is a good idea. Instead, as I suggested in #113574 (comment), I think we should fix the documentation so that it is more vague about what the value of this attribute might be for builtin functions.

I don't know if this is a good idea. I guess not.

Maybe it is better to remove this attribute from the documentation. Seeing the Terry's comment, the bug is not only the __self__ value but their own existence. In this sense, we already have been cementing undesirable behaviour.

@serhiy-storchaka
Copy link
Member

There is a code in inspect or pydoc to work around this "feature". There may be a third-party code or even code in the stdlib that depends on this feature. If we even change this in future, it is better to have explicit tests that will fail, so this change will not pass unnoticed as a side effect of other changes. We can make these tests running only on CPython, and add comments explaining this.

@adorilson
Copy link
Contributor Author

If we even change this in future, it is better to have explicit tests that will fail, so this change will not pass unnoticed as a side effect of other changes. We can make these tests running only on CPython, and add comments explaining this.

Do you mean:

  1. Considering this PR
  2. Keeping in documentation __self__ is set to None (because it is the desirable behaviour)
  3. Adding in documentation a impl-detail directive: Currently, CPython returns the module object where the built-in function is defined, but it can change in the future.

?

@serhiy-storchaka
Copy link
Member

I meant considering this PR.

@serhiy-storchaka serhiy-storchaka added skip news needs backport to 3.11 bug and security fixes needs backport to 3.12 bug and security fixes labels Jan 2, 2024
@serhiy-storchaka serhiy-storchaka changed the title gh-58211 Add builtins callables tests gh-58211: Add tests for __self__ attribute of builtins functions Jan 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting review needs backport to 3.11 bug and security fixes needs backport to 3.12 bug and security fixes skip news tests Tests in the Lib/test dir
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants