Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Fix not throwing the same error as CPython in test_pathlib.test_expanduser #5578

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

Merged

Conversation

hbina
Copy link
Contributor

@hbina hbina commented Mar 2, 2025

Given,

hbina085@akarin-thinkpad ~/g/RustPython (main) [1]> cat ggg_nonexisten_user.py                                                                                                                                        (base) 
import pwd

fakename = 'fakeuser'
while pwd.getpwnam(fakename):
    fakename += '1'

Currently, in CPython,

hbina085@akarin-thinkpad ~/g/RustPython (main)> python ggg_nonexisten_user.py                                                                                                                                         (base) 
Traceback (most recent call last):
  File "/home/hbina085/git/RustPython/ggg_nonexisten_user.py", line 4, in <module>
    while pwd.getpwnam(fakename):
          ^^^^^^^^^^^^^^^^^^^^^^
KeyError: "getpwnam(): name not found: 'fakeuser'"

Whereas, in RustPython,

hbina085@akarin-thinkpad ~/g/RustPython (main) [1]> cargo run --release --quiet -- ggg_nonexisten_user.py                                                                                                             (base) 
Traceback (most recent call last):
  File "ggg_nonexisten_user.py", line 4, in <module>
    while pwd.getpwnam(fakename):
FileNotFoundError: (2, 'No such file or directory (os error 2)')

AFAIK, CPython doesn't care what kind of errors happen underneath.
See https://github.com/python/cpython/blob/a42168d316f0c9a4fc5658dab87682dc19054efb/Modules/pwdmodule.c#L270-L279

…of a non-existent user

Signed-off-by: Hanif Ariffin <hanif.ariffin.4326@gmail.com>
@youknowone
Copy link
Member

Thanks. If related tests don't exist in test_pwd, could you add the described test under extra_tests/snippets?

@hbina
Copy link
Contributor Author

hbina commented Mar 30, 2025

Not sure what other tests I can add tbh..

@youknowone
Copy link
Member

youknowone commented Mar 31, 2025

@hbina I added a test file by copying the code you wrote. But when I ran the test on main branch, it didn't fail. That's maybe because I am on mac machine. Could you check if the test I added is failing without your patch on your machine, and add a commit message details that which environment causes that incompatibility?

@hbina
Copy link
Contributor Author

hbina commented Apr 1, 2025

I tested it on a Ubuntu machine in my VirtualBox, the issue happens on the main branch.

I am not sure what you meant by which environment variables.

image

Copy link
Member

@youknowone youknowone left a comment

Choose a reason for hiding this comment

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

Thank you for checking

@youknowone youknowone merged commit 2230d6c into RustPython:main Apr 5, 2025
11 checks passed
@hbina hbina deleted the hbina-fix-test-pathlib-test-expanduser branch April 5, 2025 08:08
Shakil582 pushed a commit to Shakil582/RustPython that referenced this pull request Apr 6, 2025
…duser (RustPython#5578)

* Fix not throwing the same error as CPython when trying to expanduser of a non-existent user

Signed-off-by: Hanif Ariffin <hanif.ariffin.4326@gmail.com>

* add pwd test

* Skip pwd test on windows

---------

Signed-off-by: Hanif Ariffin <hanif.ariffin.4326@gmail.com>
Co-authored-by: Jeong YunWon <jeong@youknowone.org>
Co-authored-by: Jeong, YunWon <69878+youknowone@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.