From 645005e947c13c4a0706310a2a46112bf63cadc0 Mon Sep 17 00:00:00 2001 From: Andrey Doroschenko Date: Sun, 17 Nov 2019 17:08:31 +0300 Subject: bpo-38724: Implement subprocess.Popen.__repr__ (GH-17151) --- Lib/subprocess.py | 9 ++++++++ Lib/test/test_subprocess.py | 24 ++++++++++++++++++++++ .../2019-11-14-14-13-29.bpo-38724.T5ySfR.rst | 1 + 3 files changed, 34 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2019-11-14-14-13-29.bpo-38724.T5ySfR.rst diff --git a/Lib/subprocess.py b/Lib/subprocess.py index b5a45d9..ba6f198 100644 --- a/Lib/subprocess.py +++ b/Lib/subprocess.py @@ -978,6 +978,15 @@ class Popen(object): raise + def __repr__(self): + obj_repr = ( + f"<{self.__class__.__name__}: " + f"returncode: {self.returncode} args: {list(self.args)!r}>" + ) + if len(obj_repr) > 80: + obj_repr = obj_repr[:76] + "...>" + return obj_repr + @property def universal_newlines(self): # universal_newlines as retained as an alias of text_mode for API diff --git a/Lib/test/test_subprocess.py b/Lib/test/test_subprocess.py index 9e96a6d..97dc09c 100644 --- a/Lib/test/test_subprocess.py +++ b/Lib/test/test_subprocess.py @@ -1360,6 +1360,30 @@ class ProcessTestCase(BaseTestCase): self.addCleanup(p.stdin.close) p.communicate(b"x" * 2**20) + def test_repr(self): + # Run a command that waits for user input, to check the repr() of + # a Proc object while and after the sub-process runs. + code = 'import sys; input(); sys.exit(57)' + cmd = [sys.executable, '-c', code] + result = "') + ) + + proc.communicate(input='exit...\n') + proc.wait() + + self.assertIsNotNone(proc.returncode) + self.assertTrue( + repr(proc).startswith(result.format(proc.returncode)) and + repr(proc).endswith('>') + ) + def test_communicate_epipe_only_stdin(self): # Issue 10963: communicate() should hide EPIPE p = subprocess.Popen(ZERO_RETURN_CMD, diff --git a/Misc/NEWS.d/next/Library/2019-11-14-14-13-29.bpo-38724.T5ySfR.rst b/Misc/NEWS.d/next/Library/2019-11-14-14-13-29.bpo-38724.T5ySfR.rst new file mode 100644 index 0000000..a5ebfb3 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2019-11-14-14-13-29.bpo-38724.T5ySfR.rst @@ -0,0 +1 @@ +Add a repr for ``subprocess.Popen`` objects. Patch by Andrey Doroschenko. \ No newline at end of file -- cgit v0.12 library/tzdata/Atlantic/Stanley | 3 +- library/tzdata/Europe/Istanbul | 3 +- library/tzdata/Pacific/Apia | 2 +- library/tzdata/Pacific/Easter | 4 +- library/tzdata/Pacific/Honolulu | 8 +- libtommath/bn_mp_div_d.c | 2 +- libtommath/bn_mp_montgomery_setup.c | 2 +- libtommath/bn_mp_prime_next_prime.c | 2 +- libtommath/bn_mp_shrink.c | 11 +- libtommath/changes.txt | 14 + libtommath/etc/drprimes.txt | 11 +- libtommath/makefile | 7 +- libtommath/makefile.shared | 2 +- libtommath/pre_gen/mpi.c | 24 +- macosx/README | 11 +- macosx/tclMacOSXFCmd.c | 6 +- tests/namespace.test | 23 +- tests/parse.test | 12 + tests/string.test | 11 +- tools/configure | 266 ++++--- tools/genStubs.tcl | 2 +- tools/tclZIC.tcl | 3 + unix/.cvsignore | 7 - unix/Makefile.in | 5 +- unix/README | 5 - unix/configure | 45 +- unix/configure.in | 8 +- unix/dltest/.cvsignore | 5 - unix/ldAix | 2 +- unix/tcl.m4 | 49 +- unix/tclLoadDl.c | 20 +- unix/tclLoadDyld.c | 10 +- unix/tclUnixFile.c | 2 +- unix/tclUnixInit.c | 10 + unix/tclUnixThrd.c | 2 +- unix/tclUnixTime.c | 28 +- win/.cvsignore | 27 - win/README | 3 - win/configure | 71 +- win/configure.in | 19 + win/makefile.vc | 19 +- win/rules.vc | 87 +-- win/tcl.m4 | 2 +- win/tclWinFile.c | 5 +- win/tclWinPort.h | 25 + 95 files changed, 3076 insertions(+), 1607 deletions(-) create mode 100644 library/tzdata/America/Metlakatla create mode 100644 library/tzdata/America/North_Dakota/Beulah create mode 100644 library/tzdata/America/Sitka delete mode 100644 unix/.cvsignore delete mode 100644 unix/dltest/.cvsignore delete mode 100644 win/.cvsignore diff --git a/ChangeLog b/ChangeLog index e33ff69..74d5613 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,262 @@ +2011-05-09 Don Porter + + * generic/tclListObj.c: Revise empty string tests so that we avoid + potentially expensive string rep generations, especially for dicts. + +2011-05-07 Miguel Sofer + + * generic/tclInt.h: fix USE_TCLALLOC so that it can be enabled + * unix/Makefile.in: without editing the Makefile + +2011-05-05 Don Porter + + * generic/tclListObj.c: Stop generating string rep of dict when + converting to list. Tolerate NULL interps more completely. + +2011-05-03 Don Porter + + * generic/tclUtil.c: Tighten Tcl_SplitList(). + * generic/tclListObj.c: Tighten SetListFromAny(). + * generic/tclDictObj.c: Tighten SetDictFromAny(). + +2011-05-02 Don Porter + + * generic/tclCmdMZ.c: Revised TclFindElement() interface. The + * generic/tclDictObj.c: final argument had been bracePtr, the address + * generic/tclListObj.c: of a boolean var, where the caller can be told + * generic/tclParse.c: whether or not the parsed list element was + * generic/tclUtil.c: enclosed in braces. In practice, no callers + really care about that. What the callers really want to know is + whether the list element value exists as a literal substring of the + string being parsed, or whether a call to TclCopyAndCollpase() is + needed to produce the list element value. Now the final argument + is changed to do what callers actually need. This is a better fit + for the calls in tclParse.c, where now a good deal of post-processing + checking for "naked backslashes" is no longer necessary. + ***POTENTIAL INCOMPATIBILITY*** + For any callers calling in via the internal stubs table who really + do use the final argument explicitly to check for the enclosing brace + scenario. Simply looking for the braces where they must be is the + revision available to those callers, and it will backport cleanly. + + * tests/parse.test: Tests for expanded literals quoting detection. + + * generic/tclCompCmds.c: New TclFindElement() is also a better + fit for the [switch] compiler. + + * generic/tclInt.h: Replace TclCountSpaceRuns() with + * generic/tclListObj.c: TclMaxListLength() which is the function we + * generic/tclUtil.c: actually want. + * generic/tclCompCmds.c: + + * generic/tclCompCmds.c: Rewrite of parts of the switch compiler to + better use the powers of TclFindElement() and do less parsing on + its own. + +2011-04-28 Don Porter + + * generic/tclInt.h: New utility routines: + * generic/tclParse.c: TclIsSpaceProc() and + * generic/tclUtil.c: TclCountSpaceRuns() + + * generic/tclCmdMZ.c: Use new routines to replace calls to + * generic/tclListObj.c: isspace() and their /* INTL */ risk. + * generic/tclStrToD.c: + * generic/tclUtf.c: + * unix/tclUnixFile.c: + +2011-04-27 Don Porter + + * generic/tclListObj.c: FreeListInternalRep() cleanup. + + * generic/tclBinary.c: Backport fix for [Bug 2857044]. + * generic/tclDictObj.c: All freeIntRepProcs set typePtr to NULL. + * generic/tclEncoding.c: + * generic/tclIndexObj.c: + * generic/tclListObj.c: + * generic/tclNamesp.c: + * generic/tclObj.c: + * generic/tclPathObj.c: + * generic/tclProc.c: + * generic/tclRegexp.c: + * generic/tclStringObj.c: + * generic/tclVar.c: + +2011-04-21 Don Porter + + * generic/tclInt.h: Use macro to set List intreps. + * generic/tclListObj.c: + + * generic/tclCmdIL.c: Limits on list length were too strict. + * generic/tclInt.h: Revised panics to errors where possible. + * generic/tclListObj.c: + + * generic/tclCompile.c: Make sure SetFooFromAny routines react + * generic/tclIO.c: reasonably when passed a NULL interp. + * generic/tclIndexObj.c: + * generic/tclListObj.c: + * generic/tclNamesp.c: + * generic/tclObj.c: + * generic/tclProc.c: + * macosx/tclMacOSXFCmd.c: + +2011-04-21 Jan Nijtmans + + * generic/tcl.h: fix for [Bug 3288345]: Wrong Tcl_StatBuf + * generic/tclInt.h: used on MinGW. Make sure that all _WIN32 + * win/tclWinFile.c: compilers use exactly the same layout + * win/configure.in: for Tcl_StatBuf - the one used by MSVC6 - + * win/configure: in all situations. + +2011-04-20 Andreas Kupries + + * generic/tclFCmd.c (TclFileAttrsCmd): Added commands to reset the + typePtr of the Tcl_Obj* whose int-rep was just purged. Required to + prevent a dangling IndexRep* to reused, smashing the heap. See + also the entries at 2011-04-16 and 2011-03-24 for the history of + the problem. + +2011-04-19 Don Porter + + * generic/tclConfig.c: Reduce internals access in the implementation + of [::pkgconfig list]. + +2011-04-18 Don Porter + + * generic/tclCmdIL.c: Use ListRepPtr(.) and other cleanup. + * generic/tclConfig.c: + * generic/tclListObj.c: + + * generic/tclInt.h: Define and use macros that test whether + * generic/tclBasic.c: a Tcl list value is canonical. + * generic/tclUtil.c: + +2011-04-16 Donal K. Fellows + + * generic/tclFCmd.c (TclFileAttrsCmd): Tidied up the memory management + a bit to try to ensure that the dynamic and static cases don't get + confused while still promoting caching where possible. Added a panic + to trap problems in the case where an extension is misusing the API. + +2011-04-13 Don Porter + + * generic/tclUtil.c: [Bug 3285375]: Rewrite of Tcl_Concat*() + routines to prevent segfaults on buffer overflow. Build them out of + existing primitives already coded to handle overflow properly. Uses + the new TclTrim*() routines. + + * generic/tclCmdMZ.c: New internal utility routines TclTrimLeft() + * generic/tclInt.h: and TclTrimRight(). Refactor the + * generic/tclUtil.c: [string trim*] implementations to use them. + +2011-04-13 Miguel Sofer + + * generic/tclVar.c: [Bug 2662380]: Fix crash caused by appending to a + variable with a write trace that unsets it. + +2011-04-12 Don Porter + + * generic/tclStringObj.c: [Bug 3285472]: Repair corruption in + * tests/string.test: [string reverse] when string rep invalidation + failed to also reset the bytes allocated for string rep to zero. + +2011-04-12 Venkat Iyer + + * library/tzdata/Atlantic/Stanley: Update to Olson tzdata2011f + +2011-04-06 Miguel Sofer + + * generic/tclExecute.c (TclCompEvalObj): Earlier return if Tip280 + gymnastics not needed. + +2011-04-05 Venkat Iyer + + * library/tzdata/Africa/Casablanca: Update to Olson's tzdata2011e + * library/tzdata/America/Santiago: + * library/tzdata/Pacific/Easter: + * library/tzdata/America/Metlakatla: (new) + * library/tzdata/America/North_Dakota/Beulah: (new) + * library/tzdata/America/Sitka: (new) + +2011-04-04 Don Porter + + * README: Updated README files, repairing broken URLs and + * macosx/README: removing other bits that were clearly wrong. + * unix/README: Still could use more eyeballs on the detailed build + * win/README: advice on various plaforms. [Bug 3202030] + +2011-04-02 Kevin B. Kenny + + * generic/tclStrToD.c (QuickConversion): Replaced another couple of + 'double' declarations with 'volatile double' to work around + misrounding issues in mingw-gcc 3.4.5. + +2011-03-24 Donal K. Fellows + + * generic/tclFCmd.c (TclFileAttrsCmd): Ensure that any reference to + temporary index tables is squelched immediately rather than hanging + around to trip us up in the future. + +2011-03-21 Jan Nijtmans + + * unix/tclLoadDl.c: [Bug #3216070]: Loading extension libraries + * unix/tclLoadDyld.c: from embedded Tcl applications. + +2011-03-16 Jan Nijtmans + + * generic/tclCkalloc.c: [Bug #3197864]: pointer truncation on Win64 + TCL_MEM_DEBUG builds + +2011-03-16 Don Porter + + * generic/tclBasic.c: Some rewrites to eliminate calls to + * generic/tclParse.c: isspace() and their /* INTL */ risk. + * generic/tclProc.c: + +2011-03-16 Jan Nijtmans + + * unix/tcl.m4: Make SHLIB_LD_LIBS='${LIBS}' the default and + * unix/configure: set to "" on per-platform necessary basis. + Backported from TEA, but kept all original platform code which was + removed from TEA. + +2011-03-14 Kevin B. Kenny + + * tools/tclZIC.tcl (onDayOfMonth): Allow for leading zeroes + in month and day so that tzdata2011d parses correctly. + * library/tzdata/America/Havana: + * library/tzdata/America/Juneau: + * library/tzdata/America/Santiago: + * library/tzdata/Europe/Istanbul: + * library/tzdata/Pacific/Apia: + * library/tzdata/Pacific/Easter: + * library/tzdata/Pacific/Honolulu: tzdata2011d + + + * unix/configure.in [Bug 3205320]: stack space detection defeated by inlining + * unix/configure: (autoconf-2.59) + +2011-03-09 Don Porter + + * generic/tclNamesp.c: Tighten the detector of nested [namespace code] + * tests/namespace.test: quoting that the quoted scripts function + properly even in a namespace that contains a custom "namespace" + command. [Bug 3202171] + + * doc/tclvars.n: Formatting fix. Thanks to Pat Thotys. + +2011-03-08 Jan Nijtmans + + * generic/tclBasic.c: Fix gcc warnings: variable set but not used + +2011-03-08 Don Porter + + * generic/tclInt.h: Remove TclMarkList() routine, an experimental + * generic/tclUtil.c: dead-end from the 8.5 alpha days. + + * generic/tclResult.c (ResetObjResult): Correct failure to clear + invalid intrep. Thanks to Colin McDonald. [Bug 3202905] + 2011-03-06 Don Porter * generic/tclBasic.c: More replacements of Tcl_UtfBackslash() calls diff --git a/README b/README index 7693034..5a65698 100644 --- a/README +++ b/README @@ -1,6 +1,5 @@ README: Tcl This is the Tcl 8.5.9 source distribution. - Tcl/Tk is also available through NetCVS: http://tcl.sourceforge.net/ You can get any source release of Tcl from the file distributions link at the above URL. @@ -12,10 +11,10 @@ Contents 3. Compiling and installing Tcl 4. Development tools 5. Tcl newsgroup - 6. Tcl contributed archive - 7. Tcl Resource Center - 8. Mailing lists - 9. Support and Training + 6. The Tcler's Wiki +