Commit Graph

106502 Commits

Author SHA1 Message Date
Pablo Galindo 41f0ef6abb bpo-39427: Document -X opt options in the CLI --help and the man page (GH-18131)
https://bugs.python.org/issue39427



Automerge-Triggered-By: @pablogsal
2020-01-22 17:03:04 -08:00
Dino Viehland 9b6fec4651
bpo-39336: Allow packages to not let their child modules be set on them (#18006)
* bpo-39336: Allow setattr to fail on modules which aren't assignable

When attaching a child module to a package if the object in sys.modules raises an AttributeError (e.g. because it is immutable) it causes the whole import to fail.  This now allows immutable packages to exist and an ImportWarning is reported and the AttributeError exception is ignored.
2020-01-22 16:42:38 -08:00
Alex Rebert d3ae95e1e9 bpo-35182: fix communicate() crash after child closes its pipes (GH-17020) (GH-18117)
When communicate() is called in a loop, it crashes when the child process
has already closed any piped standard stream, but still continues to be running

Co-authored-by: Andriy Maletsky <andriy.maletsky@gmail.com>
2020-01-22 15:28:31 -08:00
Dong-hee Na 1f0f102dec bpo-39366: Remove xpath() and xgtitle() methods of NNTP (GH-18035) 2020-01-23 00:59:43 +03:00
Victor Stinner b477d19a6b
bpo-39406: Implement os.putenv() with setenv() if available (GH-18128)
If setenv() C function is available, os.putenv() is now implemented
with setenv() instead of putenv(), so Python doesn't have to handle
the environment variable memory.
2020-01-22 22:48:16 +01:00
Victor Stinner 0852c7dd52
bpo-39406: os.putenv() avoids putenv_dict on Windows (GH-18126)
Windows: _wputenv(env) copies the *env* string and doesn't require
the caller to manage the variable memory.
2020-01-22 21:53:26 +01:00
Victor Stinner b73dd02ea7
Revert "bpo-39413: Implement os.unsetenv() on Windows (GH-18104)" (GH-18124)
This reverts commit 56cd3710a1.
2020-01-22 21:11:17 +01:00
Victor Stinner beea26b57e
bpo-39353: Deprecate the binhex module (GH-18025)
Deprecate binhex4 and hexbin4 standards. Deprecate the binhex module
and the following binascii functions:

* b2a_hqx(), a2b_hqx()
* rlecode_hqx(), rledecode_hqx()
* crc_hqx()
2020-01-22 20:44:22 +01:00
Dong-hee Na 14d80d0b60 bpo-39425: Fix list.count performance regression (GH-18119)
https://bugs.python.org/issue39425



Automerge-Triggered-By: @pablogsal
2020-01-22 09:36:54 -08:00
Inada Naoki 5bbac8cbdf
bpo-39377: json: Update doc about the encoding option. (GH-18076)
Co-authored-by: Kyle Stanley <aeros167@gmail.com>
2020-01-22 19:01:24 +09:00
Dong-hee Na 0d5eac8c32 closes bpo-39415: Remove unused codes from longobject.c complexobject.c floatobject.c. (GH-18105) 2020-01-21 18:49:30 -08:00
Keith Erskine 47be7d0108 PyLong_AsLongLong() docs should say 'long long' (#18082) 2020-01-21 19:14:13 +00:00
Victor Stinner 623ed6171e
bpo-39406: Add PY_PUTENV_DICT macro to posixmodule.c (GH-18106)
Rename posix_putenv_garbage to putenv_dict.
2020-01-21 19:25:32 +01:00
Victor Stinner 56cd3710a1
bpo-39413: Implement os.unsetenv() on Windows (GH-18104)
The os.unsetenv() function is now also available on Windows.

It is implemented with SetEnvironmentVariableW(name, NULL).
2020-01-21 16:13:09 +01:00
Victor Stinner 59e2d26b25
Move test_math tests (GH-18098)
testPerm() and testComb() belong to MathTests, not to IsCloseTests().

test_nextafter() and test_ulp() now use assertIsNaN().
2020-01-21 12:48:16 +01:00
Victor Stinner 629023c05b
bpo-33387: Fix compiler warning in frame_block_unwind() (GH-18099)
Replace int with intptr_t to fix the warning:

    objects\frameobject.c(341): warning C4244: 'initializing':
    conversion from '__int64' to 'int', possible loss of data
2020-01-21 12:47:29 +01:00
William Chargin eab3b3f1c6 bpo-39389: gzip: fix compression level metadata (GH-18077)
As described in RFC 1952, section 2.3.1, the XFL (eXtra FLags) byte of a
gzip member header should indicate whether the DEFLATE algorithm was
tuned for speed or compression ratio. Prior to this patch, archives
emitted by the `gzip` module always indicated maximum compression.
2020-01-21 13:25:24 +02:00
Victor Stinner 85ead4fc62
bpo-39396: Fix math.nextafter(-0.0, +0.0) on AIX 7.1 (GH-18094)
Move also math.nextafter() on math.ulp() tests from IsCloseTests to
MathTests.
2020-01-21 11:14:10 +01:00
Cheryl Sabella ec64640a2c bpo-32989: IDLE - fix bad editor call of pyparse method (GH-5968)
Fix comments and add tests for editor newline_and_indent_event method.
Remove unused None default for function parameter of pyparse find_good_parse_start method
and code triggered by that default.

Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
2020-01-21 05:11:26 -05:00
Carl Friedrich Bolz-Tereick 8698b34b68 improve the documentation of the LOAD_METHOD and CALL_METHOD (GH-18079) 2020-01-21 09:41:16 +09:00
Peter Bittner 8d57a4182f bpo-39383: Mention Darwin as a potential value for platform.system() (GH-18054) 2020-01-20 18:22:56 -05:00
Andrew Svetlov a96e06db77
bpo-39386: Prevent double awaiting of async iterator (GH-18081) 2020-01-21 00:49:30 +02:00
Andrew Svetlov 2c49becc69
Fix asyncio.get_event_loop() documentation (GH-18051)
Mention that the function implicitly creates new event loop only if called from the main thread.
2020-01-21 00:46:38 +02:00
Nick Coghlan 1e420f849d
bpo-35134: Migrate frameobject.h contents to cpython/frameobject.h (GH-18052) 2020-01-21 08:21:35 +10:00
Inada Naoki 5492bfcefe
bpo-39377: json: Remove the encoding option. (GH-18075) 2020-01-20 13:54:00 +09:00
Inada Naoki e96d954527
bpo-38536: locale: Remove trailing space in formatted currency (GH-16864) 2020-01-20 12:45:50 +09:00
Zackery Spytz d8ef64422a bpo-35561: Supress valgrind false alarm on epoll_ctl(event) (GH-18060)
Update Misc/valgrind-python.supp to suppress the false alarm.
2020-01-19 23:38:37 +01:00
Michael Haas 558f078911 Fix typo from base to based (GH-18055) 2020-01-19 05:29:42 -05:00
Pablo Galindo cd7db76a63
bpo-39372: Clean header files of declared interfaces with no implementations (GH-18037)
The public API symbols being removed are:

_PyBytes_InsertThousandsGroupingLocale, _PyBytes_InsertThousandsGrouping, _Py_InitializeFromArgs, _Py_InitializeFromWideArgs, _PyFloat_Repr, _PyFloat_Digits,
_PyFloat_DigitsInit, PyFrame_ExtendStack, _PyAIterWrapper_Type, PyNullImporter_Type, PyCmpWrapper_Type, PySortWrapper_Type, PyNoArgsFunction.
2020-01-18 03:14:59 +00:00
Pablo Galindo 6aabb63d96
Run doctests in GitHub actions Docs targer (GH-18041) 2020-01-17 23:44:38 +00:00
Grant Jenks ef8844f1bc Fix Lock.locked() to remove extra bold highlighting (#18042) 2020-01-17 14:54:44 -08:00
Victor Stinner 1d3b0aaa54
bpo-39356, zipfile: Remove code handling DeprecationWarning (GH-18027)
Remove old "except DeprecationWarning:" code path added by
commit bf02e3bb21. It's no longer
needed.

struct.pack() no longer emit DeprecationWarning if getting a float
whereas an integer is expected. It now raises an hard error instead.
2020-01-17 15:17:48 +01:00
Victor Stinner 10fd6b2b9f
bpo-39357: Update bz2 docstring: remove buffering (GH-18036)
Thanks Karthikeyan Singaravelan for the report ;-)
2020-01-17 13:50:39 +01:00
Victor Stinner 9baf242fc7
bpo-39357: Remove buffering parameter of bz2.BZ2File (GH-18028)
Remove the buffering parameter of bz2.BZ2File. Since Python 3.0, it
was ignored and using it was emitting a DeprecationWarning. Pass an
open file object to control how the file is opened.

The compresslevel parameter becomes keyword-only.
2020-01-16 15:33:30 +01:00
Niklas Fiekas c5b79003f5 bpo-31031: Unify duplicate bits_in_digit and bit_length (GH-2866)
Add _Py_bit_length() to unify duplicate bits_in_digit() and bit_length().
2020-01-16 15:09:19 +01:00
Victor Stinner 4691a2f2a2
bpo-39350: Remove deprecated fractions.gcd() (GH-18021)
Remove fractions.gcd() function, deprecated since Python 3.5
(bpo-22486): use math.gcd() instead.
2020-01-16 11:02:51 +01:00
Victor Stinner 210c19e3c5
bpo-39351: Remove base64.encodestring() (GH-18022)
Remove base64.encodestring() and base64.decodestring(), aliases
deprecated since Python 3.1: use base64.encodebytes() and
base64.decodebytes() instead.
2020-01-16 10:24:16 +01:00
Oz N Tiram fad8b5674c bpo-39348: Fix code highlight for the SOCK_NONBLOCK example (GH-18018)
The previous double colon was wrongly place directly after Therefore.
Which produced a block without syntax highlighting. This fixes it
by separating the double colon from the text. As a result, sphinx now
properly highlights the python code.




https://bugs.python.org/issue39348
2020-01-15 15:55:13 -08:00
Daniel Olshansky 01602ae403 bpo-37958: Adding get_profile_dict to pstats (GH-15495)
pstats is really useful or profiling and printing the output of the execution of some block of code, but I've found on multiple occasions when I'd like to access this output directly in an easily usable dictionary on which I can further analyze or manipulate.

The proposal is to add a function called get_profile_dict inside of pstats that'll automatically return this data the data in an easily accessible dict.

The output of the following script:

```
import cProfile, pstats
import pprint
from pstats import func_std_string, f8

def fib(n):
    if n == 0:
        return 0
    if n == 1:
        return 1
    return fib(n-1) + fib(n-2)

pr = cProfile.Profile()
pr.enable()
fib(5)
pr.create_stats()

ps = pstats.Stats(pr).sort_stats('tottime', 'cumtime')

def get_profile_dict(self, keys_filter=None):
    """
        Returns a dict where the key is a function name and the value is a dict
        with the following keys:
            - ncalls
            - tottime
            - percall_tottime
            - cumtime
            - percall_cumtime
            - file_name
            - line_number

        keys_filter can be optionally set to limit the key-value pairs in the
        retrieved dict.
    """
    pstats_dict = {}
    func_list = self.fcn_list[:] if self.fcn_list else list(self.stats.keys())

    if not func_list:
        return pstats_dict

    pstats_dict["total_tt"] = float(f8(self.total_tt))
    for func in func_list:
        cc, nc, tt, ct, callers = self.stats[func]
        file, line, func_name = func
        ncalls = str(nc) if nc == cc else (str(nc) + '/' + str(cc))
        tottime = float(f8(tt))
        percall_tottime = -1 if nc == 0 else float(f8(tt/nc))
        cumtime = float(f8(ct))
        percall_cumtime = -1 if cc == 0 else float(f8(ct/cc))
        func_dict = {
            "ncalls": ncalls,
            "tottime": tottime, # time spent in this function alone
            "percall_tottime": percall_tottime,
            "cumtime": cumtime, # time spent in the function plus all functions that this function called,
            "percall_cumtime": percall_cumtime,
            "file_name": file,
            "line_number": line
        }
        func_dict_filtered = func_dict if not keys_filter else { key: func_dict[key] for key in keys_filter }
        pstats_dict[func_name] = func_dict_filtered

    return pstats_dict

pp = pprint.PrettyPrinter(depth=6)
pp.pprint(get_profile_dict(ps))
```

will produce:

```
{"<method 'disable' of '_lsprof.Profiler' objects>": {'cumtime': 0.0,
                                                      'file_name': '~',
                                                      'line_number': 0,
                                                      'ncalls': '1',
                                                      'percall_cumtime': 0.0,
                                                      'percall_tottime': 0.0,
                                                      'tottime': 0.0},
 'create_stats': {'cumtime': 0.0,
                  'file_name': '/usr/local/Cellar/python/3.7.4/Frameworks/Python.framework/Versions/3.7/lib/python3.7/cProfile.py',
                  'line_number': 50,
                  'ncalls': '1',
                  'percall_cumtime': 0.0,
                  'percall_tottime': 0.0,
                  'tottime': 0.0},
 'fib': {'cumtime': 0.0,
         'file_name': 'get_profile_dict.py',
         'line_number': 5,
         'ncalls': '15/1',
         'percall_cumtime': 0.0,
         'percall_tottime': 0.0,
         'tottime': 0.0},
 'total_tt': 0.0}
 ```

 As an example, this can be used to generate a stacked column chart using various visualization tools which will assist in easily identifying program bottlenecks.



https://bugs.python.org/issue37958



Automerge-Triggered-By: @gpshead
2020-01-15 14:51:54 -08:00
Antoine dc0284ee8f Fix typo in multiprocessing.pool.AsyncResult.successful doc. (GH-17932)
Since 3.7 `successful` raises a `ValueError` as explained in the next text block from the documentation:

_Changed in version 3.7: If the result is not ready, ValueError is raised instead of AssertionError._

No issue associated with this PR.
Should be backported in 3.7 and 3.8.
2020-01-15 12:12:41 -08:00
Ammar Askar e92d39303f Fix compiler warning on Windows (GH-18012)
Python-ast.h contains a macro named Yield that conflicts with the Yield macro
in Windows system headers. While Python-ast.h has an "undef Yield" directive
to prevent this, it means that Python-ast.h must be included before Windows
header files or we run into a re-declaration warning. In commit c96be811fa
an include for pycore_pystate.h was added which indirectly includes Windows
header files. In this commit we re-order the includes to fix this warning.
2020-01-15 10:48:40 -06:00
Victor Stinner e85a305503
bpo-38630: Fix subprocess.Popen.send_signal() race condition (GH-16984)
On Unix, subprocess.Popen.send_signal() now polls the process status.
Polling reduces the risk of sending a signal to the wrong process if
the process completed, the Popen.returncode attribute is still None,
and the pid has been reassigned (recycled) to a new different
process.
2020-01-15 17:38:55 +01:00
Hai Shi ed154c387e bpo-1635741: Port _json extension module to multiphase initialization (PEP 489) (GH-17835) 2020-01-15 17:32:51 +01:00
Victor Stinner 3f12ac18a4
bpo-39164: Fix compiler warning in PyErr_GetExcInfo() (GH-18010)
The function has no return value.
2020-01-15 11:23:25 +01:00
Elena Oat cf288b53e4 Fix AsyncMock base class in the docs (GH-18008) 2020-01-15 09:50:57 +00:00
Karthikeyan Singaravelan 54f743eb31 Improve test coverage for AsyncMock. (GH-17906)
* Add test for nested async decorator patch.
* Add test for side_effect and wraps with a function.
* Add test for side_effect with an exception in the iterable.
2020-01-15 09:49:49 +00:00
Pablo Galindo 45cf5db587
Allow pgen to produce a DOT format dump of the grammar (GH-18005)
Originally suggested by Anthony Shaw.
2020-01-14 22:32:55 +00:00
Dong-hee Na 65a5ce247f bpo-39329: Add timeout parameter for smtplib.LMTP constructor (GH-17998) 2020-01-14 22:42:09 +01:00
Vinay Sajip 7d6378051f
bpo-38901: Allow setting a venv's prompt to the basename of the current directory. (GH-17946)
When a prompt value of '.' is specified, os.path.basename(os.getcwd()) is used to
configure the prompt for the created venv.
2020-01-14 20:49:30 +00:00
Dima 4b0d91aab4 venv: Suppress warning message when bash hashing is disabled. (GH-17966)
When using python's built-in venv activaton script
warnings are printed when hashing is disabled in
bash or zsh, like;

`bash: hash: hashing disabled`

This output is not really useful to the end-user and has
been disabled in `virtualenv` for long.

This commit is based on:
28e85bcd80
2020-01-14 20:47:59 +00:00