Re: Function to determine list max without itertools

2019-04-18 Thread Sayth Renshaw


> 
> In English rather than Python, how do you find the maximum element in a 
> list?
> 
> -- 
> Rob Gaddi, Highland Technology 

Get first 1 item in the list and compare it to the rest. If it is larger than 
rest its the max. However if another list member is larger it replaces the 
first item and comparison continues.

Sayth


-- 
https://mail.python.org/mailman/listinfo/python-list


[issue36664] argparse: parser aliases in subparsers stores alias in dest variable

2019-04-18 Thread paul j3


paul j3  added the comment:

I added a `print(args)` to clarify what you are talking about:

2148:~/mypy$ python3 issue36664.py subsection
Namespace(context='subsection')
my subsection was called
2148:~/mypy$ python3 issue36664.py s
Namespace(context='s')
my functon was not called 
2148:~/mypy$ python3 issue36664.py sub
Namespace(context='sub')
my functon was not called 

The value of `args.context` depends on what alias was used, not the primary 
name of the subparser.

The help lists all aliases

2148:~/mypy$ python3 issue36664.py -h
usage: issue36664.py [-h] {subsection,s,sub,subsect} ...

The sub-parser doesn't actually have a name.  In self._name_parser_map each 
alias is a key with a parser object value.  Multiple keys for a single value.  
The only thing that distinguishes 'subsection' is that was the first key in 
that dictionary.  

In effect the subparser Action object does not maintain a mapping from the 
aliases to the 'subsection' name.  I can imagine some ways of deducing that 
mapping, but it's not going to be a trivial task.

Unless someone comes up with a clever patch, I think the best choice is for you 
maintain your own mapping.  For example write a utility that takes a 'name' and 
alias list, calls

sub = subparser.add_parser('subsection', aliases=['s', 'sub', 'subsect'])

and saves some sort of mapping from the aliases to 'subsection'.  Then use that 
later when you use `args.context`.

--

___
Python tracker 

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



[issue36661] Missing dataclass decorator import in dataclasses module docs

2019-04-18 Thread Karthikeyan Singaravelan


Karthikeyan Singaravelan  added the comment:

I think the import is implied in the example since the docs page is for 
dataclasses module but adding an explicit import to InventoryItem at the top 
won't hurt too.

--
nosy: +eric.smith, xtreak
title: Missing import in docs -> Missing dataclass decorator import in 
dataclasses module docs
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



[issue36662] asdict/astuple Dataclass methods

2019-04-18 Thread Karthikeyan Singaravelan


Karthikeyan Singaravelan  added the comment:

asdict method in the benchmark does a direct dictionary construction. Meanwhile 
dataclasses.asdict does more work in 
https://github.com/python/cpython/blob/e8113f51a8bdf33188ee30a1c038a298329e7bfa/Lib/dataclasses.py#L1023
 . Hence in the example i.asdict() and asdict(i) are not equivalent.

import timeit
from dataclasses import dataclass, asdict

@dataclass
class InventoryItem:
'''Class for keeping track of an item in inventory.'''
name: str
unit_price: float
quantity_on_hand: int = 0

def asdict(self):
data = {'name': self.name,
'unit_price': self.unit_price,
'quantity_on_hand': self.quantity_on_hand,
}
return data

i = InventoryItem(name='widget', unit_price=3.0, quantity_on_hand=10)
setup = """from dataclasses import dataclass, asdict;
@dataclass
class InventoryItem:
'''Class for keeping track of an item in inventory.'''
name: str
unit_price: float
quantity_on_hand: int = 0

def asdict(self):
data = {'name': self.name,
'unit_price': self.unit_price,
'quantity_on_hand': self.quantity_on_hand,
}
return data

i = InventoryItem(name='widget', unit_price=3.0, quantity_on_hand=10)"""

print("asdict(i)")
print(timeit.Timer("asdict(i)", setup=f"{setup}").timeit(number=1_000_000))
print("i.asdict()")
print(timeit.Timer("i.asdict()", setup=f"{setup}").timeit(number=1_000_000))
print("i.inlined_asdict()")
print(timeit.Timer("i.inlined_asdict(i)", setup=f"{setup}; i.inlined_asdict = 
asdict").timeit(number=1_000_000))

i.inlined_asdict = asdict
assert asdict(i) == i.asdict() == i.inlined_asdict(i)


./python.exe ../backups/bpo36662.py
asdict(i)
11.58583875601
i.asdict()
0.4412935069925
i.inlined_asdict()
11.85804280799

--
nosy: +xtreak

___
Python tracker 

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



[issue36666] threading.Thread should have way to catch an exception thrown within

2019-04-18 Thread Karthikeyan Singaravelan


Change by Karthikeyan Singaravelan :


--
nosy: +pitrou

___
Python tracker 

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



[issue36662] asdict/astuple Dataclass methods

2019-04-18 Thread Karthikeyan Singaravelan


Change by Karthikeyan Singaravelan :


--
nosy: +eric.smith, rhettinger

___
Python tracker 

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



[issue36664] argparse: parser aliases in subparsers stores alias in dest variable

2019-04-18 Thread Karthikeyan Singaravelan


Change by Karthikeyan Singaravelan :


--
nosy: +paul.j3

___
Python tracker 

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



[issue25878] CPython on Windows builds with /W3, not /W4

2019-04-18 Thread Alexander Riccio


Alexander Riccio  added the comment:

One more thing, after I ran code analysis:

This is obviously a potential memory leak:
Warning C6308   'realloc' might return null pointer: assigning null pointer to 
'arr->items', which is passed as an argument to 'realloc', will cause the 
original memory block to be leaked.
cpython\parser\parsetok.c   38  


I found some sketchy code that isn't obviously correct. Here are a few of the 
warnings:


Warning C6294   Ill-defined for-loop:  initial condition does not satisfy test. 
 Loop body not executed.
\cpython\modules\gcmodule.c 1377


Warning C6011   Dereferencing NULL pointer 'cmdline'. See line 230 for an 
earlier location where this can occur
\cpython\python\preconfig.c 242 
(cmdline is checked for nullness after several uses?)


And finally there's one warning where I have no clue what's going on:

Warning C6386   Buffer overrun while writing to 'x_digits':  the writable size 
is '10' bytes, but '286331156' bytes might be written.   
\cpython\objects\longobject.c   2972

--
Added file: https://bugs.python.org/file48276/cpython_xdigits_overrun.PNG

___
Python tracker 

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



[issue36665] REPL doesn't ensure builtins are available when implicitly recreating __main__

2019-04-18 Thread Nick Coghlan


Change by Nick Coghlan :


--
title: Dropping __main__ from sys.modules clears the REPL namespace -> REPL 
doesn't ensure builtins are available when implicitly recreating __main__

___
Python tracker 

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



Re: Function to determine list max without itertools

2019-04-18 Thread Grant Edwards
On 2019-04-18, Rob Gaddi  wrote:
> On 4/18/19 4:35 PM, Sayth Renshaw wrote:
>
>> This is where I have ended up. Without itertools and max its what I got 
>> currently.
>> 
>> def maximum(listarg):
>>  myMax = listarg[0]
>>  for item in listarg:
>>  for i in listarg[listarg.index(item)+1:len(listarg)]:
>>  if myMax < i:
>>  myMax = i
>> 
>>  return myMax
>> 
>> How would you simplify it?
>
> In English rather than Python, how do you find the maximum element
> in a list?

Hint: "greater than" is transitive.

--
Grant


-- 
https://mail.python.org/mailman/listinfo/python-list


[issue36665] Dropping __main__ from sys.modules clears the REPL namespace

2019-04-18 Thread Nick Coghlan


Nick Coghlan  added the comment:

The relevant functions:

* PyRun_InteractiveLoopFlags: 
https://github.com/python/cpython/blob/e8113f51a8bdf33188ee30a1c038a298329e7bfa/Python/pythonrun.c#L89
* PyRun_InteractiveOneObjectEx: 
https://github.com/python/cpython/blob/e8113f51a8bdf33188ee30a1c038a298329e7bfa/Python/pythonrun.c#L180

So it turns out I was wrong: nothing is getting cleared anywhere, but instead 
each statement in the REPL is *importing* `__main__` again in order to find the 
namespace to use for the statement execution.

Because of the specific API it uses to do that, a non-module object like the 
one I injected gets replaced with a regular (empty) module object: 
https://github.com/python/cpython/blob/027b09c5a13aac9e14a3b43bb385298d549c3833/Python/import.c#L791

However, it *doesn't* have the extra code needed to make the `builtins` 
available: 
https://github.com/python/cpython/blob/027b09c5a13aac9e14a3b43bb385298d549c3833/Python/import.c#L932

So I now think the only actual *bug* here is the fact that the REPL isn't 
making sure that `__builtins__` is set appropriately - the rest can be chalked 
up to implementation defined behaviour around what happens if `__main__` gets 
replaced or removed in sys.modules while the REPL is running.

--

___
Python tracker 

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



[issue36666] threading.Thread should have way to catch an exception thrown within

2019-04-18 Thread Joel Croteau


New submission from Joel Croteau :

This has been commented on numerous times by others 
(https://stackoverflow.com/questions/2829329/catch-a-threads-exception-in-the-caller-thread-in-python,
 http://benno.id.au/blog/2012/10/06/python-thread-exceptions, to name a few), 
but there is no in-built mechanism in threading to catch an unhandled exception 
thrown by a thread. The default behavior of dumping to stderr is completely 
useless for error handling in many scenarios. Solutions do exist, but I have 
yet to see one that is not exceptionally complicated. It seems like checking 
for exceptions should be a very basic part of any threading library. The 
simplest solution would be to just have the Thread store any unhandled 
exceptions and have them raised by Thread.join(). There could also be 
additional methods to check if exceptions were raised.

--
components: Library (Lib)
messages: 340520
nosy: Joel Croteau
priority: normal
severity: normal
status: open
title: threading.Thread should have way to catch an exception thrown within
versions: Python 3.7

___
Python tracker 

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



[issue36645] re.sub() library entry does not adequately document surprising change in behavior between versions

2019-04-18 Thread mollison


mollison  added the comment:

@brett.cannon: PR is at https://github.com/python/cpython/pull/12879

--

___
Python tracker 

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



[issue36645] re.sub() library entry does not adequately document surprising change in behavior between versions

2019-04-18 Thread mollison


Change by mollison :


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

___
Python tracker 

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



[issue36665] Dropping __main__ from sys.modules clears the REPL namespace

2019-04-18 Thread Nick Coghlan


Nick Coghlan  added the comment:

The ``sys`` import gets cleared as well (accidentally omitted from the previous 
comment):

```
>>> sys
Traceback (most recent call last):
  File "", line 1, in 
NameError: name 'sys' is not defined
```

--

___
Python tracker 

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



[issue36665] Dropping __main__ from sys.modules clears the REPL namespace

2019-04-18 Thread Nick Coghlan


Nick Coghlan  added the comment:

Additional info showing the module getting reset back to the state of a freshly 
created module namespace:

```
>>> dir()
['__annotations__', '__builtins__', '__doc__', '__loader__', '__name__', 
'__package__', '__spec__']
>>> __builtins__

>>> import sys
>>> mod = sys.modules[__name__]
>>> sys.modules[__name__] = object()
>>> __builtins__
Traceback (most recent call last):
  File "", line 1, in 
NameError: name '__builtins__' is not defined
>>> __annotations__
Traceback (most recent call last):
  File "", line 1, in 
NameError: name '__annotations__' is not defined
>>> __doc__
>>> __loader__
>>> __name__
'__main__'
>>> __package__
>>> __spec__
>>> mod
Traceback (most recent call last):
  File "", line 1, in 
NameError: name 'mod' is not defined
```

--

___
Python tracker 

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



[issue36665] Dropping __main__ from sys.modules clears the REPL namespace

2019-04-18 Thread Nick Coghlan


New submission from Nick Coghlan :

While trying to create an example for a pickle bug discussion, I deliberately 
dropped `__main__` out of sys.modules, and the REPL session lost all of its 
runtime state.

Simplified reproducer:


```
>>> import sys
>>> mod = sys.modules[__name__]
>>> sys.modules[__name__] = object()
>>> dir()
Traceback (most recent call last):
  File "", line 1, in 
NameError: name 'dir' is not defined

```

(Initially encountered on Python 2.7, reproduced on Python 3.7)

If I'd just dropped the reference to `__main__` entirely, that would make sense 
(since modules clear their namespaces when they go away), but I didn't: I saved 
a reference in a local variable first.

So it appears the CPython REPL isn't keeping a strong reference to either 
`__main__` or `__main__.__dict__` between statements, so the cyclic GC kicked 
in and decided the module could be destroyed.

--
messages: 340516
nosy: ncoghlan
priority: normal
severity: normal
stage: test needed
status: open
title: Dropping __main__ from sys.modules clears the REPL namespace
type: behavior
versions: Python 2.7, 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



Re: Function to determine list max without itertools

2019-04-18 Thread Rob Gaddi

On 4/18/19 4:35 PM, Sayth Renshaw wrote:




It's still overly complicated.



This is where I have ended up. Without itertools and max its what I got 
currently.

def maximum(listarg):
 myMax = listarg[0]
 for item in listarg:
 for i in listarg[listarg.index(item)+1:len(listarg)]:
 if myMax < i:
 myMax = i

 return myMax

How would you simplify it?



In English rather than Python, how do you find the maximum element in a 
list?


--
Rob Gaddi, Highland Technology -- www.highlandtechnology.com
Email address domain is currently out of order.  See above to fix.
--
https://mail.python.org/mailman/listinfo/python-list


Re: Function to determine list max without itertools

2019-04-18 Thread Sayth Renshaw


> >
> It's still overly complicated.
> 

This is where I have ended up. Without itertools and max its what I got 
currently.

def maximum(listarg):
myMax = listarg[0]
for item in listarg:
for i in listarg[listarg.index(item)+1:len(listarg)]:
if myMax < i:
myMax = i

return myMax

How would you simplify it?
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue36664] argparse: parser aliases in subparsers stores alias in dest variable

2019-04-18 Thread Peter McEldowney


New submission from Peter McEldowney :

I noticed that I have to add a lot more code to handle contexts in subparsers 
that I was expecting would be necessary. This is something I feel should be 
handled by the argparse library. What are your thoughts on this?


If you run the sample code with the commands below, you can see that although I 
would want them to do the same thing, I have to add more lines into my code to 
achieve this. This becomes cumbersome/annoying when dealing with subparser 
trees.

python3 sample.py subsection
python3 sample.py s


Sample code (also attached):

import argparse

def get_args(args=None):
parser = argparse.ArgumentParser()
subparser = parser.add_subparsers(dest='context')

sub = subparser.add_parser('subsection', aliases=['s', 'sub', 
'subsect'])

return parser.parse_args(args)

def my_subsection_function(args):
print('my subsection was called')

def invalid_context(args):
print('my functon was not called ')

def main(args=get_args()):  
return {
'subsection': my_subsection_function
}.get(args.context, invalid_context)(args)

if __name__ == "__main__":
main()

--
components: Library (Lib)
files: sample.py
messages: 340515
nosy: Peter McEldowney
priority: normal
severity: normal
status: open
title: argparse: parser aliases in subparsers stores alias in dest variable
type: enhancement
versions: Python 3.7
Added file: https://bugs.python.org/file48275/sample.py

___
Python tracker 

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



[issue36054] Way to detect CPU count inside docker container

2019-04-18 Thread Joshua Bronson


Change by Joshua Bronson :


--
nosy: +jab

___
Python tracker 

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



[issue29980] OSError: multiple exceptions should preserve the exception type if it is common

2019-04-18 Thread Joannah Nanjekye


Change by Joannah Nanjekye :


--
nosy: +nanjekyejoannah

___
Python tracker 

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



[issue36658] Py_Initialze() throws error 'unable to load the file system encoding' when calling Py_SetPath with a path to a directory

2019-04-18 Thread RimacV


RimacV  added the comment:

Thanks for your quick response! I will try your suggestion on tuesday and will 
then let you know, if it worked as expected.

--

___
Python tracker 

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



[issue16520] subprocess.Popen() TypeError message incorrect without args argument

2019-04-18 Thread Joannah Nanjekye


Change by Joannah Nanjekye :


--
nosy: +nanjekyejoannah

___
Python tracker 

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



[issue25878] CPython on Windows builds with /W3, not /W4

2019-04-18 Thread Alexander Riccio


Alexander Riccio  added the comment:

I decided to come back to this after a python meetup last night. By messing 
with this a bit, building in VS2019 with /W4, I see that fully 2/3rds of the 
total warnings are from two specific warnings:

C4100 (unreferenced formal parameter)
C4127 (conditional expression is constant)

...This seems to be a stylistic thing across the codebase. If it were a new 
codebase, I'd simply recommend not giving unreferenced formal parameters a 
variable name - the typical way of doing it - but there's no way anybody is 
gonna care enough to comment them out across the whole codebase. C4127 is not A 
Big Deal, since dispatching based on data type sizes in conditionals is just 
the easiest way to do The Right Thing in C.

The rest of the warnings are mostly datatype coercions ('=': conversion from 
'int' to 'char', possible loss of data), old style declarators, and a bunch of 
type indirection mismatches ('function': 'volatile int *' differs in 
indirection to slightly different base types from 'volatile long *'), type cast 
truncation ('type cast': truncation from 'volatile __int64' to 'PyThreadState 
*'), named type declarations in parenthesis ('timeval': named type definition 
in parentheses), and assignments in conditionals (which I don't like, but are 
not a huge deal).

There really are only a few things that actually look sketchy. For example, in 
run_child (launcher.c), SetInformationJobObject is passing sizeof(info) as 
cbJobObjectInformationLength, where it should instead be the local variable rc.

--

___
Python tracker 

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



[issue36663] pdb: store whole exception information in locals (via user_exception)

2019-04-18 Thread daniel hahler

New submission from daniel hahler :

Currently Pdb.user_exception does not store the traceback in "user_exception", 
but only passes it to `interaction`:


def user_exception(self, frame, exc_info):
"""This function is called if an exception occurs,
but only if we are to stop at or just below this level."""
if self._wait_for_mainpyfile:
return
exc_type, exc_value, exc_traceback = exc_info
frame.f_locals['__exception__'] = exc_type, exc_value
…
self.interaction(frame, exc_traceback)

I think it would be useful to have the whole exception info at hand in the 
debugger (via the frame locals) directly.


If backward compatible is important it should use a new name for this maybe 
(`__excinfo__`), i.e. if current code would assume `__exception__` to be of 
length 2 only.
But on the other hand this only affects extensions to the debugger, and not 
"real" programs, and therefore backward compatibility is not really required 
here?

Currenly pdb extensions (e.g. pdbpp) can get it either by going up in the 
stack, or grabbing it via `interaction`, but this issue is mainly about making 
it available in plain pdb for the user to interact with.

Code ref: 
https://github.com/python/cpython/blob/e8113f51a8bdf33188ee30a1c038a298329e7bfa/Lib/pdb.py#L295-L301

--
components: Library (Lib)
messages: 340512
nosy: blueyed
priority: normal
severity: normal
status: open
title: pdb: store whole exception information in locals (via user_exception)
versions: Python 3.9

___
Python tracker 

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



[issue36662] asdict/astuple Dataclass methods

2019-04-18 Thread George Sakkis

New submission from George Sakkis :

I'd like to propose two new optional boolean parameters to the @dataclass() 
decorator, `asdict` and `astuple`, that if true, the respective methods are 
generated as equivalent to the module-level namesake functions.

In addition to saving an extra imported name, the main benefit is performance. 
By having access to the specific fields of the decorated class, it should be 
possible to generate a more efficient implementation than the one in the 
respective function. To illustrate the difference in performance, the asdict 
method is 28 times faster than the function in the following PEP 557 example:


@dataclass
class InventoryItem:
'''Class for keeping track of an item in inventory.'''
name: str
unit_price: float
quantity_on_hand: int = 0

def asdict(self): 
return {
'name': self.name, 
'unit_price': self.unit_price, 
'quantity_on_hand': self.quantity_on_hand,
} 
   

In [4]: i = InventoryItem(name='widget', unit_price=3.0, 
quantity_on_hand=10)   

In [5]: asdict(i) == i.asdict() 

Out[5]: True

In [6]: %timeit asdict(i)   

5.45 µs ± 14.1 ns per loop (mean ± std. dev. of 7 runs, 10 loops 
each)

In [7]: %timeit i.asdict()  

193 ns ± 0.443 ns per loop (mean ± std. dev. of 7 runs, 1000 loops 
each)

Thoughts?

--
components: Library (Lib)
messages: 340511
nosy: gsakkis
priority: normal
severity: normal
status: open
title: asdict/astuple Dataclass methods
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



[issue36661] Missing import in docs

2019-04-18 Thread Merlin Fisher-Levine


New submission from Merlin Fisher-Levine :

Dataclasses docs don't mention needing import for @dataclass decorator

https://docs.python.org/3/library/dataclasses.html

--
assignee: docs@python
components: Documentation
messages: 340510
nosy: docs@python, mfisherlevine
priority: normal
severity: normal
status: open
title: Missing import in docs
type: enhancement
versions: Python 3.7

___
Python tracker 

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



[no subject]

2019-04-18 Thread trisha guillot


-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Friday Filosofical Finking: Import protections

2019-04-18 Thread Chris Angelico
On Fri, Apr 19, 2019 at 3:27 AM Akkana Peck  wrote:
>
> Chris Angelico writes:
> > Actually, only the Python interpreter has to be able to do those
> > steps. That's why I put the comment *on the same line* as the import
> > statement (not immediately above it, for instance). It comes out like
> > this:
> >
> > (env) rosuav@sikorsky:~/shed$ python3 BL2_find_items.py
> > Traceback (most recent call last):
> >   File "BL2_find_items.py", line 19, in 
> > import lzo # ImportError? pip install python-lzo
> > ModuleNotFoundError: No module named 'lzo'
> > (env) rosuav@sikorsky:~/shed$
>
> Oh, I see: because it prints the full line that caused the exception.
> Clever!

Yes - provided the .py file is available. If you delete the .py file
and just run the .pyc, this doesn't work. (Another reason not to do
that, honestly.)

> > > for regular users, when you know an error is both likely and unclear
> > > to read, it might make sense to catch the exception and print
> > > a clearer message.
> >
> > Define "clearer", though. Given that many MANY users won't read *any*
> > error message, the clarity becomes largely moot, and only a handful of
> > people will (a) read what you print out, (b) be able to resolve the
> > problem, and (c) not be able to figure it out from four lines of
> > output.
>
> When writing programs for general use (which this admittedly wasn't),
> it seems sad to accept unclear errors on the assumption that some
> users don't read error messages. Even most of the nontechnical
> users I know will read a one-line error message, though they
> certainly wouldn't try to read a 4-line stack trace. I usually try
> to catch errors that I expect will be common, and print something
> clearer than the default traceback.

TBH, I don't think the default message is all that unclear. It does
lack any sort of "how to solve this" information, but that can be
provided by the comment. Something that frequently annoys me in terms
of debugging is something that "knows better" - it absorbs a nice,
useful, helpful message, and spits out one bland, generic message,
based on what the developer THINKS is the cause. Remember: You will
*never* think of everything that can go wrong.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Friday Filosofical Finking: Import protections

2019-04-18 Thread Akkana Peck
Chris Angelico writes:
> Actually, only the Python interpreter has to be able to do those
> steps. That's why I put the comment *on the same line* as the import
> statement (not immediately above it, for instance). It comes out like
> this:
> 
> (env) rosuav@sikorsky:~/shed$ python3 BL2_find_items.py
> Traceback (most recent call last):
>   File "BL2_find_items.py", line 19, in 
> import lzo # ImportError? pip install python-lzo
> ModuleNotFoundError: No module named 'lzo'
> (env) rosuav@sikorsky:~/shed$

Oh, I see: because it prints the full line that caused the exception.
Clever!

> > for regular users, when you know an error is both likely and unclear
> > to read, it might make sense to catch the exception and print
> > a clearer message.
> 
> Define "clearer", though. Given that many MANY users won't read *any*
> error message, the clarity becomes largely moot, and only a handful of
> people will (a) read what you print out, (b) be able to resolve the
> problem, and (c) not be able to figure it out from four lines of
> output.

When writing programs for general use (which this admittedly wasn't),
it seems sad to accept unclear errors on the assumption that some
users don't read error messages. Even most of the nontechnical
users I know will read a one-line error message, though they
certainly wouldn't try to read a 4-line stack trace. I usually try
to catch errors that I expect will be common, and print something
clearer than the default traceback.

> Indeed. But the biggest argument in favour of this style of thing is
> that it requires almost zero effort and has almost zero code
> readability cost. Imagine having half a dozen dependencies and tagging
> each one with a comment like mine... and now imagine having to bracket
> each one of them with a try/except and an appropriate message.

Certainly. I don't use try/except on imports in general. And I
like your short form, and there are definitely places where I'll use
that now where a try/except would have been overkill.

...Akkana
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue32913] Improve regular expression HOWTO

2019-04-18 Thread Brett Cannon


Change by Brett Cannon :


--
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



[issue30485] Element.findall(path, dict) doesn't insert null namespace

2019-04-18 Thread Stefan Behnel


Stefan Behnel  added the comment:


New changeset e8113f51a8bdf33188ee30a1c038a298329e7bfa by Stefan Behnel in 
branch 'master':
bpo-30485: Change the prefix for defining the default namespace in ElementPath 
from None to '' since there is existing code that uses that and it's more 
convenient to have an all-string-keys dict (e.g. when sorting items etc.). 
(#12860)
https://github.com/python/cpython/commit/e8113f51a8bdf33188ee30a1c038a298329e7bfa


--

___
Python tracker 

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



Re: Friday Filosofical Finking: Import protections

2019-04-18 Thread Chris Angelico
On Fri, Apr 19, 2019 at 2:46 AM Akkana Peck  wrote:
>
> Chris Angelico writes:
> > I write this as:
> >
> > import whois # ImportError? pip install python-whois
> [ ... ]
> > it means that normal exception handling is still
> > happening (which might be important if I import this into something
> > else), plus it's printing the message to stderr rather than stdout
> [ ... ]
> > About the only downside is that it assumes the .py file is available -
> > this won't work with a .pyc-only setup.
>
> It also assumes the user is capable of (1) finding the .py file
> (maybe not so easy if it's imported from another program) and
> (2) knowing Python well enough to find and understand the line with
> the comment.

Actually, only the Python interpreter has to be able to do those
steps. That's why I put the comment *on the same line* as the import
statement (not immediately above it, for instance). It comes out like
this:

(env) rosuav@sikorsky:~/shed$ python3 BL2_find_items.py
Traceback (most recent call last):
  File "BL2_find_items.py", line 19, in 
import lzo # ImportError? pip install python-lzo
ModuleNotFoundError: No module named 'lzo'
(env) rosuav@sikorsky:~/shed$

> Which in my example is not a problem since I'm probably
> the only user of my domaincheck script; but when writing programs
> for regular users, when you know an error is both likely and unclear
> to read, it might make sense to catch the exception and print
> a clearer message.

Define "clearer", though. Given that many MANY users won't read *any*
error message, the clarity becomes largely moot, and only a handful of
people will (a) read what you print out, (b) be able to resolve the
problem, and (c) not be able to figure it out from four lines of
output.

> Your counterarguments are quite valid, though. It's a trade-off.

Indeed. But the biggest argument in favour of this style of thing is
that it requires almost zero effort and has almost zero code
readability cost. Imagine having half a dozen dependencies and tagging
each one with a comment like mine... and now imagine having to bracket
each one of them with a try/except and an appropriate message.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Friday Filosofical Finking: Import protections

2019-04-18 Thread Akkana Peck
Chris Angelico writes:
> I write this as:
> 
> import whois # ImportError? pip install python-whois
[ ... ]
> it means that normal exception handling is still
> happening (which might be important if I import this into something
> else), plus it's printing the message to stderr rather than stdout
[ ... ]
> About the only downside is that it assumes the .py file is available -
> this won't work with a .pyc-only setup.

It also assumes the user is capable of (1) finding the .py file
(maybe not so easy if it's imported from another program) and
(2) knowing Python well enough to find and understand the line with
the comment. Which in my example is not a problem since I'm probably
the only user of my domaincheck script; but when writing programs
for regular users, when you know an error is both likely and unclear
to read, it might make sense to catch the exception and print
a clearer message.

Your counterarguments are quite valid, though. It's a trade-off.

...Akkana
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Friday Filosofical Finking: Import protections

2019-04-18 Thread Rhodri James

On 18/04/2019 17:10, Manolo Martínez wrote:


On 2019-04-17, DL Neil  wrote:


   2. When the program can still do something useful (if perhaps
  feature-limited) without the imported module by substituting
  something else in its place.


Isn't this a very common scenario, similar to what package management systems
call "optional dependencies"?


I wouldn't have said "very common."


I maintain a small podcast aggregator that tags podcasts using an external
tagging library as an optional dependency---people can choose not to install it
if they don't care about tags. That library is imported within a try/except
block.


Most imports I've seen have been for mandatory functionality; while my 
current code could run without its CRC library, everything it tried to 
talk to would reject its messages, for example!


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: Friday Filosofical Finking: Import protections

2019-04-18 Thread Manolo Martínez

On 2019-04-17, DL Neil  wrote:

>   2. When the program can still do something useful (if perhaps
>  feature-limited) without the imported module by substituting
>  something else in its place.

Isn't this a very common scenario, similar to what package management systems
call "optional dependencies"? 

I maintain a small podcast aggregator that tags podcasts using an external
tagging library as an optional dependency---people can choose not to install it
if they don't care about tags. That library is imported within a try/except
block.

Manolo


signature.asc
Description: PGP signature
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Friday Filosofical Finking: Import protections

2019-04-18 Thread Chris Angelico
On Fri, Apr 19, 2019 at 1:36 AM Akkana Peck  wrote:
> One example: there are a gazillion whois modules, and when I run my
> domaincheck program on a machine where I haven't yet installed
> whois, it's helpful to have a reminder of which one I should
> install. (Of course, if you have one of the other whois modules
> installed, the program will fail somewhere else.)
>
> try:
> import whois
> # python-whois from pypi, not whois from pypi or python-whois from debian
> # https://bitbucket.org/richardpenman/pywhois
> except ImportError:
> print("Couldn't import whois. Try: pip3 install python-whois")
> sys.exit(1)

I write this as:

import whois # ImportError? pip install python-whois

Way easier, AND it means that normal exception handling is still
happening (which might be important if I import this into something
else), plus it's printing the message to stderr rather than stdout
(not usually significant, but when it is, I'd usually rather the
errors go to stderr).

About the only downside is that it assumes the .py file is available -
this won't work with a .pyc-only setup.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue36659] distutils UnixCCompiler: Remove standard library path from rpath

2019-04-18 Thread STINNER Victor


STINNER Victor  added the comment:

Another test, without my PR 12876.

Python compiled without RPATH:

$ ./configure --prefix=/opt/py38
$ make
$ make install
$ /opt/py38/bin/python3.8 -m sysconfig|grep LIBDIR
LIBDIR = "/opt/py38/lib"

Build lxml manually using "setup.py build_ext --rpath /opt/py38/lib" (which is 
equal to the Python sysconfig LIBDIR variable):

$ /opt/py38/bin/python3.8 -m venv ~/opt_env
$ wget 
https://files.pythonhosted.org/packages/7d/29/174d70f303016c58bd790c6c86e6e86a9d18239fac314d55a9b7be501943/lxml-4.3.3.tar.gz
$ tar -xf lxml-4.3.3.tar.gz 
$ cd lxml-4.3.3/
$ LD_LIBRARY_PATH=/opt/py38/lib ~/opt_env/bin/python setup.py build_ext --rpath 
/opt/py38/lib
$ objdump -a -x 
build/lib.linux-x86_64-3.8/lxml/etree.cpython-38m-x86_64-linux-gnu.so|grep -i 
rpath

^^ no output, no RPATH

Hum, distutils removed the RPATH because it's equal to Python sysconfig LIBDIR? 
Without my PR? Strange.

New try with a different RPATH:

$ rm -rf build
$ ~/opt_env/bin/python setup.py build_ext --rpath /custom/rpath
$ objdump -a -x 
build/lib.linux-x86_64-3.8/lxml/etree.cpython-38m-x86_64-linux-gnu.so|grep -i 
rpath
  RUNPATH  /custom/rpath

The RPATH is correctly written in the .so file.

... Now, I'm confused. Is PR 12876 useless? Was distutils already fixed?

--

___
Python tracker 

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



[issue36660] TypeError

2019-04-18 Thread STINNER Victor


STINNER Victor  added the comment:

Note: maak opened a similar issue that has also closed as "not a bug": 
bpo-36657.

--

___
Python tracker 

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



[issue33608] Add a cross-interpreter-safe mechanism to indicate that an object may be destroyed.

2019-04-18 Thread Steve Dower


Change by Steve Dower :


--
pull_requests: +12802

___
Python tracker 

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



[issue36657] AttributeError

2019-04-18 Thread STINNER Victor


STINNER Victor  added the comment:

... maak opened a second issue... bpo-36660.

--
nosy: +vstinner

___
Python tracker 

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



[issue36660] TypeError

2019-04-18 Thread STINNER Victor


STINNER Victor  added the comment:

Sorry maak, but the Python bug tracker is not the right place to ask questions 
about Python programming. It seems like you are learning Python. Try to find 
another place like StackOverflow, python-list mailing list, etc. Thanks ;-)

--
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



[issue36660] TypeError

2019-04-18 Thread maak


New submission from maak :

TypeError: coercing to Unicode: need string or buffer, bool found

--
components: Unicode
messages: 340504
nosy: ezio.melotti, maakvol, vstinner
priority: normal
severity: normal
status: open
title: TypeError
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



[issue36657] AttributeError

2019-04-18 Thread Steven D'Aprano


Steven D'Aprano  added the comment:

Hi Maakvol,

Please remember that this is a bug tracker for bugs in the Python language and 
standard library, not a help desk.

As a beginner, 99.9% of the times you think that you have found a bug in 
Python, you haven't, it will be a bug in your own code. There are many forums 
where you can ask for help with your code, such as the tutor mailing list 

https://mail.python.org/mailman/listinfo/tutor

Stackoverflow, Reddit's /r/learnpython, and more. You should check with other, 
more experienced programmers before reporting things as bugs.

Thank you.

--
nosy: +steven.daprano

___
Python tracker 

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



Re: Friday Filosofical Finking: Import protections

2019-04-18 Thread Akkana Peck
DL Neil writes:
> On 18/04/19 8:44 AM, Grant Edwards wrote:
> >   2. When the program can still do something useful (if perhaps
> >  feature-limited) without the imported module by substituting
> >  something else in its place.
> 
> Any (publishable) examples?

One of the targets my RSS fetching program supports is Plucker on
PalmOS, which used to be how I read RSS feeds back in the day
(nowadays I use simplified HTML on Android). Plucker on Palm had
problems with accented characters, so I added a little module called
ununicode to translate strings to plain ASCII (so á would become a).
For most target platforms, it was a nonissue.

try:
import ununicode
has_ununicode = True
except ImportError as e:
has_ununicode = False

def output_encode(s, encoding):
if encoding == 'ascii' and has_ununicode:
return ununicode.toascii(s, in_encoding=encoding)
else:
return s

The program still worked fine if the module wasn't there, it just
wrote accented characters because it couldn't simplify them.

And yes, it could have tested "if 'ununicode' in sys.modules" instead
of setting a variable; I didn't know about that at the time.

> but... what of the third inherent assumption: that the user(s) will be able
> to handle the situation (discussed in another msg 'here')?

One example: there are a gazillion whois modules, and when I run my
domaincheck program on a machine where I haven't yet installed
whois, it's helpful to have a reminder of which one I should
install. (Of course, if you have one of the other whois modules
installed, the program will fail somewhere else.)

try:
import whois
# python-whois from pypi, not whois from pypi or python-whois from debian
# https://bitbucket.org/richardpenman/pywhois
except ImportError:
print("Couldn't import whois. Try: pip3 install python-whois")
sys.exit(1)

The third case has already been mentioned: modules that change name
but don't change their APIs much.

# Tkinter changed capitalization from Python 2 to Python 3.
try:
import tkinter
except ModuleNotFoundError:
import Tkinter as tkinter

I thought I had examples for gtk and qt -- GUI libraries change
their import syntax a lot -- but I can't find them.

...Akkana
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue36649] Windows Store app install registry keys have incorrect paths

2019-04-18 Thread Steve Dower


Change by Steve Dower :


--
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



[issue36657] AttributeError

2019-04-18 Thread maak


maak  added the comment:

FLAGS.train_dir has a boolean value which is checking true or false  
and i also have same issue import os
>>> os.path.join(True, 'best_checkpoint')
Traceback (most recent call last):
  File "", line 1, in 
  File 
"/usr/local/Cellar/python@2/2.7.14_3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/posixpath.py",
 line 70, in join
elif path == '' or path.endswith('/'):
AttributeError: 'bool' object has no attribute 'endswith'

can you give me a solution or idea how to solve issue

--

___
Python tracker 

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



[issue36658] Py_Initialze() throws error 'unable to load the file system encoding' when calling Py_SetPath with a path to a directory

2019-04-18 Thread Steve Dower


Steve Dower  added the comment:

This is probably a documentation failure more than anything else. We're in the 
middle of redesigning initialization though, so it's good timing to contribute 
this feedback.

The short answer is that you need to make sure Python can find the 
Lib/encodings directory, typically by putting the standard library in sys.path. 
Py_SetPath clears all inferred paths, so you need to specify all the places 
Python should look. (The rules for where Python looks automatically are 
complicated and vary by platform, which is something I'm keen to fix.)

Paths that don't exist are okay, and that's the zip file. You can choose to put 
the stdlib into a zip, and it will be found automatically if you name it the 
default path, but you can also leave it unzipped and reference the directory.

A full walk through on embedding is more than I'm prepared to type on my phone. 
Hopefully that's enough to get you going for now.

--
nosy: +vstinner

___
Python tracker 

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



[issue36659] distutils UnixCCompiler: Remove standard library path from rpath

2019-04-18 Thread STINNER Victor

STINNER Victor  added the comment:

My colleague Miro Hrončok points me to:
https://docs.fedoraproject.org/en-US/packaging-guidelines/#_beware_of_rpath

"Any rpath flagged by check-rpaths MUST be removed."

Note: On Linux, "chrpath" tool can be used to read, modify or remove the RPATH 
of an ELF binary (program or dynamic library).

--

___
Python tracker 

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



[issue36658] Py_Initialze() throws error 'unable to load the file system encoding' when calling Py_SetPath with a path to a directory

2019-04-18 Thread Stéphane Wirtel

Change by Stéphane Wirtel :


--
components: +Windows -Library (Lib)
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



[issue36657] AttributeError

2019-04-18 Thread Karthikeyan Singaravelan


Karthikeyan Singaravelan  added the comment:

> I think we could close this issue, it's not related to CPython itself.

Closing it. OP can reopen if needed. Thanks.

--
assignee: docs@python -> 
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed
type: compile error -> behavior

___
Python tracker 

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



[issue36657] AttributeError

2019-04-18 Thread Stéphane Wirtel

Stéphane Wirtel  added the comment:

Hi Karthikeyan,

I think we could close this issue, it's not related to CPython itself.

What do you think?

--
nosy: +matrixise

___
Python tracker 

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



[issue36659] distutils UnixCCompiler: Remove standard library path from rpath

2019-04-18 Thread STINNER Victor


Change by STINNER Victor :


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

___
Python tracker 

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



[issue36659] distutils UnixCCompiler: Remove standard library path from rpath

2019-04-18 Thread STINNER Victor


STINNER Victor  added the comment:

Output with attached PR 12876:

$ /opt/py38/bin/python3.8 -m venv opt_env
$ opt_env/bin/python -m pip install lxml
$ objdump -a -x $(opt_env/bin/python -c 'import lxml.etree; 
print(lxml.etree.__file__)')|grep -i rpath
  RPATH/opt/py38/lib/

... Oops, the RPATH is still here. Maybe I misunderstood the purpose of the 
change :-(

--

___
Python tracker 

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



[issue36659] distutils UnixCCompiler: Remove standard library path from rpath

2019-04-18 Thread STINNER Victor


New submission from STINNER Victor :

Since 2010, the Fedora packages of Python are using a patch on distutils 
UnixCCompiler to remove standard library path from rpath. The patch has been 
written by David Malcolm for Python 2.6.4:

* https://src.fedoraproject.org/rpms/python38/blob/master/f/1-rpath.patch
* 
https://src.fedoraproject.org/rpms/python2/c/f5df1f834310948b32407933e3b8713e1121105b

I propose to make this change upstream so other Linux distributions will 
benefit on this change: see attached PR.

"rpath" stands for "run-time search path". Dynamic linking loaders use the 
rpath to find required libraries:
https://en.wikipedia.org/wiki/Rpath

Full example. Install Python in /opt/py38 with RPATH=/opt/py38/lib, to ensure 
that Python looks for libpython in this directory:

$ cd path/to/python/sources
$ ./configure --prefix /opt/py38 LDFLAGS="-Wl,-rpath=/opt/py38/lib/" 
--enable-shared
$ make
$ make install  # on my system, my user can write into /opt ;-)
$ objdump -a -x /opt/py38/bin/python3.8|grep -i rpath
  RPATH/opt/py38/lib/
$ objdump -a -x /opt/py38/lib/libpython3.8m.so|grep -i rpath
  RPATH/opt/py38/lib/

Python is installed with RPATH:

$ /opt/py38/bin/python3.8 -m sysconfig|grep -i rpath
BLDSHARED = "gcc -pthread -shared -Wl,-rpath=/opt/py38/lib/"
CONFIGURE_LDFLAGS = "-Wl,-rpath=/opt/py38/lib/"
CONFIG_ARGS = "'--prefix' '/opt/py38' 
'LDFLAGS=-Wl,-rpath=/opt/py38/lib/' '--enable-shared'"
LDFLAGS = "-Wl,-rpath=/opt/py38/lib/"
LDSHARED = "gcc -pthread -shared -Wl,-rpath=/opt/py38/lib/"
PY_CORE_LDFLAGS = "-Wl,-rpath=/opt/py38/lib/"
PY_LDFLAGS = "-Wl,-rpath=/opt/py38/lib/"

Now the difference is how these flags are passed to third party C extensions.

$ cd $HOME
$ /opt/py38/bin/python3.8 -m venv opt_env
$ opt_env/bin/python -m pip install lxml
$ objdump -a -x $(opt_env/bin/python -c 'import lxml.etree; 
print(lxml.etree.__file__)')|grep -i rpath
  RPATH/opt/py38/lib/

lxml is compiled with the RPATH. This issue proposes to omit the Python RPATH 
here.

Comparison with Fedora Python which already contains the change:

$ python3 -m venv fed_venv  # FYI: it's Python 3.7 on Fedora 29
$ fed_venv/bin/python -m pip install lxml
$ objdump -a -x $(fed_venv/bin/python -c 'import lxml.etree; 
print(lxml.etree.__file__)')|grep -i rpath

^^ empty output: no RPATH, it's the expected behavior

... I'm not sure that the example using /usr/bin/python3.7 is useful, because 
it's not built using RPATH ...

$ objdump -a -x /usr/bin/python3.7 |grep -i rpath
$ python3.7 -m sysconfig|grep -i rpath
$ objdump -a -x /usr/lib64/libpython3.7m.so |grep -i rpath

^^ no output, it's not built with RPATH

--
components: Library (Lib)
messages: 340496
nosy: vstinner
priority: normal
severity: normal
status: open
title: distutils UnixCCompiler: Remove standard library path from rpath
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



[issue36657] AttributeError

2019-04-18 Thread Karthikeyan Singaravelan


Karthikeyan Singaravelan  added the comment:

Please check the value of FLAGS.train_dir which I guess has a boolean value. 
This is not a bug with CPython.

$ python2
Python 2.7.14 (default, Mar 12 2018, 13:54:56)
[GCC 4.2.1 Compatible Apple LLVM 7.0.2 (clang-700.1.81)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.path.join(True, 'best_checkpoint')
Traceback (most recent call last):
  File "", line 1, in 
  File 
"/usr/local/Cellar/python@2/2.7.14_3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/posixpath.py",
 line 70, in join
elif path == '' or path.endswith('/'):
AttributeError: 'bool' object has no attribute 'endswith'

--

___
Python tracker 

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



[issue36658] Py_Initialze() throws error 'unable to load the file system encoding' when calling Py_SetPath with a path to a directory

2019-04-18 Thread RimacV


New submission from RimacV :

I compiled the source of CPython 3.7.3 myself on Windows with Visual Studio 
2017 together with some packages like e.g numpy. When I start the Python 
Interpreter I am able to import and use numpy. However when I am running the 
same script via the C-API I get an ModuleNotFoundError. 

So the first thing I did, was to check if numpy is in my site-packages 
directory and indeed there is a folder named numpy-1.16.2-py3.7-win-amd64.egg. 
(Makes sense because the python interpreter can find numpy)

The next thing I did was get some information about the sys.path variable 
created when running the script via the C-API. 

# sys.path content 
C:\Work\build\product\python37.zip
C:\Work\build\product\DLLs
C:\Work\build\product\lib
C:\PROGRAM FILES (X86)\MICROSOFT VISUAL 
STUDIO\2017\PROFESSIONAL\COMMON7\IDE\EXTENSIONS\TESTPLATFORM
C:\Users\rvq\AppData\Roaming\Python\Python37\site-packages

Examining the content of sys.path I noticed two things. 

1. 
C:\Work\build\product\python37.zip has the correct path 
'C:\Work\build\product\'. There was just no zip file. All my files and 
directory were unpacked. So I zipped the files to an archive named python37.zip 
and this resolved the import error.

2. C:\Users\rvq\AppData\Roaming\Python\Python37\site-packages is wrong it 
should be C:\Work\build\product\Lib\site-packages but I dont know how this 
wrong path is created. 


The next thing I tried was to use 
Py_SetPath(L"C:/Work/build/product/Lib/site-packages") before calling 
Py_Initialize(). This led to the 

Fatal Python Error 'unable to load the file system encoding' 
ModuleNotFoundError: No module named 'encodings'


I created a minimal c++ project with exact these two calls and started to debug 
Cpython. 

int main()
{
  Py_SetPath(L"C:/Work/build/product/Lib/site-packages");
  Py_Initialize();
}

I tracked the call of Py_Initialize() down to the call of 

static int
zipimport_zipimporter___init___impl(ZipImporter *self, PyObject *path)

inside of zipimport.c

The comment above this function states the following: 

Create a new zipimporter instance.
'archivepath' must be a path-like object to a zipfile, or to a specific path
inside a zipfile. For example, it can be '/tmp/myimport.zip', or
'/tmp/myimport.zip/mydirectory', if mydirectory is a valid directory inside
the archive.
'ZipImportError' is raised if 'archivepath' doesn't point to a valid Zip
archive.
The 'archive' attribute of the zipimporter object contains the name of the
zipfile targeted.


So for me it seems that the C-API expects the path set with Py_SetPath to be a 
path to a zipfile. Is this expected behaviour or is it a bug? 
If it is not a bug is there a way to changes this so that it can also detect 
directories? 

PS: The ModuleNotFoundError did not occur for me when using Python 3.5.2+, 
which was the version I used in my project before. I also checked if I had set 
any PYTHONHOME or PYTHONPATH environment variables but I did not see one of 
them on my system.

--
components: Library (Lib)
files: Capture.PNG
messages: 340494
nosy: rvq
priority: normal
severity: normal
status: open
title: Py_Initialze() throws error 'unable to load the file system encoding' 
when calling Py_SetPath with a path to a directory
type: behavior
versions: Python 3.7
Added file: https://bugs.python.org/file48274/Capture.PNG

___
Python tracker 

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



[issue36657] AttributeError

2019-04-18 Thread maak


maak  added the comment:

File 
"/home/maak/PycharmProjects/Fyp/venv/local/lib/python2.7/site-packages/tensorflow/python/platform/app.py",
 line 48, in run
_sys.exit(main(_sys.argv[:1] + flags_passthrough))
  File "main.py", line 132, in main
bestmodel_dir = os.path.join(FLAGS.train_dir, "best_checkpoint")
  File "/home/maak/PycharmProjects/Fyp/venv/lib/python2.7/posixpath.py", line 
70, in join
elif path == '' or path.endswith('/'):
AttributeError: 'bool' object has no attribute 'endswith'

--

___
Python tracker 

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



[issue31652] make install fails: no module _ctypes

2019-04-18 Thread Nils Goroll


Nils Goroll  added the comment:

In case this helps: I noticed this during the build:


*** WARNING: renaming "_ssl" since importing it failed: ld.so.1: python: fatal: 
libssl.so.1.1: open failed: No such file or directory
*** WARNING: renaming "_hashlib" since importing it failed: ld.so.1: python: 
fatal: libssl.so.1.1: open failed: No such file or directory
*** WARNING: renaming "_ctypes" since importing it failed: ld.so.1: python: 
fatal: libffi.so.6: open failed: No such file or directory

...

Following modules built successfully but were removed because they could not be 
imported:
_ctypes   _hashlib  _ssl   

In my case the reason was that libffi was installed under /opt/local, so the 
fix was:


./configure LDFLAGS='-L/opt/local/lib -R/opt/local/lib'

and rebuild

For other users I would recommend to inspect the build output for _ctypes 
related errors, I am not saying that the cause is the same

--
nosy: +slink

___
Python tracker 

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



[issue36657] AttributeError

2019-04-18 Thread Karthikeyan Singaravelan


Karthikeyan Singaravelan  added the comment:

Please add a short script and explain the problem over why it's a bug in 
CPython and not a problem with the program. The error says path has a boolean 
value and doesn't have endswith which is a method on string object.

--
nosy: +xtreak

___
Python tracker 

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



[issue36657] AttributeError

2019-04-18 Thread maak


New submission from maak :

elif path == '' or path.endswith('/'):
AttributeError: 'bool' object has no attribute 'endswith'

--
assignee: docs@python
components: Documentation
messages: 340490
nosy: docs@python, maakvol
priority: normal
severity: normal
status: open
title: AttributeError
type: compile error
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



[issue28552] Distutils fail if sys.executable is None

2019-04-18 Thread STINNER Victor


STINNER Victor  added the comment:

This issue can be reproduced with:

diff --git a/Lib/site.py b/Lib/site.py
index ad1146332b..c850109c19 100644
--- a/Lib/site.py
+++ b/Lib/site.py
@@ -638,3 +638,5 @@ def _script():
 
 if __name__ == '__main__':
 _script()
+
+sys.executable = None

Attached PR 12875 fix distutils.sysconfig and the distutils build command if 
sys.executable is None or an empty string. I don't expect that everything works 
magically, but at least, it's possible to run "./python -m distutils.sysconfig" 
and use "make" in Python which runs "./python -E ./setup.py build". I'm 
surprised, but setup.py is able to build C extensions using sys.executable = 
None :-)

I made a similar fix for sysconfig in bpo-7774: commit 
171ba0504aa778d81346ea56fc9000b29d4d3e1d.

--
nosy: +vstinner

___
Python tracker 

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



[issue7774] sys.executable: wrong location if zeroth command argument is modified.

2019-04-18 Thread STINNER Victor


Change by STINNER Victor :


--
pull_requests: +12800

___
Python tracker 

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



[issue28552] Distutils fail if sys.executable is None

2019-04-18 Thread STINNER Victor


Change by STINNER Victor :


--
keywords: +patch
pull_requests: +12799
stage: needs patch -> patch review

___
Python tracker 

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



[issue36596] tarfile module considers anything starting with 512 bytes of zero bytes to be a valid tar file

2019-04-18 Thread Read Hughes


Read Hughes  added the comment:

GNU description of tar file format: 
http://www.gnu.org/software/tar/manual/html_node/Standard.html

Particular quotes that are relevant:

>Physically, an archive consists of a series of file entries terminated by an 
>end-of-archive entry, which consists of two 512 blocks of zero bytes

>Each file archived is represented by a header block which describes the file, 
>followed by zero or more blocks which give the contents of the file. At the 
>end of the archive file there are two 512-byte blocks filled with binary zeros 
>as an end-of-file marker

The header itself is 257 bytes padded with NUL until it reaches 512.

No input other than this, just trying to bring any relevant information to this 
issue that may help

--
nosy: +rthugh02

___
Python tracker 

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



Re: Friday Filosofical Finking: Import protections

2019-04-18 Thread Grant Edwards
On 2019-04-18, DL Neil  wrote:
> On 18/04/19 8:44 AM, Grant Edwards wrote:
>> On 2019-04-17, DL Neil  wrote:
>> 
>>> Do you bother with exception handling for import statements?
>> 
>> Sometimes.  There are two cases when I do that:
>> 
>>   1. When the module has different names under Python2 and Python3 and
>>  the program tries first one, then the other.
>
> Excellent example - and a lot easier than interrogating os.environ (for 
> example), ie permission cf forgiveness.
>
>
>>   2. When the program can still do something useful (if perhaps
>>  feature-limited) without the imported module by substituting
>>  something else in its place.
>
> Any (publishable) examples?

I can describe one example, but the source doesn't belong to me so I
can't publish it.  I wrote an application that dissects a proprietary
Ethernet protocol and prints out what's going on as a human-readable
transcript.

In the "normal" case, it uses pylibpcap to either capture packets live
or read them from a saved capture file.  If the import of pylibpcap
fails, I replace it with a built-in class which can only read packets
from a one particular type/version of capture file.  If you try to do
a live capture with the built-in class (or read an unsupported capture
file format), it prints an error message saying that's only possible
with pylibpcap and exits.

I can recall one or two other similar cases where a built-in class
handles a limited set of the functionality provided by the missing
module, but they're too obscure to describe succinctly...

>> You've omitted the second thing assumed by the authors: without numpy,
>> scipy, pandas, et alia the program can do nothing useful.
>
> but... what of the third inherent assumption: that the user(s) will be 
> able to handle the situation (discussed in another msg 'here')?

Or they notify somebody who can.  The probability of being able to
programmatically download and properly install a missing module in
order to automagically recover from a failed import is, in practice,
zero.  You could try to format the error in a prettier way, I suppose,
but that's just going to confuse experienced users and admins, and it
isn't going to help the user who doesn't know what to do anyway.

-- 
Grant Edwards   grant.b.edwardsYow! Don't hit me!!  I'm in
  at   the Twilight Zone!!!
  gmail.com

-- 
https://mail.python.org/mailman/listinfo/python-list


[issue36652] Non-embedded zip distribution

2019-04-18 Thread Steve Dower


Steve Dower  added the comment:

Also see the packages on nuget.org, which are essentially just zip files (with 
metadata and installation tools available).

--
resolution:  -> duplicate
stage:  -> resolved
status: open -> closed
superseder:  -> Please provide a .zip Windows release of Python that is not 
crippled/for embedding only

___
Python tracker 

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



[issue36651] Asyncio Event Loop documentation inconsistency (call_later and call_at methods)

2019-04-18 Thread Andrew Svetlov


Change by Andrew Svetlov :


--
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



[issue36646] os.listdir() got permission error in Python3.6 but it's fine in Python2.7

2019-04-18 Thread Eryk Sun


Eryk Sun  added the comment:

For me in Windows 10, os.listdir(u"C:\\Temp") uses the same sequence of WINAPI 
and NT system calls in 2.7 and 3.6.

Setup the query for all files ("*"), and return the first matching entry:

FindFirstFileW
FindFirstFileExW

NtOpenFile(
ObjectAttributes=(
ObjectName="\??\C:\Temp\",
Attributes=OBJ_CASE_INSENSITIVE)
DesiredAccess=(
SYNCHRONIZE | 
FILE_LIST_DIRECTORY),
ShareAccess=(
FILE_SHARE_READ | 
FILE_SHARE_WRITE | 
FILE_SHARE_DELETE),
OpenOptions=(
FILE_DIRECTORY_FILE | 
FILE_SYNCHRONOUS_IO_NONALERT |
FILE_OPEN_FOR_BACKUP_INTENT))

NtQuerDirectoryFileEx(
FileInformationClass=FileBothDirectoryInformation, 
QueryFlags=SL_RETURN_SINGLE_ENTRY,
FileName="*")

Repeat for the remaining entries:

FindNextFileW

Return the next entry from a 4 KiB buffer. If the buffer is
empty, refill it with the following call, until the query is
exhausted (i.e. STATUS_NO_MORE_FILES):

NtQuerDirectoryFileEx(
FileInformationClass=FileBothDirectoryInformation,
Length=4096)

Unfortunately, many NT status codes map to ERROR_ACCESS_DENIED (5). If it's 
STATUS_ACCESS_DENIED (0xC022), then probably NtOpenFile failed. Try 
checking the last NT status value with ctypes. For example:

>>> import os, ctypes
>>> ntdll = ctypes.WinDLL('ntdll')
>>> ntdll.RtlGetLastNtStatus.restype = ctypes.c_ulong
>>> try:
... os.listdir(u'C:\\Users\\Administrator')
... except:
... print(hex(ntdll.RtlGetLastNtStatus()))
...
0xc022

Do you have any anti-malware programs running? If so, try disabling them. They 
can hook APIs or attach to the I/O stack with a filter driver (e.g. to deny an 
I/O request that's disallowed by a rule). If disabling your anti-malware 
software allows access, then you'll need to set a rule to grant access to 
Python 3.

--

___
Python tracker 

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



Re: Importing module from another subdirectory

2019-04-18 Thread Rich Shepard

On Thu, 18 Apr 2019, dieter wrote:


Python knows about 2 kinds of "regular" imports: absolute ones and
relative ones. "Absolute" imports are guided by "sys.path" -- in the
simple case, a sequence of folders containing modules and/or pacakges.
Relative imports are guided in a similar way by the current packages's
"__path__", which typically contains just one element - the folder from
which the current package was loaded.


Dieter,

Thanks. My previous applications used a single directory rather than
separating the model, views, and controller so now I know what to learn to
resolve this issue.

Regards,

Rich
--
https://mail.python.org/mailman/listinfo/python-list


Re: Importing module from another subdirectory

2019-04-18 Thread Rich Shepard

On Wed, 17 Apr 2019, Sayth Renshaw wrote:


Apologies I don't know the answer but went looking. This guide should
answer the question. Didn't know it was so difficult to be honest.

https://chrisyeh96.github.io/2017/08/08/definitive-guide-python-imports.html#example-directory-structure

Then there was this rather long list of traps.
http://python-notes.curiousefficiency.org/en/latest/python_concepts/import_traps.html


Sayth,

Thank you. My web search terms didn't find these.

Regards,

Rich
--
https://mail.python.org/mailman/listinfo/python-list


[issue35755] On Unix, shutil.which() and subprocess no longer look for the executable in the current directory if PATH environment variable is not set

2019-04-18 Thread STINNER Victor


STINNER Victor  added the comment:

> For Python 2.7... well, I don't think that this issue is important enough to 
> justify a backport. I prefer to do nothing rather than having to deal with 
> unhappy users complaining that Python 2.7 changed broke their application in 
> a minor 2.7.x release :-) Even if, again, the risk of regression is very low.

Same rationale for Python 3.6. While I would call this change related to 
security, I'm not comfortable to backport the change. The issue is not 
important enough compared to the risk of regression.

--

___
Python tracker 

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



[issue36651] Asyncio Event Loop documentation inconsistency (call_later and call_at methods)

2019-04-18 Thread miss-islington


miss-islington  added the comment:


New changeset d29b3dd9227cfc4a23f77e99d62e20e063272de1 by Miss Islington (bot) 
in branch '3.7':
bpo-36651: Fixed Asyncio Event Loop documentation inconsistency (GH-12866)
https://github.com/python/cpython/commit/d29b3dd9227cfc4a23f77e99d62e20e063272de1


--

___
Python tracker 

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



[issue36651] Asyncio Event Loop documentation inconsistency (call_later and call_at methods)

2019-04-18 Thread Andrew Svetlov


Change by Andrew Svetlov :


--
versions: +Python 3.7

___
Python tracker 

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



[issue36651] Asyncio Event Loop documentation inconsistency (call_later and call_at methods)

2019-04-18 Thread miss-islington


miss-islington  added the comment:


New changeset 7e954e7de4f3777b5ce239640bd2b76aced09561 by Miss Islington (bot) 
(Enrico Alarico Carbognani) in branch 'master':
bpo-36651: Fixed Asyncio Event Loop documentation inconsistency (GH-12866)
https://github.com/python/cpython/commit/7e954e7de4f3777b5ce239640bd2b76aced09561


--
nosy: +miss-islington

___
Python tracker 

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



[issue36651] Asyncio Event Loop documentation inconsistency (call_later and call_at methods)

2019-04-18 Thread miss-islington


Change by miss-islington :


--
pull_requests: +12798

___
Python tracker 

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



Re: Function to determine list max without itertools

2019-04-18 Thread MRAB

On 2019-04-18 08:39, Sayth Renshaw wrote:

Thank you for the advice everyone.



The first thing to try is find every place where you update myMax, and


This was actually where I was going wrong. I was setting max but then 
overwriting it with item. Then kept checking item only to return myMax.

I went looking for other solutions as I thought I must be well off the path in 
the shrubs but I was actually close.

This is how I ended up. There may be better solutions but this works.

def maximum(listarg):
 items = list(listarg)
 myMax = items[0]
 for item in items:
 for i in items[items.index(item)+1:len(items)]:
 if myMax < i:
 myMax = i
 else:
 pass
 
 return myMax
   

It's still overly complicated.

 
if __name__ == "__main__":

 print(maximum([4,3,6,2,1,4]))


--
https://mail.python.org/mailman/listinfo/python-list


[issue36652] Non-embedded zip distribution

2019-04-18 Thread Ronald Oussoren


Ronald Oussoren  added the comment:

This is a duplicate of issue36010, which contains an explanation of why there 
is no installation method with a zipfile.

--
nosy: +ronaldoussoren

___
Python tracker 

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



[issue36648] MAP_SHARED isn't proper for anonymous mappings for VxWorks

2019-04-18 Thread LihuaZhao


LihuaZhao  added the comment:

>>What is the current behavior of m = mmap.mmap(-1, 100)? Does it raise an 
>>exception?

No, the following statement will return -1 without PR 12394

m_obj->data = mmap(NULL, map_size,
   prot, flags,
   fd, offset);

>>I don't understand why PR 12394 modifies flags afterwards, whereas "m = 
>>mmap.mmap(-1, 100)" doesn't specify explicitly flags. So the bug looks to be 
>>default flags set by Python, no?

Yes, this statement doesn't specify the flag, but as you said, the 
new_mmap_object() firstly set MAP_SHARED for flag, and in later code:

if (fd == -1) {
m_obj->fd = -1;
.
#ifdef MAP_ANONYMOUS
/* BSD way to map anonymous memory */
flags |= MAP_ANONYMOUS;

#else
#endif

This routine will pass (MAP_ANONYMOUS | MAP_SHARED) to mmap and fd is -1, this 
is true for Linux, but for VxWorks, if fd is -1, the flag type should be 
(MAP_ANONYMOUS | MAP_PRIVATE), and this behavior is not part of the POSIX 
standard, we can't say VxWorks isn't right.

So my changes clear MAP_SHARED and set MAP_PRIVATE when the system type is 
VxWorks.

>>Is MAP_SHARED constant available in C on VxWorks?

Yes, but for MAP_ANONYMOUS, it require set MAP_PRIVATE.

This PR still is try to enhance VxWorks support, doesn't affect Python user, 
and only change the behavior of VxWorks, other system don't have this issue, 
and also won't be influenced

--

___
Python tracker 

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



[issue35100] urllib.parse.unquote_to_bytes: needs "escape plus" option

2019-04-18 Thread andrew-g


andrew-g  added the comment:

pinging the issue to try get the PR reviewed

--
nosy: +andrew-g

___
Python tracker 

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



[issue36640] python ibm_db setup.py post install script does not seem to work from Anaconda

2019-04-18 Thread Saba Kauser


Saba Kauser  added the comment:

I was able to determine the reason. 
When running through anaconda, the pip copies ibm_db.so to site-packages path. 
However, as logged in user, install_name_tool fails with permission denied 
error.

BLR-D-MACOS03:site-packages skauser$ install_name_tool -change 
@loader_path/clidriver/lib/libdb2.dylib libdb2.dylib 
ibm_db.cpython-37m-darwin.so
error: /Library/Developer/CommandLineTools/usr/bin/install_name_tool: can't 
open input file: ibm_db.cpython-37m-darwin.so for writing (Permission denied)
error: /Library/Developer/CommandLineTools/usr/bin/install_name_tool: can't 
lseek to offset: 0 in file: ibm_db.cpython-37m-darwin.so for writing (Bad file 
descriptor)
error: /Library/Developer/CommandLineTools/usr/bin/install_name_tool: can't 
write new headers in file: ibm_db.cpython-37m-darwin.so (Bad file descriptor)
error: /Library/Developer/CommandLineTools/usr/bin/install_name_tool: can't 
close written on input file: ibm_db.cpython-37m-darwin.so (Bad file descriptor)
BLR-D-MACOS03:site-packages skauser$ sudo install_name_tool -change 
@loader_path/clidriver/lib/libdb2.dylib libdb2.dylib 
ibm_db.cpython-37m-darwin.so

Even if i do "sudo pip install ibm_db", although the package is copied to 
site-packages, install_name_tool fails with error.
However, if build the source via pip as :

cd  /Users/skauser/python-ibmdb/IBM_DB/ibm_db
sudo pip install .

install_name_tool is able to execute on ibm_db*.so.

Do you have any idea why would the permission problem occur only if I do pip 
install from pypi and not from source?

--

___
Python tracker 

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



[issue36635] Add _testinternalcapi module

2019-04-18 Thread STINNER Victor


STINNER Victor  added the comment:


New changeset 23bace26ec265557697cf3b578b361c178070cd5 by Victor Stinner in 
branch 'master':
bpo-36635: Add _testinternalcapi module (GH-12841)
https://github.com/python/cpython/commit/23bace26ec265557697cf3b578b361c178070cd5


--

___
Python tracker 

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



[issue36648] MAP_SHARED isn't proper for anonymous mappings for VxWorks

2019-04-18 Thread STINNER Victor


STINNER Victor  added the comment:

I don't understand why PR 12394 modifies flags afterwards, whereas "m = 
mmap.mmap(-1, 100)" doesn't specify explicitly flags. So the bug looks to be 
default flags set by Python, no?

int flags = MAP_SHARED;
...

if (!PyArg_ParseTupleAndKeywords(args, kwdict, "in|iii" _Py_PARSE_OFF_T, 
keywords,
 , _size, , ,
 , ))

Is MAP_SHARED constant available in C on VxWorks?

Is mmap.MAP_SHARED constant available in Python on VxWorks?

--

___
Python tracker 

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



[issue36648] MAP_SHARED isn't proper for anonymous mappings for VxWorks

2019-04-18 Thread STINNER Victor


STINNER Victor  added the comment:

What is the current behavior of m = mmap.mmap(-1, 100)? Does it raise an 
exception?

--

___
Python tracker 

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



[issue36277] pdb's recursive debug command is not listed in the docs

2019-04-18 Thread Antony Lee


Change by Antony Lee :


--
nosy:  -Antony.Lee

___
Python tracker 

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



[issue36656] Allow os.symlink(src, target, force=True) to prevent race conditions

2019-04-18 Thread Tom Hale


New submission from Tom Hale :

I cannot find a race-condition-free way to force overwrite an existing symlink.

os.symlink() requires that the target does not exist, meaning that it could be 
created via race condition the two workaround solutions that I've seen:

1. Unlink existing symlink (could be recreated, causing following symlink to 
fail)

2. Create a new temporary symlink, then overwrite target (temp could be changed 
between creation and replace.

The additional gotcha with the safer (because the attack filename is unknown) 
option (2) is that replace() may fail if the two files are on separate 
filesystems.

I suggest an additional `force=` argument to os.symlink(), defaulting to 
`False` for backward compatibility, but allowing atomic overwriting of a 
symlink when set to `True`.

I would be willing to look into a PR for this.

Prior art:  https://stackoverflow.com/a/55742015/5353461

--
messages: 340474
nosy: Tom Hale
priority: normal
severity: normal
status: open
title: Allow os.symlink(src, target, force=True) to prevent race conditions
versions: Python 3.7

___
Python tracker 

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



[issue36655] Division Precision Problem

2019-04-18 Thread Eric V. Smith


Eric V. Smith  added the comment:

Also see https://docs.python.org/3/tutorial/floatingpoint.html for some 
Python-specific details.

--
nosy: +eric.smith

___
Python tracker 

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



[issue36655] Division Precision Problem

2019-04-18 Thread Christian Heimes


Christian Heimes  added the comment:

This is the expected and correct behavior. Python's float are IEEE 754 floats, 
https://en.wikipedia.org/wiki/IEEE_754. IEE 754 have a limited precision. 
224847175712806907706081280 / 4294967296 is not exactly dividable under IEEE 
754 semantics. 

>>> a=224847175712806907706081280
>>> b=4294967296
>>> a/b
5.235131264496755e+16

--
nosy: +christian.heimes
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



[issue36655] Division Precision Problem

2019-04-18 Thread kulopo


New submission from kulopo :

>>> a=224847175712806907706081280
>>> b=4294967296
>>> assert int(a*b/b)==int(a)
Traceback (most recent call last):
  File "", line 1, in 
AssertionError
(a can be exact divided by b)

--
messages: 340471
nosy: kulopo
priority: normal
severity: normal
status: open
title: Division Precision Problem
type: behavior
versions: Python 3.7

___
Python tracker 

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



Re: Friday Filosofical Finking: Import protections

2019-04-18 Thread Gregory Ewing

DL Neil wrote:
Thus the basic question: why do we (apparently) so seldom consider the 
possibility of an ImportError?


Because the cases in which we can do something useful about
it are relatively rare.

--
Greg
--
https://mail.python.org/mailman/listinfo/python-list


Re: immutability is not strictly the same as having an unchangeable value, it is more subtle

2019-04-18 Thread Chris Angelico
On Thu, Apr 18, 2019 at 6:16 PM Gregory Ewing
 wrote:
>
> Arup Rakshit wrote:
> > What protocols I need to
> > learn, to define a custom immutable class ?
>
> That depends on how strictly you want to enforce immutability.
>
> The easiest thing is not to enforce it at all and simply refrain
> from mutating it. This is very often done.
>
> You can provide some protection against accidental mutation
> by using properties

Another reasonably easy way to make a custom immutable class is to
make use of namedtuple. You can subclass a namedtuple to add methods
to it, for instance.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Function to determine list max without itertools

2019-04-18 Thread Chris Angelico
On Thu, Apr 18, 2019 at 5:41 PM Sayth Renshaw  wrote:
>
> Thank you for the advice everyone.
>
> >
> > The first thing to try is find every place where you update myMax, and
>
> This was actually where I was going wrong. I was setting max but then 
> overwriting it with item. Then kept checking item only to return myMax.
>
> I went looking for other solutions as I thought I must be well off the path 
> in the shrubs but I was actually close.
>
> This is how I ended up. There may be better solutions but this works.
>
> def maximum(listarg):
> items = list(listarg)
> myMax = items[0]
> for item in items:
> for i in items[items.index(item)+1:len(items)]:
> if myMax < i:
> myMax = i
> else:
> pass
>
> return myMax
>
>
> if __name__ == "__main__":
> print(maximum([4,3,6,2,1,4]))
>

This is where I would strongly recommend printing lots of stuff out,
to explore what the algorithm is doing at each point. See if you can
figure out when myMax is being updated.

(Also: items.index(item) will potentially give the wrong result if you
have duplicates.)

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: immutability is not strictly the same as having an unchangeable value, it is more subtle

2019-04-18 Thread Gregory Ewing

Arup Rakshit wrote:

What protocols I need to
learn, to define a custom immutable class ?


That depends on how strictly you want to enforce immutability.

The easiest thing is not to enforce it at all and simply refrain
from mutating it. This is very often done.

You can provide some protection against accidental mutation
by using properties, for example,

class Foo:

def __init__(self, x):
self._x = x

@property
def x(self):
return self._x

This will let you read the x attribute but not directly assign
to it. Of course, it doesn't prevent someone from accessing the
underlying _x attribute, but there's no way to do that for a
class defined in Python. The only way to make a completely
bulletproof immutable object would be to write an extension
module in C or Cython.

--
Greg
--
https://mail.python.org/mailman/listinfo/python-list


Re: Function to determine list max without itertools

2019-04-18 Thread Sayth Renshaw
Thank you for the advice everyone.

> 
> The first thing to try is find every place where you update myMax, and

This was actually where I was going wrong. I was setting max but then 
overwriting it with item. Then kept checking item only to return myMax.

I went looking for other solutions as I thought I must be well off the path in 
the shrubs but I was actually close.

This is how I ended up. There may be better solutions but this works.

def maximum(listarg): 
items = list(listarg) 
myMax = items[0] 
for item in items:
for i in items[items.index(item)+1:len(items)]:
if myMax < i:
myMax = i
else:
pass

return myMax
  

if __name__ == "__main__":
print(maximum([4,3,6,2,1,4]))


Cheers

Sayth
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue36008] [good first issue] Update documentation for 3.8

2019-04-18 Thread Utkarsh Gupta


Utkarsh Gupta  added the comment:

Hey,

I am a new contributor, looking for an issue to start with.
Since this is a "good first issue", I wanted to know if I could take it?

I am myself at a dev sprint and would like to get it fixed :)
Mariatta, let me know if you have any problems with the same?

--
nosy: +utkarsh2102

___
Python tracker 

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



[issue36645] re.sub() library entry does not adequately document surprising change in behavior between versions

2019-04-18 Thread Karthikeyan Singaravelan


Change by Karthikeyan Singaravelan :


--
nosy: +serhiy.storchaka

___
Python tracker 

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



[issue36651] Asyncio Event Loop documentation inconsistency (call_later and call_at methods)

2019-04-18 Thread Karthikeyan Singaravelan


Change by Karthikeyan Singaravelan :


--
components: +asyncio
nosy: +asvetlov, yselivanov

___
Python tracker 

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



[issue36652] Non-embedded zip distribution

2019-04-18 Thread Karthikeyan Singaravelan


Change by Karthikeyan Singaravelan :


--
nosy: +steve.dower

___
Python tracker 

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



[issue35297] untokenize documentation is not correct

2019-04-18 Thread Utkarsh Gupta


Utkarsh Gupta  added the comment:

I am not sure if that's a documentation problem, is it?
If so, I'll be happy to send a PR :)

--
nosy: +utkarsh2102

___
Python tracker 

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



  1   2   >