Skip to content

Test suite expects _stat extension to be available #108638

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
2 tasks done
vstinner opened this issue Aug 29, 2023 · 8 comments
Closed
2 tasks done

Test suite expects _stat extension to be available #108638

vstinner opened this issue Aug 29, 2023 · 8 comments
Labels
type-bug An unexpected behavior, bug, or error

Comments

@vstinner
Copy link
Member

vstinner commented Aug 29, 2023

Bug report

Checklist

  • I am confident this is a bug in CPython, not a bug in a third-party project
  • I have searched the CPython issue tracker,
    and am confident this bug has not been reported before

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Output from running 'python -VV' on the command line:

No response

A clear and concise description of the bug:

The _stat extension is specific to CPython. For example, PyPy has no _stat module.

But the Python test suite expects the _stat module to be available: test_inspect, test_pydoc, and test_tarfile fail with it's missing.

Disable compilation of the _stat extension to reproduce the issue:

diff --git a/Modules/Setup.bootstrap.in b/Modules/Setup.bootstrap.in
index 8ef0f203a8..a1f6b8cc85 100644
--- a/Modules/Setup.bootstrap.in
+++ b/Modules/Setup.bootstrap.in
@@ -29,7 +29,7 @@ _abc _abc.c
 _functools _functoolsmodule.c
 _locale _localemodule.c
 _operator _operator.c
-_stat _stat.c
+#_stat _stat.c
 _symtable symtablemodule.c
 
 # for systems without $HOME env, used by site._getuserbase()

Example:

$ ./python -c 'import _stat'
ModuleNotFoundError: No module named '_stat'

Linked PRs

@vstinner vstinner added the type-bug An unexpected behavior, bug, or error label Aug 29, 2023
vstinner added a commit to vstinner/cpython that referenced this issue Aug 29, 2023
* Fix test_inspect, test_pydoc, test_stat and test_tarfile when the
  _stat extension is missing.
* Change the pure Python implementation of stat.filemode() for
  unknown file type: use "?", as done by the _stat.filemode().
vstinner added a commit to vstinner/cpython that referenced this issue Aug 29, 2023
Change the pure Python implementation of stat.filemode() for unknown
file type: use "?", as done by the _stat.filemode().

test_stat skips TestFilemodeCStat if the _stat extension is missing.
vstinner added a commit to vstinner/cpython that referenced this issue Aug 29, 2023
Change the pure Python implementation of stat.filemode() for unknown
file type: use "?", as done by the _stat.filemode().

test_stat skips TestFilemodeCStat if the _stat extension is missing.
vstinner added a commit to vstinner/cpython that referenced this issue Aug 29, 2023
Change the pure Python implementation of stat.filemode() for unknown
file type: use "?", as done by the _stat.filemode().

test_stat skips TestFilemodeCStat if the _stat extension is missing.
vstinner added a commit to vstinner/cpython that referenced this issue Aug 29, 2023
Change the pure Python implementation of stat.filemode() for unknown
file type: use "?", as done by the _stat.filemode().

test_stat skips TestFilemodeCStat if the _stat extension is missing.
@sobolevn
Copy link
Member

Some time ago I opened the exact same issue, but about _functools extension.
Tests is written in a way that expect _functools to always be there. However, other iterpreters may not have it.

My PR was rejected :(
https://bugs.python.org/issue46647

@vstinner
Copy link
Member Author

Some time ago I opened the exact same issue, but about _functools extension.

pypy3 (PyPy 3.9.16 v7.3.12) doesn't have the _functools module, but pypy2 (PyPy 2.7.18 v7.3.12) has the _functools module. It may help to make test_functools compatible with PyPy to support the case when _functools is missing. I didn't look if your proposed change make functools and/or test_functools maintenance too complicated or not.

@sunmy2019
Copy link
Member

The _stat extension is specific to CPython. For example, PyPy has _stat module.

Do you mean "PyPy doesn't have _stat module"?

@vstinner
Copy link
Member Author

Do you mean "PyPy doesn't have _stat module"?

Oops, right:

$ pypy3
Python 3.9.17 (a61d7152b989, Aug 13 2023, 10:27:46)
[PyPy 7.3.12 with GCC 13.2.1 20230728 (Red Hat 13.2.1-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.

>>>> import _stat
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named '_stat'

vstinner added a commit that referenced this issue Aug 29, 2023
Change the pure Python implementation of stat.filemode() for unknown
file type: use "?", as done by the _stat.filemode().

test_stat skips TestFilemodeCStat if the _stat extension is missing.
@gvanrossum
Copy link
Member

Seems fixed now.

@vstinner
Copy link
Member Author

test_inspect and test_pydoc still fail. I reopen the issue.

I'm not sure if it's better to change _stat and/or stat functions signature, or skip the affected tests when _stat is not available.

@vstinner vstinner reopened this Aug 29, 2023
@gvanrossum
Copy link
Member

I'm not sure if it's better to change _stat and/or stat functions signature, or skip the affected tests when _stat is not available.

Whichever is the simplest fix, I'd say.

vstinner added a commit to vstinner/cpython that referenced this issue Aug 30, 2023
Fix test_inspect and test_pydoc when the _stat extension is missing.
Skip tests relying on _stat when _stat is missing.
vstinner added a commit to vstinner/cpython that referenced this issue Aug 30, 2023
Fix test_inspect and test_pydoc when the _stat extension is missing.
Skip tests relying on _stat when _stat is missing.
vstinner added a commit that referenced this issue Aug 31, 2023
Fix test_inspect and test_pydoc when the _stat extension is missing.
Skip tests relying on _stat when _stat is missing.
@vstinner
Copy link
Member Author

vstinner commented Aug 31, 2023

The whole test suite now pass when the _stat extension is missing. I close the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

4 participants