[issue33053] Avoid adding an empty directory to sys.path when running a module with `-m`

2018-03-19 Thread Eryk Sun

Eryk Sun  added the comment:

> the way `python -m pip` searches for the module to execute is much 
> closer to the way Windows searches for a command like `pip` (i.e. 
> current directory first)

That's classic Windows behavior. However, search paths for CreateProcess and 
the loader are composed on demand, which allows different behavior to be 
selected easily enough. The current behavior depends on a mix of environment 
variables, registry settings, reserved names (known DLLs, API sets), 
application and DLL manifests, .local redirection, and in-process 
configuration. For example, to skip the working directory when searching for 
DLLs, there's the CWDIllegalInDllSearch registry setting, 
SetDllDirectoryW(L""), or SetDefaultDllDirectories (the latter removes PATH as 
well, so it's not suited for loosely-couple systems). To skip  the working 
directory when searching for executables, define the environment variable 
"NoDefaultCurrentDirectoryInExePath".

--
nosy: +eryksun

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33089] Add multi-dimensional Euclidean distance function to the math module

2018-03-19 Thread Tim Peters

Tim Peters  added the comment:

Mark, how about writing a clever single-rounding dot product that merely 
_detects_ when it encounters troublesome cases?  If so, it can fall back to a 
(presumably) much slower method.  For example, like this for the latter:

def srdp(xs, ys):
"Single rounding dot product."
import decimal
from decimal import Decimal, Inexact
# XXX check that len(xs) == len(ys)
with decimal.localcontext(decimal.ExtendedContext) as ctx:
ctx.traps[Inexact] = True
total = Decimal(0)
for x, y in zip(map(Decimal, xs), map(Decimal, ys)):
while True:
try:
total += x * y
break
except Inexact:
ctx.prec += 1
return float(total)

So it just converts everything to Decimal; relies on decimal following all the 
IEEE rules for special cases; retries the arithmetic boosting precision until 
decimal gets an exact result (which it eventually will since we're only doing + 
and *); and relies on float() to get everything about final rounding, overflow, 
and denorms right.  If that doesn't work, I'd say it's a bug in the decimal 
module ;-)

I'd bet a dollar that, in real life, falling back to this would almost never 
happen, outside of test cases.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33100] dataclasses and __slots__ - non-default argument (member_descriptor)

2018-03-19 Thread Eric V. Smith

Change by Eric V. Smith :


--
resolution:  -> fixed
stage: patch review -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33100] dataclasses and __slots__ - non-default argument (member_descriptor)

2018-03-19 Thread Eric V. Smith

Eric V. Smith  added the comment:


New changeset 3d41f482594b6aab12a316202b3c06757262109a by Eric V. Smith (Miss 
Islington (bot)) in branch '3.7':
bpo-33100: Dataclasses now handles __slots__ and default values correctly. 
(GH-6152) (GH-6153)
https://github.com/python/cpython/commit/3d41f482594b6aab12a316202b3c06757262109a


--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33094] dataclasses: ClassVar attributes are not working properly

2018-03-19 Thread Eric V. Smith

Eric V. Smith  added the comment:

Are there any remaining issues here? If not, I'm going to close this issue.

--
status: open -> pending

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33105] os.path.isfile returns false on Windows when file path is longer than 260 characters

2018-03-19 Thread Eryk Sun

Eryk Sun  added the comment:

> If you use os.listdir() on the networked folder, the log file 
> will come up.

Querying a file's parent directory (e.g. via os.scandir in Python 3) can 
provide a basic stat (i.e. attributes, reparse tag, size, and timestamps) when 
opening the file directly fails. Currently the os.[l]stat implementation in 
Python 3 falls back on querying the directory for ERROR_ACCESS_DENIED (e.g. due 
to a file's security, delete disposition, or an exclusive open) and 
ERROR_SHARING_VIOLATION (e.g. a system paging file). 

This could be expanded to ERROR_PATH_NOT_FOUND, which among other reasons, can 
indicate the path was too long if long-path support isn't available. This would 
expand the reach to all files in which the path of the parent directory is less 
than MAX_PATH. This would keep os.[l]stat consistent with os.listdir and 
os.scandir, which it currently is not. For example:

>>> parent_path, filename = os.path.split(path)
>>> len(path), len(parent_path), filename
(264, 255, 'spam.txt')

>>> os.path.exists(path)
False
>>> entry = next(os.scandir(parent_path))
>>> entry.name
'spam.txt'
>>> entry.stat()
os.stat_result(st_mode=33206, st_ino=0, st_dev=0, st_nlink=0,
   st_uid=0, st_gid=0, st_size=0, st_atime=1521507879,
   st_mtime=1521507879, st_ctime=1521507879)

--
components: +Windows
stage:  -> needs patch
versions: +Python 3.8

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33103] Syntax to get multiple arbitrary items from an iterable

2018-03-19 Thread Raymond Hettinger

Raymond Hettinger  added the comment:

FWIW, there is already a way to do this but it involves the extra step of 
applying map() to a bound method:

>>> my_list = ["John", "Richard", "Alice", 1, True, 2.1, "End"]
>>> a, b, c = map(my_list.__getitem__, [1, 3, -1])
>>> a
'Richard'
>>> b
1
>>> c
'End'

--
nosy: +rhettinger

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1467929] %-formatting and dicts

2018-03-19 Thread Eric V. Smith

Change by Eric V. Smith :


--
assignee: eric.smith -> 

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33100] dataclasses and __slots__ - non-default argument (member_descriptor)

2018-03-19 Thread Eric V. Smith

Eric V. Smith  added the comment:


New changeset 7389fd935c95b4b6f094312294e703ee0de18719 by Eric V. Smith in 
branch 'master':
bpo-33100: Dataclasses now handles __slots__ and default values correctly. 
(GH-6152)
https://github.com/python/cpython/commit/7389fd935c95b4b6f094312294e703ee0de18719


--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33100] dataclasses and __slots__ - non-default argument (member_descriptor)

2018-03-19 Thread miss-islington

Change by miss-islington :


--
pull_requests: +5911

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33105] os.path.isfile returns false on Windows when file path is longer than 260 characters

2018-03-19 Thread Eryk Sun

Eryk Sun  added the comment:

Python 2.7 is all but set in stone. Changes to its behavior have to correct 
serious bugs, not work around limits in an OS. You can do that yourself. For 
example, use an extended local-device path, i.e. a path that's prefixed by 
u"?\\". This path type must be unicode, fully-qualified, and use only 
backslash as the path separator. Also, the UNC device has to be used 
explicitly. Python 2 has poor support for unicode raw strings (\u and \U 
escapes aren't disabled), so you can instead use forward slashes and 
normpath(). For example: 

f1_path = 
os.path.normpath(u"//?/UNC/tst/tc/proj/MTV/cs_fft/Milo/Fries/STL/BLNA/F1") 
log_path = os.path.join(f1_path, log_filename)
assert os.path.isfile(log_path)

--
nosy: +eryksun
title: os.isfile returns false on Windows when file path is longer than 260 
characters -> os.path.isfile returns false on Windows when file path is longer 
than 260 characters

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33100] dataclasses and __slots__ - non-default argument (member_descriptor)

2018-03-19 Thread Eric V. Smith

Change by Eric V. Smith :


--
keywords: +patch
pull_requests: +5910
stage:  -> patch review

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33087] No reliable clean shutdown method

2018-03-19 Thread Brett Cannon

Change by Brett Cannon :


--
type: behavior -> enhancement
versions: +Python 3.8 -Python 2.7, Python 3.4, Python 3.5, Python 3.6, Python 
3.7

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue3405] Add support for the new data option supported by event generate (Tk 8.5)

2018-03-19 Thread Matthias Kievernagel

Change by Matthias Kievernagel :


--
nosy: +mkiever

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33100] dataclasses and __slots__ - non-default argument (member_descriptor)

2018-03-19 Thread Eric V. Smith

Eric V. Smith  added the comment:

Thanks, but I'm already looking at this in the context of a different bug.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33100] dataclasses and __slots__ - non-default argument (member_descriptor)

2018-03-19 Thread Adrian Stachlewski

Adrian Stachlewski  added the comment:

There's also another major problem. Because Base.x has value, __init__ is not 
prepared correctly (member_descriptor is passed as default). 

@dataclass
class Base:
__slots__ = ('x',)
x: Any

Base()  # No TypeError exception

Fixing this should be quite easy, if you want I can prepare PR.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33106] Deleting a key in a read-only gdbm results in KeyError, not gdbm.error

2018-03-19 Thread sds

sds  added the comment:

Same problem with 3.6.4, start with

>>> from dbm import gnu as gdbm

then the same incorrect behavior

--
versions: +Python 3.6 -Python 2.7

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33106] Deleting a key in a read-only gdbm results in KeyError, not gdbm.error

2018-03-19 Thread sds

New submission from sds :

deleting a key from a read-only gdbm should be gdbm.error, not KeyError:


>>> import gdbm
>>> db = gdbm.open("foo","n")   # create new
>>> db["a"] = "b"
>>> db.close()
>>> db = gdbm.open("foo","r")   # read only
>>> db["x"] = "1"
Traceback (most recent call last):
  File "", line 1, in 
gdbm.error: Reader can't store# correct
>>> db["a"]
'b'
>>> del db["a"]
Traceback (most recent call last):
  File "", line 1, in 
KeyError: 'a'# WRONG!  should be the same as above

--
components: Library (Lib)
messages: 314119
nosy: sam-s
priority: normal
severity: normal
status: open
title: Deleting a key in a read-only gdbm results in KeyError, not gdbm.error
type: behavior
versions: Python 2.7

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue31550] Inconsistent error message for TypeError with subscripting

2018-03-19 Thread Raymond Hettinger

Raymond Hettinger  added the comment:

> it's different than python3 (for no good reason?)
Python 3 has new style classes which were always different.

> main concern here is ease in portability  
We've long stated that there should never be dependency on the exact wording of 
an error message.  We're allowed to change that.

> For instance it was consistent in 2.7.1
To the extent we care about this, it is more important to be consistent with 
later releases than earlier releases.

Since I don't see any evidence that there is a real world problem, I would like 
to see this left alone.  At this point, in Python 2.7's life we need to have a 
strong aversion to any changes at all.  Not only has that ship sailed, its 
voyage is almost over.

--
versions: +Python 2.7 -Python 3.7

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue25345] Unable to install Python 3.5 on Windows 10

2018-03-19 Thread Arran McCutcheon

Arran McCutcheon  added the comment:

Yes there have been various Cumulative Updates and Security Updates in the past 
few months, the most recent five days ago. Last features update was 
successfully installed in December. Update Status: Your device is up to date. 
Last checked today, 09:14. 
I certainly agree that it's a machine issue, although it's strange that I'm 
still able to install windows updates, notepads, video editors etc without 
problems. I just tried to install Java - and got a similar error. According to 
the Java error, msiexec.exe is currently processing another installation. It 
seems to only be a problem when attempting to install programming languages. 
Could a clean boot help? I saw that recommended somewhere.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue31550] Inconsistent error message for TypeError with subscripting

2018-03-19 Thread Anthony Sottile

Anthony Sottile  added the comment:

I think the main concern here is ease in portability coupled with the 
incorrectness of the current message (pointed out in 
https://bugs.python.org/issue31550#msg302738)

For instance it was consistent in 2.7.1, but not later on in the 2.7.x tree.  
*And* it's different than python3 (for no good reason?)

The message is misleading as well, it's not looking for __getitem__ on the 
instance but on the type.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue31550] Inconsistent error message for TypeError with subscripting

2018-03-19 Thread Raymond Hettinger

Raymond Hettinger  added the comment:

I would like to leave this as-is.  Consistency between error message wording is 
one of our least important considerations.  The __getitem__ message is somewhat 
useful -- it helps learners know which magic method is being called and what 
they would need to add to a class to make it work.  This was the typical 
wording for old-style classes.  For example, calling len() on an old-style 
class without __len__ gave this message, "AttributeError: A instance has no 
attribute '__len__'".

In addition, we are getting very close to end-of-life for Python2.7.  
Accordingly, any changes at this point should be limited to things that really 
matter.  It will be too easy to introduce a new problem that we won't have an 
opportunity to fix later.

I recommend closing this and shifting attention to things that matter.

--
assignee:  -> rhettinger

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33105] os.isfile returns false on Windows when file path is longer than 260 characters

2018-03-19 Thread Steve Dower

Steve Dower  added the comment:

Given basically every other file operation on Windows XP will also break on 
this file, I don't think it's worth us fixing in 2.7.

If it occurs on Python 3.6 on Windows 7, we can consider it. But considering 
how well known this limitation is (and the workarounds for newer OSs), I don't 
think it's particularly urgent.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33089] Add multi-dimensional Euclidean distance function to the math module

2018-03-19 Thread Tim Peters

Tim Peters  added the comment:

Mark, thanks!  I'm happy with that resolution:  if any argument is infinite, 
return +inf; else if any argument is a NaN, return a NaN; else do something 
useful ;-)

Serhiy, yes, the scaling that prevents catastrophic overflow/underflow due to 
naively squaring unscaled values can introduce small errors of its own.  A 
single-rounding dot product could avoid that, leaving two sources of 
single-rounding errors (the dot product, and the square root).

Raymond, yes, fsum() on its own can reduce errors.  Note that scaling on its 
own can also reduce errors (in particular, when the arguments are all the same, 
they're each scaled to exactly 1.0):

>>> import math
>>> n = 1000
>>> math.sqrt(sum([0.1 ** 2] * n))
3.1622776601683524
>>> math.sqrt(math.fsum([0.1 ** 2] * n))
3.1622776601683795
>>> hypot(*([0.1] * n)) # using the code above
3.1622776601683795
>>> math.sqrt(n) * 0.1
3.1622776601683795

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue25345] Unable to install Python 3.5 on Windows 10

2018-03-19 Thread Steve Dower

Steve Dower  added the comment:

Arran - I think you have something else going wrong with your machine. There is 
nothing we do to cause multiple installs to start at the same time, and if 
rebooting does not help then I have to assume you have some permanently corrupt 
state.

Have you installed Windows Updates recently? I would expect that updates will 
either fail (and may be able to recover better than a 3rd-party installer) or 
succeed and clear the state.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33061] NoReturn missing from __all__ in typing.py

2018-03-19 Thread Ivan Levkivskyi

Ivan Levkivskyi  added the comment:


New changeset 4573820d2a9156346392838d455e89f33067e9dd by Ivan Levkivskyi 
(aetracht) in branch 'master':
bpo-33061: Add missing 'NoReturn' to __all__ in typing.py (GH-6127)
https://github.com/python/cpython/commit/4573820d2a9156346392838d455e89f33067e9dd


--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue25345] Unable to install Python 3.5 on Windows 10

2018-03-19 Thread Arran McCutcheon

Arran McCutcheon  added the comment:

Hi Steve, thanks for the reply. I tried the download again and got the same 
error with a slightly different log file, hopefully that will help identify the 
problem. Apart from that, I don't know of any other Python log files, there's 
no others in the same folder and I can't find others elsewhere. The full error 
message reads: 'Another installation is already in progress. Complete that 
installation before proceeding with this install.'

--
Added file: https://bugs.python.org/file47494/Python 3.6.4 
(64-bit)_20180319182314.log

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33105] os.isfile returns false on Windows when file path is longer than 260 characters

2018-03-19 Thread Ned Deily

Change by Ned Deily :


--
nosy: +paul.moore, steve.dower, tim.golden, zach.ware

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33105] os.isfile returns false on Windows when file path is longer than 260 characters

2018-03-19 Thread Luis Conejo-Alpizar

New submission from Luis Conejo-Alpizar :

Windows has a maximum path length limitation of 260 characters. This 
limitation, however, can be bypassed in the scenario described below. When this 
occurs, os.isfile() will return false, even when the affected file does exist. 
For Windows systems, the behavior should be for os.isfile() to return an 
exception in this case, indicating that maximum path length has been exceeded.

Sample scenario:

1. Let's say you have a folder, named F1 and located in your local machine at 
this path:

C:\tc\proj\MTV\cs_fft\Milo\Fries\STL\BLNA\F1\

2. Inside of that folder, you have a log file with this name:

This_is_a_really_long_file_name_that_by_itself_is_not_capable_of_exceeding_the_path_length_limitation_Windows_has_in_pretty_much_every_single_version_of_Wind.log

3. The combined length of the path and the file is exactly 260 characters, so 
Windows lets you get away with it when the file is initially created and/or 
placed there.

4. Later, you decide to make the F1 folder available on your network, under 
this name:

\\tst\tc\proj\MTV\cs_fft\Milo\Fries\STL\BLNA\F1\

5. Your log file continues to be in the folder, but its full network path is 
now 263 characters, effectively violating the maximum path length limitation.

6. If you use os.listdir() on the networked folder, the log file will come up.

7. Now, if you try os.path.isfile(os.path.join(networked_path,logfile_name)) it 
will return false, even though the file is indeed there and is indeed a file.

--
components: Library (Lib)
messages: 314109
nosy: ldconejo
priority: normal
severity: normal
status: open
title: os.isfile returns false on Windows when file path is longer than 260 
characters
type: behavior
versions: Python 2.7

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue32968] Fraction modulo infinity should behave consistently with other numbers

2018-03-19 Thread Mark Dickinson

Mark Dickinson  added the comment:

> Mark, I tried `Fraction(10**23) // 1e22`, and I got 10.

Sorry: that result was with your PR (as it was at the time I wrote that 
comment). On master, you do indeed get 10.

> I think the fact that floating-point rounding error sometimes causes
> strange results is not a reason to do really unexpected things like
> making 1.0 // 1/10 equal 9.0, if that can be reasonably avoided.

I understand, but I think in this case, the cure is worse than the disease. I 
don't think converting the float to a Fraction in mixed-type operations is 
going to work, for a number of reasons:

- it's changing the behaviour for _all_ the arithmetic operations, not just // 
and %; that widens the scope for accidental breakage. For example, with the 
latest commit 038664e6a6288f6113ab96103e57d3b25b39a8c2 on your PR:

>>> Fraction(1) + math.inf
inf
>>> math.inf + Fraction(1)
Traceback (most recent call last):
  File "", line 1, in 
  File "/Users/mdickinson/Python/cpython/Lib/fractions.py", line 391, in reverse
return float(fallback_operator(Fraction(a), b))
  File "/Users/mdickinson/Python/cpython/Lib/fractions.py", line 130, in __new__
self._numerator, self._denominator = numerator.as_integer_ratio()
OverflowError: cannot convert Infinity to integer ratio

But on master, we have:

>>> import math
>>> from fractions import Fraction
>>> math.inf + Fraction(1)
inf
>>> Fraction(1) + math.inf
inf

- it's counter to the spirit of the numeric tower, where for most arithmetic 
operations, values are propagated _up_ the tower (from Integral -> Rational -> 
Real -> Complex) to the first common type before the operation is performed. 
That keeps things simple; having some cases where values are converted down the 
tower is going to cause confusion. (Comparisons are necessarily a special case: 
the need to preserve transitivity of equality and trichotomy means that using 
the same rules as for arithmetic operations won't fly)

- it introduces a non-obvious difference between mixed-mode Fraction-float and 
int-float operations. For an int x and a float y, I'd expect the result of `x 
 y` to be identical to the result of `Fraction(x)  y`.

So I'm sorry, but I do think having 1.0 // Fraction(1, 10) give 9.0 rather than 
10.0 is the least worst option here. It's a surprise, but it's not a _new_ 
surprise: it's a surprise that's already there in the world of floating-point 
arithmetic.

>>> 1.0 // 0.1
9.0

You're evaluating a discontinuous function _at_ a discontinuity, using a type 
that's known for its inexactness. In that situation, getting the value for 
_either_ side of that discontinuity is reasonable.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33104] Documentation for EXTENDED_ARG in dis module is incorrect for >=3.6

2018-03-19 Thread Eric Appelt

Eric Appelt  added the comment:

Yes, thanks. I failed to see the duplicate searching for open issues, closing.

--
resolution:  -> duplicate
stage:  -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue32625] Update the dis module documentation to reflect switch to wordcode

2018-03-19 Thread Eric Appelt

Change by Eric Appelt :


--
nosy: +Eric Appelt

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue25433] whitespace in strip()/lstrip()/rstrip()

2018-03-19 Thread Cheryl Sabella

Change by Cheryl Sabella :


--
versions: +Python 3.7, Python 3.8 -Python 3.5, Python 3.6

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue31550] Inconsistent error message for TypeError with subscripting

2018-03-19 Thread Anthony Sottile

Anthony Sottile  added the comment:

I made a new PR which instead *reverts* the python2.7 patch to restore 
consistency

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue31550] Inconsistent error message for TypeError with subscripting

2018-03-19 Thread Anthony Sottile

Change by Anthony Sottile :


--
pull_requests: +5909

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19417] Bdb: add a unittest file (test.test_bdb)

2018-03-19 Thread Mariatta Wijaya

Mariatta Wijaya  added the comment:


New changeset 424f3dafea16fbaee55a30903af2d6717f4d4a6b by Mariatta (xdegaye) in 
branch '3.6':
bpo-19417: Add test_bdb.py (GH-5217)
https://github.com/python/cpython/commit/424f3dafea16fbaee55a30903af2d6717f4d4a6b


--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue32756] argparse: parse_known_args: raising exception on unknown arg following known one

2018-03-19 Thread paul j3

paul j3  added the comment:

>From the documentation, 16.4.4.1. Option value syntax

> For short options (options only one character long), the option and its value 
> can be concatenated:

> Several short options can be joined together, using only a single - prefix, 
> as long as only the last option (or none of them) requires a value:

It does not promise that an short option and an unrelated (not-required) value 
will work.  The only value that works in such a construct is one required by 
the last short option.

I think this should be closed, unless you can support your expectations from 
documentation, or examples from other parsers.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33089] Add multi-dimensional Euclidean distance function to the math module

2018-03-19 Thread Mark Dickinson

Mark Dickinson  added the comment:

Okay, that cut and paste didn't work so well. Just imagine an infinity symbol 
in those missing spaces. Trying again:

> For the hypot function, hypot(±0, ±0) is +0, hypot(±∞, qNaN) is +∞, and
> hypot(qNaN, ±∞) is +∞.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33089] Add multi-dimensional Euclidean distance function to the math module

2018-03-19 Thread Mark Dickinson

Mark Dickinson  added the comment:

> By the same logic, if there's an infinite argument to hypot(), it doesn't 
> matter what any other argument is - the result is +inf regardless.

Yep, that's what IEEE 754-2008 says for the two-argument case, so I think 
that's the logic that should be followed in the many-argument case: if any of 
the inputs is an infinity, the output should be infinity.

>From section 9.2.1 of IEEE 754:

> For the hypot function, hypot(±0, ±0) is +0, hypot(± , qNaN) is + , and
> hypot(qNaN, ± ) is + .

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26647] ceval: use Wordcode, 16-bit bytecode

2018-03-19 Thread Serhiy Storchaka

Change by Serhiy Storchaka :


--
pull_requests:  -1041

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33104] Documentation for EXTENDED_ARG in dis module is incorrect for >=3.6

2018-03-19 Thread Serhiy Storchaka

Serhiy Storchaka  added the comment:

Isn't this a duplicate of issue32625?

--
nosy: +serhiy.storchaka

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33104] Documentation for EXTENDED_ARG in dis module is incorrect for >=3.6

2018-03-19 Thread Eric Appelt

New submission from Eric Appelt :

The documentation for the EXTENDED_ARG instruction in the dis module 
documentation refers to the way the opcode worked before 3.6: 
https://docs.python.org/3.6/library/dis.html#opcode-EXTENDED_ARG

As I understand, since moving to 2-byte wordcode in 3.6, each EXTENDED_ARG 
effectively adds a byte to the argument of the next instruction and they can be 
chained to allow up to a 32-bit argument. The current documentation refers the 
2-byte arguments from the older bytecode used in 3.5 and below.

I'm trying to think of a clear and concise wording for how it works now and 
will add a PR to fix this issue unless someone gets to it before me.

--
assignee: docs@python
components: Documentation
messages: 314100
nosy: Eric Appelt, docs@python
priority: normal
severity: normal
status: open
title: Documentation for EXTENDED_ARG in dis module is incorrect for >=3.6
versions: Python 3.6, Python 3.7, Python 3.8

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33089] Add multi-dimensional Euclidean distance function to the math module

2018-03-19 Thread Tim Peters

Tim Peters  added the comment:

Some notes on the hypot() code I pasted in:  first, it has to special case 
infinities too - it works fine if there's only one of 'em, but returns a NaN if 
there's more than one (it ends up computing inf/inf, and the resulting NaN 
propagates).

Second, it's not clear to me what the result "should be" if there's at least 
one infinity _and_ at least one NaN.  At the start, "anything with a NaN input 
returns a NaN" was the rule everything followed.  Later an exception to that 
was made for NaN**0 == 1, under the theory that it didn't really matter if the 
computation of the base screwed up, because anything whatsoever to the 0 power 
is 1 0 viewing NaN as meaning "we have no idea what the true value is", it 
simply doesn't matter what the true value is in this context.  By the same 
logic, if there's an infinite argument to hypot(), it doesn't matter what any 
other argument is - the result is +inf regardless.  So that requires some 
investigation.  Offhand I'm inclined to return NaN anyway.

Finally, if there is a robust single-rounding dot product, of course scaling 
can be skipped (and so eliminate another source of small errors).

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33103] Syntax to get multiple arbitrary items from an iterable

2018-03-19 Thread Serhiy Storchaka

Serhiy Storchaka  added the comment:

This syntax already is supported for dicts and NumPy arrays, but with different 
semantic.

>>> d = {(1, 2): 'foo'}
>>> d[1, 2]
'foo'
>>> a = numpy.array([[1, 2], [3, 4]])
>>> a[1, 0]
3

--
nosy: +serhiy.storchaka
resolution:  -> rejected
stage:  -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33101] Possible name inversion in heapq implementation

2018-03-19 Thread Raymond Hettinger

Raymond Hettinger  added the comment:

There isn't universal agreement on whether it should be sift up or sift down.  
One point of view for sift down is that the datum is moving downward.  The 
other point of view is that the datum is stationary which the rest of the heap 
moves downward (like sifting a ring out of flour).  Different sources make 
different choices in this regard. 


"There is some confusion in the literature on the naming of the siftup/down 
routines. presented above. The routine named siftdown here is called siftdown 
in [1], siftup. in [3], trickledown in [4] and heapify in [5]." -- 
www.diku.dk/~jyrki/PE-lab/Jesper/heaplab/survey.ps.gz

--
nosy: +rhettinger
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33102] get the nth folder of a given path

2018-03-19 Thread Eric V. Smith

Eric V. Smith  added the comment:

Path.parents will do what you want. I don't have a Windows box handy, but this 
is on MacOS:

>>> from pathlib import Path
>>> p = 
>>> Path("/Users/User/AppData/Local/Programs/Python/Python36/Lib/asyncio/__init__.py")
>>> p.parents[1]
PosixPath('/Users/User/AppData/Local/Programs/Python/Python36/Lib')
>>>

--
nosy: +eric.smith

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33103] Syntax to get multiple arbitrary items from an iterable

2018-03-19 Thread amjad ben hedhili

Change by amjad ben hedhili :


--
title: Syntax to get multiple items from an iterable -> Syntax to get multiple 
arbitrary items from an iterable

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33103] Syntax to get multiple items from an iterable

2018-03-19 Thread amjad ben hedhili

New submission from amjad ben hedhili :

It will be much of improvement for readability to write:

my_list = ["John", "Richard", "Alice", 1, True, 2.1, "End"]
a, b, c = my_list[1, 3, -1]

instead of:

my_list = ["John", "Richard", "Alice", 1, True, 2.1, "End"]
a, b, c = my_list[1], my_list[3], my_list[-1]

--
messages: 314095
nosy: amjad ben hedhili
priority: normal
severity: normal
status: open
title: Syntax to get multiple items from an iterable
type: enhancement

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33102] get the nth folder of a given path

2018-03-19 Thread amjad ben hedhili

Change by amjad ben hedhili :


--
title: get the nth folder -> get the nth folder of a given path

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33102] get the nth folder

2018-03-19 Thread amjad ben hedhili

New submission from amjad ben hedhili :

It will be handy if there was an os or os.path function that returns the path 
to the nth directory in a given path

for example:
given path = 
"C:\Users\User\AppData\Local\Programs\Python\Python36\Lib\asyncio\__init__.py"

os.path.nthpath(path, 2) returns 
"C:\Users\User\AppData\Local\Programs\Python\Python36\Lib"

--
messages: 314094
nosy: amjad ben hedhili
priority: normal
severity: normal
status: open
title: get the nth folder
type: enhancement

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33101] Possible name inversion in heapq implementation

2018-03-19 Thread Yomguithereal

New submission from Yomguithereal :

Hello Python team,

I might be hallucinating but I am under the impression that the `heapq` module 
uses reverse naming.

What I mean is that it seems to me that the _siftup method should actually be 
named _siftdown and, the other way around, _siftdown should be named _siftup.

This has absolutely no practical consequence since the module works as it 
should but I am a bit confused since I don't know if the module got naming 
wrong or if it followed another canonical naming I don't know about.

I am willing to open a PR to fix this if the named reverasl was to be confirmed.

Good day to you.

--
components: Library (Lib)
messages: 314093
nosy: Yomguithereal
priority: normal
severity: normal
status: open
title: Possible name inversion in heapq implementation
type: enhancement
versions: Python 3.8

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33053] Avoid adding an empty directory to sys.path when running a module with `-m`

2018-03-19 Thread Nick Coghlan

Nick Coghlan  added the comment:

It occurs to me that there may be some additional unshared context here: the 
way `python -m pip` searches for the module to execute is much closer to the 
way Windows searches for a command like `pip` (i.e. current directory first) 
than it is to the way *nix systems search for it (i.e. if the current directory 
isn't on PATH it must be specified explicitly as "./pip"). If you spend a lot 
of time on Windows systems, or working with Windows users, it becomes a habit 
to assume that folks aren't going to expect it to be safe to run arbitrary 
commands from arbitrary directories.

This behaviour means that if you want to intercept "python -m pip", the current 
easiest filename to use to intercept it is just "pip.py", similar to the way 
you can use "pip.exe"  or "python.exe" to intercept those commands on Windows.

I do think switching from a Windows-style default search behaviour to a *nix 
style default search behaviour is potentially reasonable, but the related 
backwards compatibility considerations would likely push it into being a PEP 
level change.

I'll also note that Nathaniel's right that I was wrong about `sitecustomize` 
always being easy to intercept from the current directory, though, as 
sys.path[0] gets set *after* "import site" has already executed.

I was just confusing myself, as my default approach to double-checking the 
behaviour of the "-m" switch is to run "python -m site", but that's misleading 
in this case since doing that *also* re-runs the site and user customisation 
modules (and will pick them up from the current working directory) - it's 
closely akin to testing `python3 -c "import runpy; runpy.run_module('site', 
run_name='__main__')"`

--
stage:  -> needs patch

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19417] Bdb: add a unittest file (test.test_bdb)

2018-03-19 Thread Xavier de Gaye

Change by Xavier de Gaye :


--
pull_requests: +5908

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33100] dataclasses and __slots__ - non-default argument (member_descriptor)

2018-03-19 Thread Eric V. Smith

Eric V. Smith  added the comment:

My point is that the problem is that after:

@dataclass
class Base:
__slots__ = ('x',)
x: Any

Base.x has a value (it's the member_descriptor for x). That's what's causing 
the problem that when adding a field to the derived class, it thinks you're 
adding a field without a default value after one that has a default value.

I agree that I could detect this specific case and allow it. My comment about 
the error message was inaccurate.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33100] dataclasses and __slots__ - non-default argument (member_descriptor)

2018-03-19 Thread Adrian Stachlewski

Adrian Stachlewski  added the comment:

I don't really get your point. 

@dataclass
class Base:
__slots__ = ('x',)
x: Any

This case is described in PEP 557 as correct, so I don't understand why you 
want to generate error. Also inheritance without defining slots is correct as 
stated in data model. 

In my opinion, member_descriptor should be treated same as MISSING and 
everything should work correctly.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33053] Avoid adding an empty directory to sys.path when running a module with `-m`

2018-03-19 Thread Nathaniel Smith

Nathaniel Smith  added the comment:

Ah, yeah, I see:

~/t$ echo 'print("hi")' > re.py
~/t$ pip --version
pip 9.0.1 from 
/home/njs/.user-python3.5-64bit/local/lib/python3.5/site-packages (python 3.5)
~/t$ python -m pip --version
hi
Traceback (most recent call last):
[...]

But if I create a sitecustomize.py or an io.py in the current directory 
(knowing that 'import io' happens implicitly startup), then those *don't* seem 
to get picked up by 'python -m pip' or 'python -c ...' or plain 'python'. I 
guess the cwd doesn't get added to sys.path until after initial bootstrapping 
is finished.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33053] Avoid adding an empty directory to sys.path when running a module with `-m`

2018-03-19 Thread Antti Haapala

Antti Haapala  added the comment:

Took 2 seconds.

% sudo python3 -mpip --version
hello world
Traceback (most recent call last):
  File "/usr/lib/python3.6/runpy.py", line 183, in _run_module_as_main
mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
  File "/usr/lib/python3.6/runpy.py", line 142, in _get_module_details
return _get_module_details(pkg_main_name, error)
  File "/usr/lib/python3.6/runpy.py", line 109, in _get_module_details
__import__(pkg_name)
  File "/usr/lib/python3/dist-packages/pip/__init__.py", line 4, in 
import locale
  File "/usr/lib/python3.6/locale.py", line 180, in 
_percent_re = re.compile(r'%(?:\((?P.*?)\))?'
AttributeError: module 're' has no attribute 'compile'
Error in sys.excepthook:
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 53, in 
apport_excepthook
if not enabled():
  File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 28, in 
enabled
return re.search(r'^\s*enabled\s*=\s*0\s*$', conf, re.M) is None
AttributeError: module 're' has no attribute 'search'

Original exception was:
Traceback (most recent call last):
  File "/usr/lib/python3.6/runpy.py", line 183, in _run_module_as_main
mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
  File "/usr/lib/python3.6/runpy.py", line 142, in _get_module_details
return _get_module_details(pkg_main_name, error)
  File "/usr/lib/python3.6/runpy.py", line 109, in _get_module_details
__import__(pkg_name)
  File "/usr/lib/python3/dist-packages/pip/__init__.py", line 4, in 
import locale
  File "/usr/lib/python3.6/locale.py", line 180, in 
_percent_re = re.compile(r'%(?:\((?P.*?)\))?'
AttributeError: module 're' has no attribute 'compile'

Same for `python -mhttp.server`, say. 



I'd prefer there be a change that the default be always safe from some version 
on, so that the REPL can do whatever it does, but `-m` etc probably shouldn't 
even have neither the *initial* current directory *nor* the current current 
directory in the path unless the interactive session is requested. I am not 
worried about the garbage that the user would have installed in their own 
directories breaking things.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33100] dataclasses and __slots__ - non-default argument (member_descriptor)

2018-03-19 Thread Eric V. Smith

Eric V. Smith  added the comment:

This is the same reason that this fails:

class Base:
__slots__ = ('x',)
x = 3

with:
ValueError: 'x' in __slots__ conflicts with class variable

In the dataclasses case, the error needs to be improved, and moved to when the 
base class is being defined.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33094] dataclasses: ClassVar attributes are not working properly

2018-03-19 Thread Adrian Stachlewski

Adrian Stachlewski  added the comment:

Once more same mistake. 

'x' should be declared as: 
- x: ClassVar[set] = set()
- x: ClassVar[Set[Any]] = set()

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33083] math.factorial accepts non-integral Decimal instances

2018-03-19 Thread Serhiy Storchaka

Serhiy Storchaka  added the comment:

"Special cases aren't special enough to break the rules."

Supporting floats is a special case. After ending the period of deprecation the 
code can be simplified.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33083] math.factorial accepts non-integral Decimal instances

2018-03-19 Thread Mark Dickinson

Mark Dickinson  added the comment:

Raymond: what are your thoughts on deprecating the ability of `math.factorial` 
to accept a float (as in `math.factorial(5.0)` -> `120`)?

For me, I'm not sure I see the value of the deprecation. It's the usual story: 
the answer to "Knowing what we know now, should we have done this differently 
in the first place" is "Probably, yes". But "Should we change the current 
behaviour" is a very different question. I'm tempted to see the acceptance of 
integral floats as a harmless quirk, and the deprecation of that behaviour as a 
case of gratuitous breakage.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33021] Some fstat() calls do not release the GIL, possibly hanging all threads

2018-03-19 Thread Robert Collins

Robert Collins  added the comment:

Re: backporting this. I think backporting to 3.6/3.7 makes a lot of sense - 
bugfix and prerelease respectively.

For 2.7, this bug has been around for ages, the patch is small, and I have no 
objection - but the RM has already said no, so I guess not happening :).

That said, if I was analyzing this from scratch I'd look at the pypi download 
stats to assess what footprint 2.7 still has, and whether taking this fix there 
would make objective sense.

While it is a genuine bug - and a nice catch - I have to say that running any 
Python with mmapped data off of NFS is a supremely bad idea :).

--
nosy: +rbcollins

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33089] Add multi-dimensional Euclidean distance function to the math module

2018-03-19 Thread Mark Dickinson

Mark Dickinson  added the comment:

+1 for a single-rounded dot product. If we're allowed to assume IEEE 754, it's 
straightforward to code up something that's not too inefficient and gives 
correctly rounded results for "normal" cases, using a combination of Veltkamp 
splitting, Dekker multiplication, and fsum. The difficulties come in if you 
want to maintain correct rounding in cases where any of the partial products 
overflows or (especially awkwardly) underflows.

Also, if we can figure out how to do a correctly-rounded dot product, that 
gives us math.fma as a special case... (a*b + c = dot([a, c], [b, 1.0])). (Of 
course, that's a bit backwards, since usually you'd see fma as a primitive and 
*use* it in computing a dot product.)

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33053] Avoid adding an empty directory to sys.path when running a module with `-m`

2018-03-19 Thread Nathaniel Smith

Nathaniel Smith  added the comment:

@ncoghlan: The comparison I'm worried about is specifically this one: IIUC, 
right now it's safe to run 'pip --version' in an arbitrary directory, but it's 
not safe to run 'python -m pip --version' in an arbitrary directory. Am I 
wrong? (I actually couldn't convince either version to execute arbitrary code 
in 2 minutes of trying, but that's my understanding of the discussion so far.)

If that's correct, then I don't think this is like... the hugest security bug 
ever, but... I also think that it's irresponsible for e.g. packaging.python.org 
to be recommending people run 'python -m pip' the way it does now, and we need 
to find some way to change things so our beginner docs aren't triggering 
arbitrary code execution in a rare and subtle case.

We could add a bunch of warnings to packaging.python.org, explaining about how 
the code execution can be triggered, but that seems unsatisfactory given how 
those docs are targeted at beginners, plus there are so many places around the 
internet that recommend 'python -m pip' we'd never find them all.

We could update all those docs to instead recommend 'python -Im pip', but that 
has the same problems: no-one will understand, and people won't do it.

We could stop recommending 'python -m pip' entirely, but that runs into all the 
problems that have motivated this in the first place.

So I think we should find a way to make it so 'python -m pip' *never* executes 
code from the current directory (modulo the usual caveats, like the user 
explicitly setting PYTHONPATH to an insecure value etc.).

If 'python -m mypkg.myscript' is important, maybe we can make it 'PYTHONPATH=. 
python -m mypkg.myscript', or 'python -M mypkg.myscript', or making 'python 
mypkg/myscript.py' DTRT, or... something?

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33098] add implicit conversion for random.choice() on a dict

2018-03-19 Thread Aristide Grange

Aristide Grange  added the comment:

My bad... For my reference to Python 2, I relied on my memory only, which 
starts to vanish. Really sorry about that. Yes, `random.choice(d)` (mostly) 
fails in Python 2 too, with an error message that I better understand after 
reading your explanation.

So, in Python 2/3, when `random.choice()` is applied to a dictionary, it draws 
a random integer i in [0, len(d)[ and tries to return the _value_ `d[i]`. It's 
quite unexpected, for me at last. According to the doc:

random.choice(seq)
Return a random element from the non-empty sequence seq. If seq is empty, 
raises IndexError.

In Python 3, evaluating `choice(d.keys())` raises "TypeError: 'dict_keys' 
object does not support indexing". Shouldn't `choice(d)` _always_ fail with the 
same error message? I am not sure to see any legitimate use for the current 
behavior.

With regard to the repeated refusal to hide the fact that `choice`-ing among 
the keys of a dictionary is a linear operation, I can understand this decision. 
The general interest does not necessary align with that of an algorithmic 
teacher which only uses Python as a support language for introducing students 
to basic / transversal datatypes such as lists, arrays, dictionaries, sets, and 
prefers to avoid speaking of `dict_keys` and other Python's niceties...

Anyway, thanks a lot for your detailed and patient answer.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33089] Add multi-dimensional Euclidean distance function to the math module

2018-03-19 Thread Raymond Hettinger

Raymond Hettinger  added the comment:

[Uncle Timmy]
> I doubt `fsum()` would add much value here:  all the addends have the 
> same sign, so cancellation is impossible

fsum() may be overkill for this problem.  I mentioned it because the math 
module already had the requisite code and because it improved accuracy with 
high dimensional data in machine learning examples I've encountered:

>>> from math import fsum, sqrt

>>> n = 1000
>>> sum([0.1] * n)
99.99986
>>> fsum([0.1] * n)
100.0

>>> sqrt(sum([0.1] * n) / n)
0.3162277660168357
>>> sqrt(fsum([0.1] * n) / n)
0.31622776601683794

# fsum() version exactly matches the decimal crosscheck
>>> getcontext().prec = 40
>>> (sum([Decimal(0.1)] * n) / n).sqrt()
Decimal('0.3162277660168379419769730258850242641698')

If we care about those little differences (about 80 ulp in this example), the 
single-rounding dot products seems like a better way to go.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33089] Add multi-dimensional Euclidean distance function to the math module

2018-03-19 Thread Serhiy Storchaka

Serhiy Storchaka  added the comment:

With this implementation

>>> hypot(*range(15), 3)
32.01

The exact result is 32.

--
nosy: +serhiy.storchaka

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com