Skip to content

Commit fbb1b30

Browse files
authored
Merge branch 'python:main' into mac-info-plist-fix
2 parents 5ef3678 + 6213a51 commit fbb1b30

File tree

6 files changed

+47
-15
lines changed

6 files changed

+47
-15
lines changed

Lib/asyncio/__main__.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,15 @@ def run(self):
8686
global return_code
8787

8888
try:
89-
banner = (
90-
f'asyncio REPL {sys.version} on {sys.platform}\n'
91-
f'Use "await" directly instead of "asyncio.run()".\n'
92-
f'Type "help", "copyright", "credits" or "license" '
93-
f'for more information.\n'
94-
)
95-
96-
console.write(banner)
89+
if not sys.flags.quiet:
90+
banner = (
91+
f'asyncio REPL {sys.version} on {sys.platform}\n'
92+
f'Use "await" directly instead of "asyncio.run()".\n'
93+
f'Type "help", "copyright", "credits" or "license" '
94+
f'for more information.\n'
95+
)
96+
97+
console.write(banner)
9798

9899
if startup_path := os.getenv("PYTHONSTARTUP"):
99100
sys.audit("cpython.run_startup", startup_path)

Lib/pdb.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -391,17 +391,22 @@ def __init__(self, completekey='tab', stdin=None, stdout=None, skip=None,
391391
# Read ~/.pdbrc and ./.pdbrc
392392
self.rcLines = []
393393
if readrc:
394+
home_rcfile = os.path.expanduser("~/.pdbrc")
395+
local_rcfile = os.path.abspath(".pdbrc")
396+
394397
try:
395-
with open(os.path.expanduser('~/.pdbrc'), encoding='utf-8') as rcFile:
396-
self.rcLines.extend(rcFile)
397-
except OSError:
398-
pass
399-
try:
400-
with open(".pdbrc", encoding='utf-8') as rcFile:
401-
self.rcLines.extend(rcFile)
398+
with open(home_rcfile, encoding='utf-8') as rcfile:
399+
self.rcLines.extend(rcfile)
402400
except OSError:
403401
pass
404402

403+
if local_rcfile != home_rcfile:
404+
try:
405+
with open(local_rcfile, encoding='utf-8') as rcfile:
406+
self.rcLines.extend(rcfile)
407+
except OSError:
408+
pass
409+
405410
self.commands = {} # associates a command list to breakpoint numbers
406411
self.commands_defining = False # True while in the process of defining
407412
# a command list

Lib/test/test_pdb.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4093,6 +4093,23 @@ def test_readrc_homedir(self):
40934093
f.write("invalid")
40944094
self.assertEqual(pdb.Pdb().rcLines[0], "invalid")
40954095

4096+
def test_readrc_current_dir(self):
4097+
with os_helper.temp_cwd() as cwd:
4098+
rc_path = os.path.join(cwd, ".pdbrc")
4099+
with open(rc_path, "w") as f:
4100+
f.write("invalid")
4101+
self.assertEqual(pdb.Pdb().rcLines[-1], "invalid")
4102+
4103+
def test_readrc_cwd_is_home(self):
4104+
with os_helper.EnvironmentVarGuard() as env:
4105+
env.unset("HOME")
4106+
with os_helper.temp_cwd() as cwd, patch("os.path.expanduser"):
4107+
rc_path = os.path.join(cwd, ".pdbrc")
4108+
os.path.expanduser.return_value = rc_path
4109+
with open(rc_path, "w") as f:
4110+
f.write("invalid")
4111+
self.assertEqual(pdb.Pdb().rcLines, ["invalid"])
4112+
40964113
def test_header(self):
40974114
stdout = StringIO()
40984115
header = 'Nobody expects... blah, blah, blah'

Lib/test/test_repl.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,12 @@ def test_toplevel_contextvars_async(self):
409409
expected = "toplevel contextvar test: ok"
410410
self.assertIn(expected, output, expected)
411411

412+
def test_quiet_mode(self):
413+
p = spawn_repl("-q", "-m", "asyncio", custom=True)
414+
output = kill_python(p)
415+
self.assertEqual(p.returncode, 0)
416+
self.assertEqual(output[:3], ">>>")
417+
412418

413419
if __name__ == "__main__":
414420
unittest.main()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix issue where ``pdb`` would read a ``.pdbrc`` twice if launched from the home directory
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
The :mod:`asyncio` REPL no longer prints copyright and version messages in
2+
the quiet mode (:option:`-q`). Patch by Bartosz Sławecki.

0 commit comments

Comments
 (0)