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-80744: pdb: do not read .pdbrc twice when in $HOME #12731

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

Conversation

blueyed
Copy link
Contributor

@blueyed blueyed commented Apr 8, 2019

Copy link
Member

@tirkarthi tirkarthi left a comment

Choose a reason for hiding this comment

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

Perhaps add a test case for this? Please add a NEWS entry since this is change in behavior.

diff --git a/Lib/test/test_pdb.py b/Lib/test/test_pdb.py
index 56d8232495..bc10ff3b91 100644
--- a/Lib/test/test_pdb.py
+++ b/Lib/test/test_pdb.py
@@ -1337,6 +1337,33 @@ class PdbTestCase(unittest.TestCase):
             if save_home is not None:
                 os.environ['HOME'] = save_home

+    def test_readrc_home_twice(self):
+        script = textwrap.dedent("""
+            import pdb; pdb.Pdb(readrc=True).set_trace()
+
+            print('hello')
+        """)
+
+        with support.temp_cwd() as cur_dir:
+            with patch.dict(os.environ, {'HOME': cur_dir}):
+                with open('.pdbrc', 'w') as f:
+                    f.write("invalid\n")
+
+                with open('main.py', 'w') as f:
+                    f.write(script)
+
+                cmd = [sys.executable, 'main.py']
+                proc = subprocess.Popen(
+                    cmd,
+                    stdout=subprocess.PIPE,
+                    stdin=subprocess.PIPE,
+                    stderr=subprocess.PIPE,
+                )
+                with proc:
+                    stdout, stderr = proc.communicate(b'q\n')
+                    output = stdout.decode()
+                    self.assertEqual(output.count('NameError'), 1)
+
     def test_header(self):
         stdout = StringIO()
         header = 'Nobody expects... blah, blah, blah'

Test without patch :

➜  cpython git:(master) ✗ git checkout master Lib/pdb.py
➜  cpython git:(master) ✗ ./python.exe -m test --fail-env-changed -uall test_pdb
Run tests sequentially
0:00:00 load avg: 3.10 [1/1] test_pdb
test test_pdb failed -- Traceback (most recent call last):
  File "/Users/karthikeyansingaravelan/stuff/python/cpython/Lib/test/test_pdb.py", line 1365, in test_readrc_home_twice
    self.assertEqual(output.count('NameError'), 1)
AssertionError: 2 != 1

test_pdb failed

== Tests result: FAILURE ==

1 test failed:
    test_pdb

Total duration: 3 sec 249 ms
Tests result: FAILURE

Test with patch :

➜  cpython git:(master) ✗ git checkout pr_12731 Lib/pdb.py
➜  cpython git:(master) ✗ ./python.exe -m test --fail-env-changed -uall test_pdb
Run tests sequentially
0:00:00 load avg: 2.93 [1/1] test_pdb

== Tests result: SUCCESS ==

1 test OK.

Total duration: 3 sec 226 ms
Tests result: SUCCESS

@blueyed
Copy link
Contributor Author

blueyed commented Apr 8, 2019

@tirkarthi
Thanks for the review and test!
Feel free to push it here already - otherwise I will do so tomorrow probably.

@tirkarthi
Copy link
Member

I am not sure I have the required access to push to a PR or maybe I am missing something in workflow. Feel free to use the test as part of next commit as needed 👍

@@ -162,18 +162,18 @@ def __init__(self, completekey='tab', stdin=None, stdout=None, skip=None,
# Read $HOME/.pdbrc and ./.pdbrc
self.rcLines = []
if readrc:
readrcFiles = []
Copy link
Contributor

Choose a reason for hiding this comment

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

Small neat: please use name_with_underscores instead of camelCase

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@asvetlov
I've tried to keep the style of the other vars there.
Can change it, but want to make sure it is really wanted.

Copy link
Contributor

Choose a reason for hiding this comment

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

self.rcLines exists starting from 2001.
Too late to change the name, it is a part of public API for good or for bad.
But for new variables better to follow PEP 8 style.

@bedevere-bot
Copy link

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@matrixise matrixise self-assigned this Sep 13, 2019
@saucoide
Copy link
Contributor

@blueyed is this abandoned?

@picnixz picnixz changed the title bpo-36563: pdb: do not read .pdbrc twice when in $HOME gh-80744: pdb: do not read .pdbrc twice when in $HOME Mar 22, 2025
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.

None yet

8 participants