[issue35928] socket makefile read-write discards received data

2019-02-10 Thread Ammar Askar


Ammar Askar  added the comment:

Recreatable on master as well, also Martin your suspicion seems correct, 
reverting 
https://github.com/python/cpython/commit/23db935bcf258657682e66464bf8512def8af830
 fixes it.

--
nosy: +ammar2, serhiy.storchaka
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



Re: The slash "/" as used in the documentation

2019-02-10 Thread Terry Reedy

On 2/10/2019 11:32 PM, Ian Kelly wrote:

On Sun, Feb 10, 2019 at 9:34 AM Chris Angelico  wrote:



Do you ACTUALLY want to call math.sin(x=1.234) or is it purely for the
sake of consistency? Aside from questions about the help format, what
is actually lost by the inability to pass those arguments by name?


No, but I wouldn't object to d.get(key='foo', default=12).


I don't see what dict acccess has to do with function calls.  But moving on.


It's partly
about consistency, but mostly I was reacting to Terry's comments in
that a) positional-only arguments are a "limitation"


If one thinks of Python's flexible signatures as 'normal', which they 
aren't, than positional-only seems like a limitation.  (Some other 
languages have somewhat similar flexibility.)  From a 
C/assembler/machine perspective, positional is normal.



and there is no
desire for the rest of Python to match CPython's behavior in this
instance,


For reasons of complexity and speed, without a countervailing argument, 
there is no desire to add to C-coded functions a flexibility that will 
mostly not be used.



and b) it sounds like a great deal of effort is being spent
on updating all the C function signatures one at a time


It tends to be done a module per PR.  I don't know what effort is needed 
since I have never done it.



so that the
help string can be updated to a form that is unfamiliar and not
intuitive


'*' is not 'intuitive either.  As I said elsewhere, multiple options 
were considered.  '/' was the favorite because it is 'connected' to '*' 
and more intuitive for dividing a list into two sublists.


Any, IDLE, but not help(), adds a comment to explain.
"['/' marks preceding arguments as positional only]"
The downside is that this and a following blank line add 2 lines to a 
calltip that is usually 2 lines, making it more obtrusive.  And once '/' 
is understood, the comment is extra noise.  So I am thinking of 
condensing it somehow.



and not normally accessible to pure Python functions without
some arm twisting.


In my first response on this thread I explained and demonstrated how to 
access signature strings from Python, as done by both help() and IDLE. 
Please read if you are concerned about this.  There is hardly any extra 
difficulty.  I did not discuss how to process the signature string 
returned by str(signature) nor how to access the information in 
Signature objects otherwise, but the str and Signature docs cover these.


It is possible the a sentence about '/' should be added somewhere.


If every function has to be updated anyway, why not
update them by fixing their signatures?


I proposed this once and the answer was that it would be too costly.

--
Terry Jan Reedy

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


Re: The slash "/" as used in the documentation

2019-02-10 Thread Ian Kelly
On Mon, Feb 11, 2019 at 12:19 AM Terry Reedy  wrote:
> The pass-by-position limitation is not in CPython, it is the behavior of
> C functions, which is the behavior of function calls in probably every
> assembly and machine language.  Allowing the flexibility of Python
> function calls take extra code and slows function calls.
>
> math.sin, for instance, is a fast-as-possible wrapper around the C math
> library sin function.  It extracts the C double from the Python float,
> calls C sin, and returns the returned C double wrapped as a Python
> float.  Coredevs decided that being able to call math.sin(x=.3) is
> not worth the resulting slowdown.  I am rather sure that heavy users of
> the math module would agree.

For math.sin, sure, but what about, say, list.index? Here's the start
of the implementation:

static PyObject *
listindex(PyListObject *self, PyObject *args)
{
Py_ssize_t i, start=0, stop=Py_SIZE(self);
PyObject *v;

if (!PyArg_ParseTuple(args, "O|O&:index", ,
_PyEval_SliceIndex, ,
_PyEval_SliceIndex, ))


This is already paying the cost of not using C-style positional
function arguments, but then it only takes an argument tuple, so it
can't take keyword arguments anyway. Why? Wouldn't it be nice to be
able to write:

mylist.index(42, start=10, stop=99)

instead of:

mylist.index(42, 10, 99)

This would also allow stop to be passed alone:

mylist.index(42, stop=99)

rather than having to pass the default value for start explicitly just
so we can pass stop:

mylist.index(42, 0, 99)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: The use of type()

2019-02-10 Thread ^Bart

a = 5
print(a.__class__.__name__)

int

b = 5.0
print(b.__class__.__name__)

float


Thank you very much! :)

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


[issue35928] socket makefile read-write discards received data

2019-02-10 Thread Palle Ravn


Palle Ravn  added the comment:

>>> f = TextIOWrapper(BufferedRWPair(BytesIO(b"Hello\nYou\n"), BytesIO()))
>>> f.readline()
'Hello\n'
>>> f.write(_)
6
>>> f.readline()  # Returns empty string
''

--

___
Python tracker 

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



Re: The slash "/" as used in the documentation

2019-02-10 Thread Terry Reedy

On 2/10/2019 10:47 AM, Ian Kelly wrote:

On Sat, Feb 9, 2019 at 1:19 PM Terry Reedy  wrote:


This is the result of Python being a project of mostly unpaid volunteers.

See my response in this thread explaining how '/' appears in help output
and IDLE calltips.  '/' only appears for CPython C-coded functions that
have been modified to use Argument Clinic.  A.C. was added, I believe,
in 3.5.  Simple builtins like len would have been the first to be
converted.  The math module was converted for 3.7.  There are some new
conversions for 3.8 and likely some will be left for future versions.


I'm sure there are good reasons for it like most things Python does, but I
can't help but wonder if working on removing the positional limitation from
CPython would be a better use of time.


The pass-by-position limitation is not in CPython, it is the behavior of 
C functions, which is the behavior of function calls in probably every 
assembly and machine language.  Allowing the flexibility of Python 
function calls take extra code and slows function calls.


math.sin, for instance, is a fast-as-possible wrapper around the C math 
library sin function.  It extracts the C double from the Python float, 
calls C sin, and returns the returned C double wrapped as a Python 
float.  Coredevs decided that being able to call math.sin(x=.3) is 
not worth the resulting slowdown.  I am rather sure that heavy users of 
the math module would agree.


--
Terry Jan Reedy

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


Re: The slash "/" as used in the documentation

2019-02-10 Thread Ian Kelly
On Sun, Feb 10, 2019 at 2:18 PM Avi Gross  wrote:
> I am not sure how python implements some of the functionality it does as
> compared to other languages with similar features. But I note that there are
> rules, presumably some for efficiency, such as requiring all keyword
> arguments to be placed after the last positional argument. I mean I can call
> func(a,b,c,d=1,e=2) but not func(a,b,d=1, c, e=2).
>
> So if you allowed a keyword to optionally be used for any positional
> argument other than the last, c, would it not require a change in this rule?
> I mean func(a="invalid",b,c,d=1,e=2) would violate the rule and so would
> making b a keyword version. In my example, and for this reason only, maybe c
> could work.

My suggestion was not to allow keyword arguments to arbitrarily
replace any positional parameter, or to otherwise change
argument-passing in any way. The suggestion was to drop
positional-only arguments from functions implemented in C instead of
just documenting them better. In the example above, if you want to
pass a by keyword, you would have to pass b and c by keyword as well.
That would still be true for functions implemented in C if a, b, and c
are no longer positional-only.

> The original motivation for keyword arguments included the concept of
> specifying a default if not used. Positional arguments have no default.
> Similarly, they are required if explicitly named in the function definition.
> So we are intermingling multiple concepts in the previous design.

Positional arguments are allowed to have defaults, and keyword-only
arguments are allowed to not have defaults. These are all valid
syntax:

# Allows a and b to be passed either positionally or by keyword
def foo(a=1, b=2): pass

# b is keyword-only
def foo(a=1, *, b=2): pass

# Allows a and b to be passed either positionally or by keyword
def foo(a, b): pass

# b is keyword-only and has no default
def foo(a, *, b): pass

Positional-ONLY arguments are not directly supported by the language,
but they exist in the C API and can also have defaults. For example,
dict.get takes two positional-only arguments. The second argument is
optional, and its default is None.

My point is that the axis of positional-only versus
positional-or-keyword versus keyword-only, and the axis of required
versus optional are entirely separate.

> I won't go on except to say it would break lots of existing code and
> potentially complicate new code.

Can you give an example of something that would be broken by updating
C API functions to name positional-only arguments instead of just
updating them to document that they're positional-only?
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue35813] shared memory construct to avoid need for serialization between processes

2019-02-10 Thread Davin Potts


Davin Potts  added the comment:

@giampaolo.rodola: Your patch from 3 days ago in issue35917 included additional 
tests around the SharedMemoryManager which are now causing test failures in my 
new PR.  This is my fault because I altered SharedMemoryManager to no longer 
support functionality from SyncManager that I thought could be confusing to 
include.  I am just now discovering this and am not immediately sure if simply 
removing the SharedMemoryManager-relevant lines from your patch is the right 
solution but I wanted to mention this thought right away.

Thank you for discovering that SyncManager was being overlooked in the tests 
and the nice patch in issue35917.

--

___
Python tracker 

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



[issue35813] shared memory construct to avoid need for serialization between processes

2019-02-10 Thread Davin Potts


Davin Potts  added the comment:

Docs and tests are now available in a new PR.  I have stayed focused on getting 
these docs and tests to everyone without delay but that means I have not yet 
had an opportunity to respond to the helpful comments, thoughtful questions, 
and threads that have popped up in the last few days.  I will follow up with 
all comments as quickly as possible starting in the morning.

There are two topics in particular that I hope will trigger a wider discussion: 
 the api around the SharedMemory class and the inclusion-worthiness of the 
shareable_wrap function.

Regarding the api of SharedMemory, the docs explain that not all of the current 
input parameters are supportable/enforceable across platforms.  I believe we 
want an api that is relevant across all platforms but at the same time we do 
not want to unnecessarily suppress/hide functionality that would be useful on 
some platforms -- there needs to be a balance between these motivations but 
where do we strike that balance?

Regarding the inclusion-worthiness of the shareable_wrap function, I 
deliberately did not include it in the docs but its docstring in the code 
explains its purpose.  If included, it would drastically simplify working with 
NumPy arrays; please see the code example in the docs demonstrating the use of 
NumPy arrays without the aid of the shareable_wrap function.  I have received 
feedback from others using this function also worth discussing.


Thank you to everyone who has already looked at the code and shared helpful 
thoughts -- please have a look at the tests and docs.

--

___
Python tracker 

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



[issue35813] shared memory construct to avoid need for serialization between processes

2019-02-10 Thread Davin Potts


Change by Davin Potts :


--
pull_requests: +11834

___
Python tracker 

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



[issue35813] shared memory construct to avoid need for serialization between processes

2019-02-10 Thread Davin Potts


Change by Davin Potts :


--
pull_requests: +11834, 11835, 11836

___
Python tracker 

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



[issue35813] shared memory construct to avoid need for serialization between processes

2019-02-10 Thread Davin Potts


Change by Davin Potts :


--
pull_requests: +11834, 11835

___
Python tracker 

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



Re: The slash "/" as used in the documentation

2019-02-10 Thread Ian Kelly
On Sun, Feb 10, 2019 at 9:34 AM Chris Angelico  wrote:
>
> On Mon, Feb 11, 2019 at 2:49 AM Ian Kelly  wrote:
> >
> > On Sat, Feb 9, 2019 at 1:19 PM Terry Reedy  wrote:
> > >
> > > This is the result of Python being a project of mostly unpaid volunteers.
> > >
> > > See my response in this thread explaining how '/' appears in help output
> > > and IDLE calltips.  '/' only appears for CPython C-coded functions that
> > > have been modified to use Argument Clinic.  A.C. was added, I believe,
> > > in 3.5.  Simple builtins like len would have been the first to be
> > > converted.  The math module was converted for 3.7.  There are some new
> > > conversions for 3.8 and likely some will be left for future versions.
> >
> > I'm sure there are good reasons for it like most things Python does, but I
> > can't help but wonder if working on removing the positional limitation from
> > CPython would be a better use of time.
>
> Do you ACTUALLY want to call math.sin(x=1.234) or is it purely for the
> sake of consistency? Aside from questions about the help format, what
> is actually lost by the inability to pass those arguments by name?

No, but I wouldn't object to d.get(key='foo', default=12). It's partly
about consistency, but mostly I was reacting to Terry's comments in
that a) positional-only arguments are a "limitation" and there is no
desire for the rest of Python to match CPython's behavior in this
instance, and b) it sounds like a great deal of effort is being spent
on updating all the C function signatures one at a time so that the
help string can be updated to a form that is unfamiliar and not
intuitive and not normally accessible to pure Python functions without
some arm twisting. If every function has to be updated anyway, why not
update them by fixing their signatures?
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue35951] os.renames() creates directories if original name doesn't exist

2019-02-10 Thread Ammar Askar


Ammar Askar  added the comment:

Aah, I interpreted the combination of the warning and the fact that it says 
"attempted first" to mean that any failures in the actual renaming will leave 
the new directory in place. That is, no cleanup is ever performed.

A quick glance at the code seems to suggest that as well.

--

___
Python tracker 

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



[issue35951] os.renames() creates directories if original name doesn't exist

2019-02-10 Thread Chris Jerdonek


Chris Jerdonek  added the comment:

Lacking permissions seems very different to me from the source directory or 
file not existing. For example, in the example I provided, I did have the 
needed permissions.

Incidentally (and this is a separate documentation issue), the note seems 
unclear as to whether "the leaf directory or file" the user lacks permissions 
to remove is in reference to the "rightmost path segments of the old name" 
being pruned away, or the new directory structure to be removed on failure.

--

___
Python tracker 

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



[issue35960] dataclasses.field does not preserve empty metadata object

2019-02-10 Thread Karthikeyan Singaravelan


Change by Karthikeyan Singaravelan :


--
nosy: +eric.smith

___
Python tracker 

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



[issue35961] gc_decref: Assertion "gc_get_refs(g) > 0" failed: refcount is too small

2019-02-10 Thread Karthikeyan Singaravelan


Karthikeyan Singaravelan  added the comment:

I too saw this a week back but couldn't reproduce it. There is one another test 
that fails like this and passes on verbose mode issue35809 . Travis doesn't 
report tests that fail in the complete run and pass during verbose run like 
buildbots do.

--
nosy: +xtreak

___
Python tracker 

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



[issue35460] Add PyDict_GetItemStringWithError

2019-02-10 Thread Raymond Hettinger


Raymond Hettinger  added the comment:

-1 for expanding this API.  As Serhiy pointed-out, PyDict_GetItemString() is an 
old API kept just for backward compatibility.  For your use case, it is easy to 
call PyUnicode_FromString(key) and then follow-up with 
PyDict_GetItemWithError().  The latter way is more flexible in that it allows 
you to cache the unicode object for future use (something you're going to want 
to do if you care about performance).  The latter way also lets you intern the 
string as well.

FWIW, if it is only your own code, it is trivially easy to write your own 
helper function if that is what you needed for a single porting project.  IMO, 
unnecessarily adding to many variants of the same function just makes the API 
harder to learn (see all the ObjectCall variants for example) and makes the 
code harder for us to maintain.  ISTM most of the concrete APIs are 
deliberately sparse, so adding this variant would be a change in the philosophy 
of the C-API.  Also, we mostly want people to use the abstract API unless they 
know for sure that a target dictionary is an exact dict (this has been an 
outstanding problem for OrderedDicts for example).

--
nosy: +rhettinger

___
Python tracker 

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



[issue35889] sqlite3.Row doesn't have useful repr

2019-02-10 Thread Raymond Hettinger


Raymond Hettinger  added the comment:

+1 from me.  We're already made regular expression match objects less opaque 
and that has been useful.  There's no need for a python-ideas discussion for 
this.

If a repr doesn't round-trip, we generally put it angle brackets (see PEP 8):

>>> re.search(r'([a-z]+)(\d*)', 'alpha7')


The Row object access style uses square brackets and has a keys() method.  That 
suggests a dict-like representation would be intuitive and match how Row 
objects are used:  ro['salary'] and ro.keys().

Putting those two ideas together we get:



Note the OP's suggestion for keyword argument style doesn't make sense for two 
reasons: 1) Row objects don't allow attribute access (i.e. ro.name is invalid) 
and 2) the field names are not required to be valid Python identifiers (i.e. 
ro['class'] is possible but ro.class is syntactically invalid because "class" 
is a keyword).

--
nosy: +rhettinger

___
Python tracker 

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



[issue35796] time.localtime returns error for negative values

2019-02-10 Thread Ammar Askar


Ammar Askar  added the comment:

Victor is correct, this is a limitation in Windows. As the documentation for 
time notes:

>Although this module is always available, not all functions are available on 
>all platforms. Most of the functions defined in this module call platform C 
>library functions with the same name. It may sometimes be helpful to consult 
>the platform documentation, because the semantics of these functions varies 
>among platforms.

https://docs.python.org/3/library/time.html#module-time

And as the Windows documentation notes: 

>less than 0 or greater than _MAX__TIME64_T: EINVAL

https://msdn.microsoft.com/en-us/library/a442x3ye.aspx?f=255=-2147217396

--
nosy: +ammar2
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



[issue35960] dataclasses.field does not preserve empty metadata object

2019-02-10 Thread Christopher Hunt


Change by Christopher Hunt :


--
keywords: +patch, patch, patch
pull_requests: +11831, 11832, 11833
stage:  -> patch review

___
Python tracker 

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



[issue35960] dataclasses.field does not preserve empty metadata object

2019-02-10 Thread Christopher Hunt


Change by Christopher Hunt :


--
keywords: +patch, patch
pull_requests: +11831, 11832
stage:  -> patch review

___
Python tracker 

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



[issue35960] dataclasses.field does not preserve empty metadata object

2019-02-10 Thread Christopher Hunt


Change by Christopher Hunt :


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

___
Python tracker 

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



[issue31940] copystat on symlinks fails for alpine -- faulty lchmod implementation?

2019-02-10 Thread Benjamin Peterson


Change by Benjamin Peterson :


--
resolution:  -> duplicate
stage: patch review -> resolved
status: open -> closed
superseder:  -> never enable lchmod on Linux

___
Python tracker 

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



[issue28627] [alpine] shutil.copytree fail to copy a direcotry with broken symlinks

2019-02-10 Thread Benjamin Peterson


Change by Benjamin Peterson :


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



[issue35956] Sort documentation could be improved for complex sorting

2019-02-10 Thread Raymond Hettinger


Raymond Hettinger  added the comment:

It seems to me that the sorting howto covers this topic.

If I'm reading the OP's task correctly, it isn't complex at all:

   points.sort(key=attrgetter('x', 'y'))  # x is primary key; y is secondary

--
assignee: docs@python -> rhettinger
nosy: +rhettinger

___
Python tracker 

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



[issue35951] os.renames() creates directories if original name doesn't exist

2019-02-10 Thread Ammar Askar


Ammar Askar  added the comment:

It seems this behavior is somewhat documented: 
https://docs.python.org/3/library/os.html#os.renames

>Works like rename(), except creation of any intermediate directories needed to 
>make the new pathname good is attempted first.
>This function can fail with the new directory structure made if you lack 
>permissions needed to remove the leaf directory or file.


The source directory not existing isn't the same as not having permissions to 
remove it but close enough.

--
nosy: +ammar2

___
Python tracker 

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



[issue35961] gc_decref: Assertion "gc_get_refs(g) > 0" failed: refcount is too small

2019-02-10 Thread Pablo Galindo Salgado


New submission from Pablo Galindo Salgado :

I am seeing some failures in travis and some buildbots:

0:02:24 load avg: 3.30 [147/420/1] test_slice crashed (Exit code -6) -- 
running: test_multiprocessing_spawn (32 sec 523 ms), test_asyncio (45 sec 433 
ms), test_multiprocessing_forkserver (47 sec 869 ms)
Modules/gcmodule.c:110: gc_decref: Assertion "gc_get_refs(g) > 0" failed: 
refcount is too small
Enable tracemalloc to get the memory block allocation traceback
object  : .BadCmp object at 
0x2ab2051faef0>
type: BadCmp
refcount: 1
address : 0x2ab2051faef0
Fatal Python error: _PyObject_AssertFailed
Current thread 0x2ab1fe0519c0 (most recent call first):
  File "/home/travis/build/python/cpython/Lib/test/test_slice.py", line 107 in 

  File "/home/travis/build/python/cpython/Lib/unittest/case.py", line 197 in 
handle
  File "/home/travis/build/python/cpython/Lib/unittest/case.py", line 782 in 
assertRaises
  File "/home/travis/build/python/cpython/Lib/test/test_slice.py", line 107 in 
test_cmp
  File "/home/travis/build/python/cpython/Lib/unittest/case.py", line 642 in run
  File "/home/travis/build/python/cpython/Lib/unittest/case.py", line 702 in 
__call__
  File "/home/travis/build/python/cpython/Lib/unittest/suite.py", line 122 in 
run
  File "/home/travis/build/python/cpython/Lib/unittest/suite.py", line 84 in 
__call__
  File "/home/travis/build/python/cpython/Lib/unittest/suite.py", line 122 in 
run
  File "/home/travis/build/python/cpython/Lib/unittest/suite.py", line 84 in 
__call__
  File "/home/travis/build/python/cpython/Lib/unittest/suite.py", line 122 in 
run
  File "/home/travis/build/python/cpython/Lib/unittest/runner.py", line 176 in 
run
  File "/home/travis/build/python/cpython/Lib/test/support/__init__.py", line 
1935 in _run_suite
  File "/home/travis/build/python/cpython/Lib/test/support/__init__.py", line 
2031 in run_unittest
  File "/home/travis/build/python/cpython/Lib/test/libregrtest/runtest.py", 
line 178 in test_runner
  File "/home/travis/build/python/cpython/Lib/test/libregrtest/runtest.py", 
line 182 in runtest_inner
  File "/home/travis/build/python/cpython/Lib/test/libregrtest/runtest.py", 
line 127 in runtest
  File "/home/travis/build/python/cpython/Lib/test/libregrtest/runtest_mp.py", 
line 68 in run_tests_worker
  File "/home/travis/build/python/cpython/Lib/test/libregrtest/main.py", line 
600 in _main
  File "/home/travis/build/python/cpython/Lib/test/libregrtest/main.py", line 
586 in main
  File "/home/travis/build/python/cpython/Lib/test/libregrtest/main.py", line 
640 in main
  File "/home/travis/build/python/cpython/Lib/test/regrtest.py", line 46 in 
_main
  File "/home/travis/build/python/cpython/Lib/test/regrtest.py", line 50 in 

  File "/home/travis/build/python/cpython/Lib/runpy.py", line 85 in _run_code

Usually, this happens with test_slice but when the test runner runs test_slice 
in isolation, it succeeds.

I am afraid that this will be a weird combination of tests.

--
components: Tests
messages: 335185
nosy: pablogsal
priority: normal
severity: normal
status: open
title: gc_decref: Assertion "gc_get_refs(g) > 0" failed: refcount is too small
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



[issue35960] dataclasses.field does not preserve empty metadata object

2019-02-10 Thread Christopher Hunt

New submission from Christopher Hunt :

The metadata argument to dataclasses.field is not preserved in the resulting 
Field.metadata attribute if the argument is a mapping with length 0.

The docs for dataclasses.field state:

> metadata: This can be a mapping or None. None is treated as an empty dict. 
> This value is wrapped in MappingProxyType() to make it read-only, and exposed 
> on the Field object.

The docs for MappingProxyType() state:

> Read-only proxy of a mapping. It provides a dynamic view on the mapping’s 
> entries, which means that when the mapping changes, the view reflects these 
> changes.

I assumed that the mapping provided could be updated after class initialization 
and the changes would reflect in the field's metadata attribute. Indeed this is 
the case when the mapping is non-empty, but not when the mapping is initially 
empty.

For example:

$ python
Python 3.8.0a1+ (heads/master:9db56fb8fa, Feb 10 2019, 19:54:10)
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from dataclasses import field
>>> d = {}
>>> v = field(metadata=d)
>>> d['i'] = 1
>>> v.metadata
mappingproxy({})
>>> v = field(metadata=d)
>>> v.metadata
mappingproxy({'i': 1})
>>> d['j'] = 2
>>> v.metadata
mappingproxy({'i': 1, 'j': 2})

In my case I have a LazyDict into which I was trying to save partial(callback, 
field). I could not have the field before it was initialized so I tried:

d = {}
member: T = field(metadata=d)
d['key'] = partial(callback, field)

and it failed same as above.

As a workaround, one can set a dummy value in the mapping prior to calling 
dataclasses.field and then remove/overwrite it afterwards.

--
components: Library (Lib)
messages: 335184
nosy: chrahunt
priority: normal
severity: normal
status: open
title: dataclasses.field does not preserve empty metadata object
type: behavior
versions: 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



[issue35808] Let's retire pgen

2019-02-10 Thread Pablo Galindo Salgado


Change by Pablo Galindo Salgado :


--
pull_requests:  -11829, 11830

___
Python tracker 

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



[issue35808] Let's retire pgen

2019-02-10 Thread Pablo Galindo Salgado


Change by Pablo Galindo Salgado :


--
pull_requests:  -11830

___
Python tracker 

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



[issue35808] Let's retire pgen

2019-02-10 Thread Pablo Galindo Salgado


Change by Pablo Galindo Salgado :


--
keywords: +patch, patch, patch
pull_requests: +11828, 11829, 11830
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



[issue35808] Let's retire pgen

2019-02-10 Thread Pablo Galindo Salgado


Change by Pablo Galindo Salgado :


--
keywords: +patch, patch
pull_requests: +11828, 11829
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



[issue35808] Let's retire pgen

2019-02-10 Thread Pablo Galindo Salgado


Change by Pablo Galindo Salgado :


--
keywords: +patch
pull_requests: +11828
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



[issue23460] Decimals do not obey ':g' exponential notation formatting rules

2019-02-10 Thread Brennan D Baraban


Brennan D Baraban <3...@holbertonschool.com> added the comment:

What is the status of this issue? I can submit a PR based on Tuomas Suutari's 
patch.

--
nosy: +bdbaraban

___
Python tracker 

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



[issue35892] Fix awkwardness of statistics.mode() for multimodal datasets

2019-02-10 Thread Steven D'Aprano


Steven D'Aprano  added the comment:

Thanks Raymond for the interesting use-case.

The original design of mode() was support only the basic form taught in 
secondary schools, namely a single unique mode for categorical data or 
discrete numerical data.

I think it is time to consider a richer interface to support more uses, 
such as estimating the mode of continuous numerical data, and the 
multi-mode case you bring up.

One reason I've been hesitant is that deciding what is the right 
behaviour is quite hard (or at least it has been for me). I think there 
are a few cases to consider:

- the existing behaviour (which may not be very useful?) which is to
  raise an exception unless the mode is unique; 

- would it be more useful to return an out-of-band value like a NAN 
  or None?

- the multi-mode case where you want some arbitrary(?) mode, possibly
  the left-most (smallest) for numeric data;

- the multi-mode case where you want all the modes.

I like Francis' suggestion to use an enum to select the behavioural, er, 
mode (pun intended). What do you think?

--

___
Python tracker 

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



[issue35904] Add statistics.fmean(seq)

2019-02-10 Thread Steven D'Aprano


Steven D'Aprano  added the comment:

> Would you like me to submit a PR with docs and tests?

Yes please! I'm happy with the name fmean.

--

___
Python tracker 

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



[issue35899] '_is_sunder' function in 'enum' module fails on empty string

2019-02-10 Thread Brennan D Baraban


Brennan D Baraban <3...@holbertonschool.com> added the comment:

Got it, makes sense. Thank you. New contributor here :)

--

___
Python tracker 

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



[issue12317] inspect.getabsfile() is not documented

2019-02-10 Thread Terry J. Reedy


Terry J. Reedy  added the comment:

Given the absence of agreement among core-devs, a PR is a bit premature.  

Looking again at the existing docstring, I think it must be revised before 
copying and *not* copied as is.

0. The existing first sentence mislead me.  The 'source or compiled file' must 
be a Python source or compiled Python (.pyc) file.  An object in a compiled C 
file gives a TypeError.  Change 'an object' to 'a Python-coded object'.

1. The 'object' argument cannot be just any Python-coded object (class object 
instance).  Based on the exception message, add this second sentence: "The 
object must be a module, class, method, function, traceback, frame, or code 
object."  Otherwise, TypeError.

2. The second paragraph is garbled.  All objects in a module have a common 
origin, not a unique origin.  I think the idea is that the name for the origin 
should be a standardized full path.  I think that this paragraph adds so little 
that it should be deleted rather than revised.

What paused this issue was Brett's opinion that getabsfile is untrustworthy 
and, with __file__ absolute, 'pointless', to a degree that it should not be 
documented. (If that were true, it should be deprecated.)

I read the 3.7.2 source for getabsfile, getsourcefile, and getfile. The 
returned name is based on either module.__file__ or code.co_filename. I think 
the function should be kept and documented.

1. Assuming that both __file__ and co_filename are now normcased and normalized 
absolute paths, (and identical for functions,) then 
"os.path.normcase(os.path.abspath(_filename))" is a no-op returning _filename 
as is, and should be dropped.  There is no longer a "guess at what the cwd was 
when a module was imported" in getabsfile itself.

2. getfile and getsourcefile do non-trivial switching and name processing that 
users would not get right if getabsfile were not present.

--

___
Python tracker 

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



[issue35899] '_is_sunder' function in 'enum' module fails on empty string

2019-02-10 Thread Ethan Furman


Ethan Furman  added the comment:

Let's give Maxwell until the 14th (so a week from when I asked him to turn his 
code into a patch) and if nothing from him by then you are welcome to take it 
over.

--

___
Python tracker 

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



[issue34652] never enable lchmod on Linux

2019-02-10 Thread Anthony Sottile


Anthony Sottile  added the comment:

I believe this also closes https://bugs.python.org/issue31940 and 
https://bugs.python.org/issue28627

--
nosy: +Anthony Sottile

___
Python tracker 

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



RE: The use of type()

2019-02-10 Thread Avi Gross
Follow on to below. I was right and there is a fairly trivial and portable
way to just show 'int' for the type of probably many types:

No need to call the type() function at all.

If "a" is an integer object containing "5" then you can ask for the class of
it and then within that for the name like this:

>>> a = 5
>>> print(a.__class__.__name__)
int
>>> b = 5.0
>>> print(b.__class__.__name__)
float

-Original Message-
From: Python-list  On
Behalf Of Avi Gross
Sent: Sunday, February 10, 2019 5:43 PM
To: python-list@python.org
Subject: RE: The use of type()

Without using regular expressions, if you just want to extract the word
"int" or "float" you can substring the results by converting what type says
to a string:

>>> a = 5
>>> str(type(a))[8:11]
'int'

>>> a=5.0
>>> str(type(a))[8:13]
'float'

Since the format and length vary, this may not meet your needs. You could
search for the first index where there is a single quote and then the next
and take what is in between.

You can run this in-line or make a function that might work for at least the
basic types:

>>> a = 5
>>> text = str(type(a))
>>> first = text.find("'")
>>> first += 1
>>> second = text.find("'", first)
>>> first, second
(8, 11)
>>> text[first : second]
'int'
>>> print(text[first : second])
Int

If I do the same with a float like 5.0:

>>> a=5.0
>>> text = str(type(a))
>>> first = text.find("'")
>>> first += 1
>>> second = text.find("'", first)
>>> print(text[first : second])
float

For a list:

>>> a = ["list", "of", "anything"]
..
>>> print(text[first : second])
list

Of course this is so simple it must be out there in some module.




-Original Message-
From: Python-list  On
Behalf Of ^Bart
Sent: Sunday, February 10, 2019 4:43 PM
To: python-list@python.org
Subject: The use of type()

I need to print something like "this variable is int" or "this variable is
string"

n1 = 10
n2 = 23

print ("Total of n1+n2 is: ",n1+n2," the type is", type(n1+n2))

When I run it I have:

Total of n1+n2 is:  33  the type is   >>>

I'd like to read "the type is int" and NOT "the type is , how
could I solve it?

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

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

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


[issue35899] '_is_sunder' function in 'enum' module fails on empty string

2019-02-10 Thread Brennan


Brennan <3...@holbertonschool.com> added the comment:

I'm not sure if Maxwell is still working on this issue, but may I pick it up? I 
can submit a PR within the day.

--
nosy: +bdbaraban

___
Python tracker 

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



RE: The use of type()

2019-02-10 Thread Avi Gross
Without using regular expressions, if you just want to extract the word
"int" or "float" you can substring the results by converting what type says
to a string:

>>> a = 5
>>> str(type(a))[8:11]
'int'

>>> a=5.0
>>> str(type(a))[8:13]
'float'

Since the format and length vary, this may not meet your needs. You could
search for the first index where there is a single quote and then the next
and take what is in between.

You can run this in-line or make a function that might work for at least the
basic types:

>>> a = 5
>>> text = str(type(a))
>>> first = text.find("'")
>>> first += 1
>>> second = text.find("'", first)
>>> first, second
(8, 11)
>>> text[first : second]
'int'
>>> print(text[first : second])
Int

If I do the same with a float like 5.0:

>>> a=5.0
>>> text = str(type(a))
>>> first = text.find("'")
>>> first += 1
>>> second = text.find("'", first)
>>> print(text[first : second])
float

For a list:

>>> a = ["list", "of", "anything"]
...
>>> print(text[first : second])
list

Of course this is so simple it must be out there in some module.




-Original Message-
From: Python-list  On
Behalf Of ^Bart
Sent: Sunday, February 10, 2019 4:43 PM
To: python-list@python.org
Subject: The use of type()

I need to print something like "this variable is int" or "this variable is
string"

n1 = 10
n2 = 23

print ("Total of n1+n2 is: ",n1+n2," the type is", type(n1+n2))

When I run it I have:

Total of n1+n2 is:  33  the type is   >>>

I'd like to read "the type is int" and NOT "the type is , how
could I solve it?

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

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


[issue35940] multiprocessing manager tests fail in the Refleaks buildbots

2019-02-10 Thread Giampaolo Rodola'


Giampaolo Rodola'  added the comment:

Pablo thanks a lot for taking care of this.

--

___
Python tracker 

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



[issue35278] [security] directory traversal in tempfile prefix

2019-02-10 Thread Cheryl Sabella

Cheryl Sabella  added the comment:

Adding Łukasz to the nosy list as release manager.

--
nosy: +cheryl.sabella, lukasz.langa

___
Python tracker 

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



[issue9584] fnmatch, glob: Allow curly brace expansion

2019-02-10 Thread Matúš Valo

Matúš Valo  added the comment:

Hi All,

this is a humble ping.

--

___
Python tracker 

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



Re: The use of type()

2019-02-10 Thread Chris Angelico
On Mon, Feb 11, 2019 at 8:46 AM ^Bart  wrote:
>
> I need to print something like "this variable is int" or "this variable
> is string"
>
> n1 = 10
> n2 = 23
>
> print ("Total of n1+n2 is: ",n1+n2," the type is", type(n1+n2))
>
> When I run it I have:
>
> Total of n1+n2 is:  33  the type is 
>  >>>
>
> I'd like to read "the type is int" and NOT "the type is ,
> how could I solve it?
>

Many things in Python, including functions and types, have inherent names.

>>> print(sys.__name__, int.__name__, print.__name__)
sys int print

Enjoy!

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


The use of type()

2019-02-10 Thread ^Bart
I need to print something like "this variable is int" or "this variable 
is string"


n1 = 10
n2 = 23

print ("Total of n1+n2 is: ",n1+n2," the type is", type(n1+n2))

When I run it I have:

Total of n1+n2 is:  33  the type is 
>>>

I'd like to read "the type is int" and NOT "the type is , 
how could I solve it?


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


RE: Im trying to replicate the youtube video Creating my own customized celebrities with AI.

2019-02-10 Thread Avi Gross
Bob,

>> tenserflow, pygame, scipy, and numby

> All of these are probably installable using pip. By the way did you mean
numpy? 
> At a command prompt type pip install packagename.

While you are correcting the spelling of downloads as the downloader is
quite picky about exact spelling, please mention that the tenser flow should
be tensorflow. I think numby and perhaps tense is how you feel as you read
to the end of the documentation on numpy. 

More seriously, it helps if you have some idea of why these modules get
names. NUMeric PYthon is numpy. Something like SCIentific PYthon is scipy. 

I am not as sure about TensorFlow but suspect the mathematical concept of a
Tensor along with how it improves workflow. Haven't had a need to use it
yet. Neither have I had a need for pygame which seems to be a way to make
games in python.

-Original Message-
From: Python-list  On
Behalf Of Bob Gailer
Sent: Sunday, February 10, 2019 12:07 PM
To: jadenfig...@gmail.com
Cc: python list 
Subject: Re: Im trying to replicate the youtube video Creating my own
customized celebrities with AI.

On Feb 10, 2019 11:40 AM,  wrote:
>
> The video

I don't see any video here. If you  attached  one the attachment did not
come through.

> gives the source code and the necessary things to download with it. 
> But
I'm new to python and don't understand how to install any of the files. The
files include: Python 3

Which you can download from python.org - just follow the link to downloads.

> pip

is automatically installed when you install python

> tenserflow, pygame, scipy, and numby

All of these are probably installable using pip. By the way did you mean
numpy? At a command prompt type pip install packagename.

I suggest you switch from l...@python.org to h...@python.org.

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

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


RE: The slash "/" as used in the documentation

2019-02-10 Thread Avi Gross
Chris,

I would appreciate another pointer to the documentation explaining what was
done and why as I deleted the earlier discussion.

You ask:

> Aside from questions about the help format, what is actually lost by the
inability 
> to pass those arguments by name?

I am not sure how python implements some of the functionality it does as
compared to other languages with similar features. But I note that there are
rules, presumably some for efficiency, such as requiring all keyword
arguments to be placed after the last positional argument. I mean I can call
func(a,b,c,d=1,e=2) but not func(a,b,d=1, c, e=2).

So if you allowed a keyword to optionally be used for any positional
argument other than the last, c, would it not require a change in this rule?
I mean func(a="invalid",b,c,d=1,e=2) would violate the rule and so would
making b a keyword version. In my example, and for this reason only, maybe c
could work.

And note the impact IF ALLOWED on the existing and new programs that allow a
variable number of arguments of the form func(*args, **kwargs) when they
evaluate. The previous model was that args would be a sequence of the
arguments you could index so args[0] would be the first, or that you can pop
off the front and use. If any of the previously un-named arguments can now
entered with a keyword, are they now placed in args or in the dictionary
kwargs? If in kwargs, the program now needs to know to look there in
addition to the command line. If it was the first argument and is no longer
in args, the second and further arguments would either be shifted over and
be used wrong or you need a placeholder.

The original motivation for keyword arguments included the concept of
specifying a default if not used. Positional arguments have no default.
Similarly, they are required if explicitly named in the function definition.
So we are intermingling multiple concepts in the previous design.

I won't go on except to say it would break lots of existing code and
potentially complicate new code.

Let me add a dumb suggestion. Anyone who desperately wants to name the
parameters has a rather strange option they can do now. Very imperfect but
consider the function prototype I have been using for illustration:

func(a,b,c,d=1,e=2)

It requires three positional arguments. What if you implement your code so
some special values mean that you are going to pass along "a" as "key_a"
instead. You can use something like None or the ellipsis(...) to signal this
as in:

def func(a, b, c, d=1, e=2, key_a=None):
if a == ... :
a = key_a
print(a)

The above does nothing but illustrates a WAY to allow a keyword
implementation by using one or more placeholders as you can do the same
gimmick for b and c.

Here is how it runs if you use the positional arg, or an ellipsis and then a
keyword or an ellipsis and accept the default for the keyword:

>>> func(1,2,3)
1
>>> func(...,2,3,key_a="keyed up")
keyed up
>>> func(...,2,3)
None

So could you re-implement processing in a NEW language to allow different
handling. I am guessing you could. Again, other languages currently do
things their own way. But for compatibility, I can see why they may be
patching and documenting what IS.

And note you could create an amazingly annoying language where each
parameter is specified as having umpteen attributes like it has to be the
second un-named argument and of a restricted number of types and if it has a
keyword it can be abbreviated as short as some string and then should it be
placed in position 2 and does it have a default and who knows what more.

Avi

-Original Message-
From: Python-list  On
Behalf Of Chris Angelico
Sent: Sunday, February 10, 2019 11:32 AM
To: Python 
Subject: Re: The slash "/" as used in the documentation

On Mon, Feb 11, 2019 at 2:49 AM Ian Kelly  wrote:
>
> On Sat, Feb 9, 2019 at 1:19 PM Terry Reedy  wrote:
> >
> > This is the result of Python being a project of mostly unpaid
volunteers.
> >
> > See my response in this thread explaining how '/' appears in help 
> > output and IDLE calltips.  '/' only appears for CPython C-coded 
> > functions that have been modified to use Argument Clinic.  A.C. was 
> > added, I believe, in 3.5.  Simple builtins like len would have been 
> > the first to be converted.  The math module was converted for 3.7.  
> > There are some new conversions for 3.8 and likely some will be left for
future versions.
>
> I'm sure there are good reasons for it like most things Python does, 
> but I can't help but wonder if working on removing the positional 
> limitation from CPython would be a better use of time.

Do you ACTUALLY want to call math.sin(x=1.234) or is it purely for the sake
of consistency? Aside from questions about the help format, what is actually
lost by the inability to pass those arguments by name?

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

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


[issue35959] math.prod(range(10)) caues segfault

2019-02-10 Thread Pablo Galindo Salgado


Change by Pablo Galindo Salgado :


--
pull_requests: +11825, 11826, 11827

___
Python tracker 

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



[issue35959] math.prod(range(10)) caues segfault

2019-02-10 Thread Pablo Galindo Salgado


Change by Pablo Galindo Salgado :


--
pull_requests: +11825

___
Python tracker 

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



[issue35959] math.prod(range(10)) caues segfault

2019-02-10 Thread Pablo Galindo Salgado


Change by Pablo Galindo Salgado :


--
pull_requests: +11825, 11826

___
Python tracker 

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



[issue35959] math.prod(range(10)) caues segfault

2019-02-10 Thread Pablo Galindo Salgado


Change by Pablo Galindo Salgado :


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



[issue35940] multiprocessing manager tests fail in the Refleaks buildbots

2019-02-10 Thread Pablo Galindo Salgado


Change by Pablo Galindo Salgado :


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



[issue35959] math.prod(range(10)) caues segfault

2019-02-10 Thread Pablo Galindo Salgado


Pablo Galindo Salgado  added the comment:

PR11808 fixes the error and add some basic test. Please review the PR instead :)

--

___
Python tracker 

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



[issue35959] math.prod(range(10)) caues segfault

2019-02-10 Thread Pablo Galindo Salgado


Change by Pablo Galindo Salgado :


--
keywords: +patch, patch, patch
pull_requests: +11822, 11823, 11824
stage:  -> patch review

___
Python tracker 

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



[issue35959] math.prod(range(10)) caues segfault

2019-02-10 Thread Pablo Galindo Salgado


Change by Pablo Galindo Salgado :


--
keywords: +patch, patch
pull_requests: +11822, 11823
stage:  -> patch review

___
Python tracker 

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



[issue35959] math.prod(range(10)) caues segfault

2019-02-10 Thread Pablo Galindo Salgado


Change by Pablo Galindo Salgado :


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

___
Python tracker 

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



[issue35936] Give modulefinder some much-needed updates.

2019-02-10 Thread Brandt Bucher


Brandt Bucher  added the comment:

Alright, I've gotten all of the tests passing for the new importlib-only 
implementation. I broke these modifications out into a new private function, 
_find_module, to make it clear that this fix is a simple drop-in replacement 
for imp.find_module.

Let me know if there's anything I've missed or could improve. Otherwise, I feel 
my work here is done!

--

___
Python tracker 

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



[issue35959] math.prod(range(10)) caues segfault

2019-02-10 Thread Rémi Lapeyre

Rémi Lapeyre  added the comment:

Could it be 
https://github.com/python/cpython/blob/master/Modules/mathmodule.c#L2565

When 0 is in the iterator, i_result get sets to 0 and then on the next 
iteration x/i_result is 0/0 which is undefined behavior?

C99 6.5.5p5 - The result of the / operator is the quotient from the division of 
the first operand by the second; the result of the % operator is the remainder. 
In both operations, if the value of the second operand is zero, the behavior is 
undefined.

I will do some tests, if it's that I will post a patch.

--
nosy: +remi.lapeyre

___
Python tracker 

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



[issue35959] math.prod(range(10)) caues segfault

2019-02-10 Thread Pablo Galindo Salgado


Pablo Galindo Salgado  added the comment:

The problem is that the intermediate result (i_result) can be 0 when doing the 
overflow check:

x / i_result != b

i am working on a fix.

--

___
Python tracker 

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



[issue35959] math.prod(range(10)) caues segfault

2019-02-10 Thread Karthikeyan Singaravelan

New submission from Karthikeyan Singaravelan :

math.prod introduced with issue35606 seems to segfault when zero is present on 
some cases like start or middle of the iterable. I couldn't find the exact 
cause of this. This also occurs in optimized builds.

# Python information built with ./configure && make

➜  cpython git:(master) ./python.exe
Python 3.8.0a1+ (heads/master:8a03ff2ff4, Feb 11 2019, 00:13:49)
[Clang 7.0.2 (clang-700.1.81)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>

# Segfaults with range(10), [0, 1, 2, 3] and [1, 0, 2, 3]

➜  cpython git:(master) ./python.exe -X faulthandler -c 'import math; 
print(math.prod(range(10)))'
Fatal Python error: Floating point exception

Current thread 0x7fff7939f300 (most recent call first):
  File "", line 1 in 
[1]40465 floating point exception  ./python.exe -X faulthandler -c 'import 
math; print(math.prod(range(10)))'

➜  cpython git:(master) ./python.exe -X faulthandler -c 'import math; 
print(math.prod([0, 1, 2, 3]))'
Fatal Python error: Floating point exception

Current thread 0x7fff7939f300 (most recent call first):
  File "", line 1 in 
[1]40414 floating point exception  ./python.exe -X faulthandler -c 'import 
math; print(math.prod([0, 1, 2, 3]))'
➜  cpython git:(master) ./python.exe -X faulthandler -c 'import math; 
print(math.prod([1, 0, 2, 3]))'
Fatal Python error: Floating point exception

Current thread 0x7fff7939f300 (most recent call first):
  File "", line 1 in 
[1]40425 floating point exception  ./python.exe -X faulthandler -c 'import 
math; print(math.prod([1, 0, 2, 3]))'


# No segfault when zero is at the end and floats seem to work fine.

➜  cpython git:(master) ./python.exe -X faulthandler -c 'import math; 
print(math.prod([1, 2, 3, 0]))'
0
➜  cpython git:(master) ./python.exe -c 'import math; 
print(math.prod(map(float, range(10'
0.0

--
components: Library (Lib)
messages: 335168
nosy: pablogsal, rhettinger, xtreak
priority: normal
severity: normal
status: open
title: math.prod(range(10)) caues segfault
type: crash
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



[issue35956] Sort documentation could be improved for complex sorting

2019-02-10 Thread Cheryl Sabella


Cheryl Sabella  added the comment:

Take a look at issue 35020 which discusses multisort.

--
nosy: +cheryl.sabella

___
Python tracker 

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



[issue35958] io.IOBase subclasses don't play nice with abc.abstractmethod

2019-02-10 Thread Jon McMahon


New submission from Jon McMahon :

Subclasses of io.IOBase can be instantiated with abstractmethod()s, even though 
ABCs are supposed to prevent this from happening. I'm guessing this has to do 
with io using the _io C module because the alternative pure-python 
implementation _pyio doesn't seem to have this issue. I'm using Python 3.6.7

>>> import _pyio
>>> import io
>>> import abc
>>> class TestPurePython(_pyio.IOBase):
... @abc.abstractmethod
... def foo(self):
... print('Pure python implementation')
... 
>>> class TestCExtension(io.IOBase):
... @abc.abstractmethod
... def bar(self):
... print('C extension implementation')
... 
>>> x=TestPurePython()
Traceback (most recent call last):
  File "", line 1, in 
TypeError: Can't instantiate abstract class TestPurePython with abstract 
methods foo
>>> y=TestCExtension()
>>> y.bar()
C extension implementation
>>>

--
components: IO
messages: 335166
nosy: Jon McMahon
priority: normal
severity: normal
status: open
title: io.IOBase subclasses don't play nice with abc.abstractmethod
versions: Python 3.6

___
Python tracker 

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



[issue35957] Indentation explanation is unclear

2019-02-10 Thread Jérôme LAURENS

New submission from Jérôme LAURENS :

https://docs.python.org/3/reference/lexical_analysis.html#indentation reads

Point 1:
"Tabs are replaced (from left to right) by one to eight spaces such that the 
total number of characters up to and including the replacement is a multiple of 
eight"

and in the next paragraph

Point 2:
"Indentation is rejected as inconsistent if a source file mixes tabs and spaces 
in a way that makes the meaning dependent on the worth of a tab in spaces"

In point 1, each tab has definitely a unique space counterpart, in point 2, 
tabs may have different space counterpart, which one is reliable ?

The documentation should state that Point 1 concerns cPython, or at least 
indicate that the 8 may depend on the implementation, which then gives sense to 
point 2.

--
assignee: docs@python
components: Documentation
messages: 335165
nosy: Jérôme LAURENS, docs@python
priority: normal
severity: normal
status: open
title: Indentation explanation is unclear
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



Re: Im trying to replicate the youtube video Creating my own customized celebrities with AI.

2019-02-10 Thread Bob Gailer
On Feb 10, 2019 11:40 AM,  wrote:
>
> The video

I don't see any video here. If you  attached  one the attachment did not
come through.

> gives the source code and the necessary things to download with it. But
I'm new to python and don't understand how to install any of the files. The
files include: Python 3

Which you can download from python.org - just follow the link to downloads.

> pip

is automatically installed when you install python

> tenserflow, pygame, scipy, and numby

All of these are probably installable using pip. By the way did you mean
numpy? At a command prompt type pip install packagename.

I suggest you switch from l...@python.org to h...@python.org.

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


Re: where is math_sin defined?

2019-02-10 Thread Chris Angelico
On Mon, Feb 11, 2019 at 3:37 AM Barry Scott  wrote:
>
> On Sunday, 10 February 2019 15:15:32 GMT Jon Ribbens wrote:
> > As an aside, how is 'math.sin' actually implemented? mathmodule.c
> > refers to the function 'math_sin' but that name is not defined
> > anywhere in the Python source code. I'm a bit mystified as to how
> > CPython manages to compile!
>
> I used gdb to find it:
>

Effective, if a little tedious.

My technique was to first confirm that there was nothing saying
"math_sin" anywhere in the repo (trust but verify - doesn't hurt to do
a quick "git grep"), then to search mathmodule.c for "sin(", since
searching for "sin" on its own gave way too many hits. That led me to
the definition of sinpi(), then to asin() and sin(), both being
defined using the FUNC1 template.

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


Im trying to replicate the youtube video Creating my own customized celebrities with AI.

2019-02-10 Thread jadenfigger
The video gives the source code and the necessary things to download with it. 
But I'm new to python and don't understand how to install any of the files. The 
files include: Python 3, pip, tenserflow, pygame, scipy, and numby. Could 
anyone help me install all of this to run the AI. Thank you
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue35956] Sort documentation could be improved for complex sorting

2019-02-10 Thread SilentGhost


SilentGhost  added the comment:

Is this not equivalent to the following?

  sorted(points, key=lambda p: (p.y, p.x))

--
nosy: +SilentGhost

___
Python tracker 

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



Re: where is math_sin defined?

2019-02-10 Thread Barry Scott
On Sunday, 10 February 2019 15:15:32 GMT Jon Ribbens wrote:
> As an aside, how is 'math.sin' actually implemented? mathmodule.c
> refers to the function 'math_sin' but that name is not defined
> anywhere in the Python source code. I'm a bit mystified as to how
> CPython manages to compile!

I used gdb to find it:

Breakpoint 1, math_sin (self=, args=0) at /
usr/src/debug/python3-3.7.2-4.fc29.x86_64/Modules/mathmodule.c:1176
1176FUNC1(sin, sin, 0,
(gdb) l
1171  "remainder($module, x, y, /)\n--\n\n"
1172  "Difference between x and the closest integer multiple of y.
\n\n"
1173  "Return x - n*y where n*y is the closest integer multiple of y.
\n"
1174  "In the case where x is exactly halfway between two multiples 
of\n"
1175  "y, the nearest even value of n is used. The result is always 
exact.")
1176FUNC1(sin, sin, 0,
1177  "sin($module, x, /)\n--\n\n"
1178  "Return the sine of x (measured in radians).")
1179FUNC1(sinh, sinh, 1,
1180  "sinh($module, x, /)\n--\n\n"
(gdb) 

Barry


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


Re: The slash "/" as used in the documentation

2019-02-10 Thread Chris Angelico
On Mon, Feb 11, 2019 at 2:49 AM Ian Kelly  wrote:
>
> On Sat, Feb 9, 2019 at 1:19 PM Terry Reedy  wrote:
> >
> > This is the result of Python being a project of mostly unpaid volunteers.
> >
> > See my response in this thread explaining how '/' appears in help output
> > and IDLE calltips.  '/' only appears for CPython C-coded functions that
> > have been modified to use Argument Clinic.  A.C. was added, I believe,
> > in 3.5.  Simple builtins like len would have been the first to be
> > converted.  The math module was converted for 3.7.  There are some new
> > conversions for 3.8 and likely some will be left for future versions.
>
> I'm sure there are good reasons for it like most things Python does, but I
> can't help but wonder if working on removing the positional limitation from
> CPython would be a better use of time.

Do you ACTUALLY want to call math.sin(x=1.234) or is it purely for the
sake of consistency? Aside from questions about the help format, what
is actually lost by the inability to pass those arguments by name?

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


[issue35956] Sort documentation could be improved for complex sorting

2019-02-10 Thread fabrice salvaire


New submission from fabrice salvaire :

I just implemented Graham Scan algorithm in Python 3 and have to read carefully 
the sort documentation.  Notice this is a good algorithm for a large audience 
language like Python.

Since Python 3, the old order function cmp is depicted as an old way to proceed.

But some sorting procedure require complex order like this

def sort_by_y(p0, p1):
return p0.x - p1.x if (p0.y == p1.y) else p0.y - p1.y
sorted(points, key=cmp_to_key(sort_by_y))

which is less natural to implement than

def sort_by_y(p0, p1):
return p0.x < p1.x if (p0.y == p1.y) else p0.y < p1.y
sorted(points, cmp=sort_by_y)

Since Python 3 we should do this

points.sort(key=attrgetter('x'))
points.sort(key=attrgetter('y'))

But we must take care to the chaining order !!! Here we must sort first on x 
then on y.

I think the documentation could explain much better how to perform complex sort 
and the performance of the Python sort algorithm.  Is the old way faster than 
the new one ???  What about short and large array ???  What happen when we sort 
a zillion of short array ???

--
assignee: docs@python
components: Documentation
messages: 335163
nosy: FabriceSalvaire, docs@python
priority: normal
severity: normal
status: open
title: Sort documentation could be improved for complex sorting
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



[issue21269] Provide args and kwargs attributes on mock call objects

2019-02-10 Thread Karthikeyan Singaravelan


Karthikeyan Singaravelan  added the comment:

This feels safer to me with respect to backwards compatibility and also that it 
might be easier to backport this to mock on GitHub which works with Python 2.7. 
I have less knowledge on difference between tuple and namedtuple internals so I 
might be wrong here.

--

___
Python tracker 

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



Re: C API PyObject_GetAttrString returns not the object I expected

2019-02-10 Thread Barry Scott
On Sunday, 10 February 2019 13:58:57 GMT Stefan Behnel wrote:
> Barry Scott schrieb am 10.02.19 um 13:08:
> > After calling PyObject_GetAttrString() I expected to get a PyObject string
> > back but I found that I had been given a  instead.
> > 
> > (gdb) p *args_o
> > $4 = 
> > 
> > What is going on and how do I get from the  to the
> > object I want?
> 
> Phil is right about the function itself, but my guess is that you called
> GetAttr() on a class instead of an instance. Read up on Python descriptors
> to understand what difference that makes.
> 
> https://docs.python.org/3/howto/descriptor.html
> 
> Basically, you got something like a property object back, but not the value
> that the property maintaines. If you look up the attribute on the instance,
> the property (or descriptor) will hand it to you. The same applies to
> method lookups and other special attributes that may also be implemented as
> descriptors.

Thanks that the clue I needed. I had assumed that PyErr_Occurred() returned 
the instance, but it returns the type and as you explained that gives you the 
get_set_descriptor. I need to use PyErr_Fetch to get the instance.


> Also take a look at Cython, which is designed to keep users from having to
> learn all these things and instead lets you do them in Python.
> 
> https://cython.org/

I'm adding better code to look at exceptions to PyCXX and hit this issue.

Barry
PyCXX maintainer.



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


Re: [solved] C API version of str(exception) is not the same as pure python version

2019-02-10 Thread Barry Scott
On Sunday, 10 February 2019 11:59:16 GMT Barry Scott wrote:
> When I use the C API to get the str() of an execption I see this text:
> 
>   
> 
> But python reports the following for the same exception:
> 
>   TypeError: unsupported operand type(s) for +: 'int' and 'str'
> 
> What do I need to do in the C API to get the the same text for the
> exception?
> 

> PyObject *err = PyErr_Occurred();
> if( err != 0 )
> {
> PyObject *u_why = PyObject_Str( err );
> PyObject *b_why = PyUnicode_AsEncodedString( u_why, "utf-8",
> "strict" );
> int size = PyBytes_Size( b_why );
> char *why = PyBytes_AsString( b_why );
> printf("Error: %*s\n", size, why );
> return 0;
> }

Using this code fixes the problem as Stefan pointed out I had the type of the 
exception and not the value of the exception.

if( PyErr_Occurred() )
{
PyObject *type, *value, *trace;
PyErr_Fetch( , ,  );

PyObject *u_why = PyObject_Str( value );
PyObject *b_why = PyUnicode_AsEncodedString( u_why, "utf-8", "strict" 
);
int size = PyBytes_Size( b_why );
char *why = PyBytes_AsString( b_why );
printf("Error: %*s\n", size, why );
return 0;
}



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


[issue21269] Provide args and kwargs attributes on mock call objects

2019-02-10 Thread Rémi Lapeyre

Rémi Lapeyre  added the comment:

@xtreak, couldn't we have made `_Call` inherit from namedtuple to achieve a 
similar result (albeit the handling of name would be weird)?

--

___
Python tracker 

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



Re: print console out to a txt or csv file

2019-02-10 Thread Peter Otten
GISDude wrote:

> Hi all,
> I have been working on some code to list the files of a folder that has
> .pdf extension. I have the basic code to create a list, but it prints that
> list to the console. I'd like my code to write a txt file that contains
> that list (to later import into excel).
> 
> ###A script to list pdf files in a folder
> ###gisdude 02/09/19
> ###
> import os, sys, glob, csv, pathlib
> 
> ###First, let's change the dir with os
> 
> os.chdir("C:\\Users\\Randy\\Documents\\BOOKS")

I have come to the conclusion that keeping track of the full path is much 
easier than keeping track of what directory you are in at the moment.
I recommend that you never use os.chdir().

> ###Second, let's now get the list of files in this directory
> 
> files = glob.glob('*.pdf')
> for file in glob.glob("*.pdf"):
> print (file)
> 
> ###This prints to the IDLE console
> ###But, I want to print to a csv file
> 
> for filename in glob.iglob ('*.pdf'):
> ###with open('Listofpdf', 'filename') as
> ###csvfile: writer = csv.writer(csvfile,
> ###delimter=' ', quotechar='|',
> ###quoting=csv.QUOTE_MINIMAL)
> ###writer.writerrow([('{}\t.format(elem))])
> from pathlib import Path
> searchdir = "C:\\Users\\Randy\\Documents\\BOOKS"
> csvfilename = "listofpdf.txt"
> 
> with Path(csvfilename).open(mode="w+") as p:
> files = Path(searchdir).glob('*.py')
> p.write(f"{' '.join(str(file) for file in files)}\n")
> 
> At this point, the pathlib mod seems like it should create the file?
> 
> I'm on WINDOWS 10 and IDLE 3.7.
> 
> Thanks for any help,
> R`

This looks rather messy, mainly because you are keeping every attempt you 
made. I recommend that you remove the code you don't use or that doesn't 
work as soon as possible.

Here are two ways to write the list of filenames to a csv file:

(1) Using traditional file path manipulation routines:

PDFFOLDER = "C:\\Users\\Randy\\Documents\\BOOKS"
CSVFILE = "files.txt"

filenames = glob.glob(os.path.join(PDFFOLDER, "*.pdf"))

with open(CSVFILE, "w", newline="") as outstream:
writer = csv.writer(outstream)
writer.writerows([path] for path in filenames)

Note that you are actually writing a list of lists; omitting the inner list 
leads to writing one column per character in the filename.


(2) Using pathlib's Path objects:

PDFFOLDER = pathlib.Path("C:\\Users\\Randy\\Documents\\BOOKS")
CSVFILENAME = pathlib.Path("files.txt")

filenames = PDFFOLDER.glob("*.pdf")
with CSVFILENAME.open("w", newline="") as outstream:
writer = csv.writer(outstream)
writer.writerows([path] for path in filenames)


If you want the filename without directory replace path in the single item 
lists with os.path.basename(path) or path.name respectively.

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


Re: The slash "/" as used in the documentation

2019-02-10 Thread Jon Ribbens
On 2019-02-10, Chris Angelico  wrote:
> On Mon, Feb 11, 2019 at 2:21 AM Jon Ribbens  wrote:
>> On 2019-02-09, Terry Reedy  wrote:
>> > '/' is no uglier than, and directly analogous to, and as easy to produce
>> > and comprehend, as '*'.  It was selected after considerable discussion
>> > of how to indicate that certain parameters are, at least in CPython,
>> > positional only.  The discussion of options included at least some of
>> > those given above.  It is very unlikely to go away or be changed.
>>
>> Ok, but what does it *mean*?
>
> It means "everything prior to this point is positional-only".
>
>> As an aside, how is 'math.sin' actually implemented? mathmodule.c
>> refers to the function 'math_sin' but that name is not defined
>> anywhere in the Python source code. I'm a bit mystified as to how
>> CPython manages to compile!
>
> A lot of those sorts of functions are hyperthin wrappers around the C
> math library. A bit of digging takes me to line 1176 of mathmodule.c
> (in my source tree; exact line number may vary), which uses the
> #define of FUNC1 from line 1032, and the actual code is up at line
> 876, with a good block comment.

Ah, it's using C preprocessor string concatenation to build the
function name, which is why grepping for 'math_sin' didn't find it.

Many thanks for your helpful answers.
-- 
https://mail.python.org/mailman/listinfo/python-list


Fwd: improve TypeError for AsyncIterables when attempting to sync iterate

2019-02-10 Thread Thomas Grainger
Currently when attempting to sync iterate an async iterable you get a
TypeError:

TypeError: 'SomeType' object is not iterable

When attempting to iterate an async iterable (eg an object with a __aiter__
method the error could be something like:

TypeError: 'SomeType' object is not iterable, it is however an
AsyncIterable. Use `async for` instead.
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue21269] Provide args and kwargs attributes on mock call objects

2019-02-10 Thread Rémi Lapeyre

Rémi Lapeyre  added the comment:

I like this patch, working with calls often feels weird and this change 
simplify attribute access.

--
nosy: +remi.lapeyre

___
Python tracker 

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



[issue35460] Add PyDict_GetItemStringWithError

2019-02-10 Thread Ronald Oussoren


Ronald Oussoren  added the comment:

There are more reasons to implement in C than just speed ;-). In my code I have 
two usecases for using PyDict_GetItemString, both not in performance critical 
code

1) Look up a hardcoded name in a dictionary. These could be switched to the Id 
API if that were public (and I might implement something like the Id API 
myself). 

2) Look up a name that is passed in as a "char*" from C code that's outside of 
my control.  This is a real use case for a PyDict_GetItemString API and not 
easilty converted to another API.

In PyObjC the majority of calls to PyDict_GetItemString are in the first 
category, while most of the latter would probably be better of using a 
PyDict_GetItemBytes API.  Although I definitely to not propose to add such an 
API to CPython.

--

___
Python tracker 

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



Re: The slash "/" as used in the documentation

2019-02-10 Thread Ian Kelly
On Sat, Feb 9, 2019 at 1:19 PM Terry Reedy  wrote:
>
> This is the result of Python being a project of mostly unpaid volunteers.
>
> See my response in this thread explaining how '/' appears in help output
> and IDLE calltips.  '/' only appears for CPython C-coded functions that
> have been modified to use Argument Clinic.  A.C. was added, I believe,
> in 3.5.  Simple builtins like len would have been the first to be
> converted.  The math module was converted for 3.7.  There are some new
> conversions for 3.8 and likely some will be left for future versions.

I'm sure there are good reasons for it like most things Python does, but I
can't help but wonder if working on removing the positional limitation from
CPython would be a better use of time.
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue35878] ast.c: end_col_offset may be used uninitialized in this function

2019-02-10 Thread Ivan Levkivskyi


Change by Ivan Levkivskyi :


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



Re: The slash "/" as used in the documentation

2019-02-10 Thread Chris Angelico
On Mon, Feb 11, 2019 at 2:21 AM Jon Ribbens  wrote:
>
> On 2019-02-09, Terry Reedy  wrote:
> > '/' is no uglier than, and directly analogous to, and as easy to produce
> > and comprehend, as '*'.  It was selected after considerable discussion
> > of how to indicate that certain parameters are, at least in CPython,
> > positional only.  The discussion of options included at least some of
> > those given above.  It is very unlikely to go away or be changed.
>
> Ok, but what does it *mean*?

It means "everything prior to this point is positional-only".

> As an aside, how is 'math.sin' actually implemented? mathmodule.c
> refers to the function 'math_sin' but that name is not defined
> anywhere in the Python source code. I'm a bit mystified as to how
> CPython manages to compile!

A lot of those sorts of functions are hyperthin wrappers around the C
math library. A bit of digging takes me to line 1176 of mathmodule.c
(in my source tree; exact line number may vary), which uses the
#define of FUNC1 from line 1032, and the actual code is up at line
876, with a good block comment.

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


Re: The slash "/" as used in the documentation

2019-02-10 Thread Jon Ribbens
On 2019-02-09, Terry Reedy  wrote:
> '/' is no uglier than, and directly analogous to, and as easy to produce 
> and comprehend, as '*'.  It was selected after considerable discussion 
> of how to indicate that certain parameters are, at least in CPython, 
> positional only.  The discussion of options included at least some of 
> those given above.  It is very unlikely to go away or be changed.

Ok, but what does it *mean*?

As an aside, how is 'math.sin' actually implemented? mathmodule.c
refers to the function 'math_sin' but that name is not defined
anywhere in the Python source code. I'm a bit mystified as to how
CPython manages to compile!
-- 
https://mail.python.org/mailman/listinfo/python-list


print console out to a txt or csv file

2019-02-10 Thread GISDude
Hi all,
I have been working on some code to list the files of a folder that has .pdf 
extension. I have the basic code to create a list, but it prints that list to 
the console. I'd like my code to write a txt file that contains that list (to 
later import into excel).

###A script to list pdf files in a folder
###gisdude 02/09/19
###
import os, sys, glob, csv, pathlib

###First, let's change the dir with os

os.chdir("C:\\Users\\Randy\\Documents\\BOOKS")

###Second, let's now get the list of files in this directory

files = glob.glob('*.pdf')
for file in glob.glob("*.pdf"):
print (file)

###This prints to the IDLE console
###But, I want to print to a csv file

for filename in glob.iglob ('*.pdf'):
###with open('Listofpdf', 'filename') as csvfile:
###writer = csv.writer(csvfile, delimter=' ', 
quotechar='|', quoting=csv.QUOTE_MINIMAL)
###writer.writerrow([('{}\t.format(elem))])
from pathlib import Path
searchdir = "C:\\Users\\Randy\\Documents\\BOOKS"
csvfilename = "listofpdf.txt"

with Path(csvfilename).open(mode="w+") as p:
files = Path(searchdir).glob('*.py')
p.write(f"{' '.join(str(file) for file in files)}\n")

At this point, the pathlib mod seems like it should create the file?

I'm on WINDOWS 10 and IDLE 3.7.

Thanks for any help,
R`









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


[issue35955] unittest assertEqual reports incorrect location of mismatch

2019-02-10 Thread Karthikeyan Singaravelan


Karthikeyan Singaravelan  added the comment:

Sorry to comment on a closed issue. I see the following behavior with 
difflib.ndiff which is used under the hood by unittest. The strings that differ 
by '-' and 'w' generate different output compared to 'a' and 'w'. I find the 
output for diff using '-' and 'w' little confusing and is this caused due to 
'-' which is also used as a marker in difflib?

$ ./python.exe
Python 3.8.0a1+ (heads/master:8a03ff2ff4, Feb  9 2019, 10:42:29)
[Clang 7.0.2 (clang-700.1.81)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import difflib
>>> print(''.join(difflib.ndiff(["drwxrwxr-x 2 2000  2000\n"], ["drwxr-xr-x 2 
>>> 2000  2000\n"])))
- drwxrwxr-x 2 2000  2000
?  ---
+ drwxr-xr-x 2 2000  2000
?+++

>>> print(''.join(difflib.ndiff(["drwxrwxr-x 2 2000  2000\n"], ["drwxraxr-x 2 
>>> 2000  2000\n"])))
- drwxrwxr-x 2 2000  2000
?  ^
+ drwxraxr-x 2 2000  2000
?  ^

--
nosy: +xtreak

___
Python tracker 

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



[issue35460] Add PyDict_GetItemStringWithError

2019-02-10 Thread Stefan Behnel


Stefan Behnel  added the comment:

The overhead of calling PyErr_Occurred() is definitely negligible in something 
as involved as PyDict_GetItemStringWithError(), where a mere key lookup first 
has to fire up the string decoder on a C character buffer to create a new 
string object and then calculate its hash value, just to throw away all that 
right after the tiny time interval that it takes to look up the key in the 
dict. It is not something I would encourage anyone to do in code that has only 
the slightest excuse for being implemented in C. :)

Rather, I would propose to open up the ID-String API that CPython uses 
internally, so that user code can benefit from fast lookups of interned strings 
with pre-initialised hash values, without having to care about creating and 
cleaning up string constants themselves all the time.

(FWIW, Cython also generates interned string constants automatically, but does 
not currently use the ID-API, also because it does it for *all* its strings, 
not just those that resemble identifiers etc.)

--
nosy: +scoder

___
Python tracker 

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



[issue35955] unittest assertEqual reports incorrect location of mismatch

2019-02-10 Thread Jason R. Coombs


Jason R. Coombs  added the comment:

I was able to replicate the issue using pytest and not unittest, so I've 
[reported the issue with that 
project](https://github.com/pytest-dev/pytest/issues/4765).

--

___
Python tracker 

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



[issue35955] unittest assertEqual reports incorrect location of mismatch

2019-02-10 Thread Jason R. Coombs


Change by Jason R. Coombs :


--
resolution:  -> third party
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



[issue35955] unittest assertEqual reports incorrect location of mismatch

2019-02-10 Thread Jason R. Coombs


Jason R. Coombs  added the comment:

I should acknowledge that I'm using pytest here also... and pytest may be the 
engine that's performing the reporting of the failed assertion.

In fact, switching to simple assertions, I see the same behavior, so I now 
suspect the issue may lie with pytest and not unittest.

--

___
Python tracker 

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



[issue35955] unittest assertEqual reports incorrect location of mismatch

2019-02-10 Thread Jason R. Coombs


New submission from Jason R. Coombs :

In [this job](https://travis-ci.org/jaraco/cmdix/jobs/491246158), a project is 
using assertEqual to compare two directory listings that don't match in the 
group. But the hint markers pointing to the mismatch are pointing at positions 
that match:

E   AssertionError: '--w-[50 chars]drwxrwxr-x 2 2000  20004096 
2019-02-10 14:[58 chars]oo\n' != '--w-[50 chars]drwxr-xr-x 2 2000  20004096 
2019-02-10 14:[58 chars]oo\n'
E --w-r---wx 1 2000  2000  99 2019-02-10 14:02 bar
E   - drwxrwxr-x 2 2000  20004096 2019-02-10 14:02 biz
E   ?  ---
E   + drwxr-xr-x 2 2000  20004096 2019-02-10 14:02 biz
E   ?+++
E   - -rw-rw-r-- 1 2000  2000 100 2019-02-10 14:02 foo
E   ? ---
E   + -rw-r--r-- 1 2000  2000 100 2019-02-10 14:02 foo
E   ?+++

As you can see, it's the 'group' section of the flags that differ between the 
left and right comparison, but the hints point at the 'user' section for the 
left side and the 'world' section for the right side, even though they match.

I observed this on Python 3.7.1. I haven't delved deeper to see if the issue 
exists on 3.7.2 or 3.8.

--
components: Library (Lib)
messages: 335154
nosy: jaraco
priority: normal
severity: normal
status: open
title: unittest assertEqual reports incorrect location of mismatch

___
Python tracker 

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



Re: C API PyObject_GetAttrString returns not the object I expected

2019-02-10 Thread Stefan Behnel
Barry Scott schrieb am 10.02.19 um 13:08:
> After calling PyObject_GetAttrString() I expected to get a PyObject string 
> back but I found that I had been given a  instead.
> 
> (gdb) p *args_o 
> $4 = 
> 
> What is going on and how do I get from the  to the object 
> I 
> want?

Phil is right about the function itself, but my guess is that you called
GetAttr() on a class instead of an instance. Read up on Python descriptors
to understand what difference that makes.

https://docs.python.org/3/howto/descriptor.html

Basically, you got something like a property object back, but not the value
that the property maintaines. If you look up the attribute on the instance,
the property (or descriptor) will hand it to you. The same applies to
method lookups and other special attributes that may also be implemented as
descriptors.

Also take a look at Cython, which is designed to keep users from having to
learn all these things and instead lets you do them in Python.

https://cython.org/

Stefan

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


Re: C API PyObject_GetAttrString returns not the object I expected

2019-02-10 Thread Phil Thompson
On 10 Feb 2019, at 12:08 pm, Barry Scott  wrote:
> 
> After calling PyObject_GetAttrString() I expected to get a PyObject string 
> back but I found that I had been given a  instead.
> 
> (gdb) p *args_o 
> $4 = 
> 
> What is going on and how do I get from the  to the object 
> I 
> want?

The "String" part of "PyObject_GetAttrString()" refers to the way you provide 
the attribute name and not the type of the object returned.

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


[issue35953] crosscompilation fails with clang on android

2019-02-10 Thread Karthikeyan Singaravelan


Change by Karthikeyan Singaravelan :


--
nosy: +xdegaye

___
Python tracker 

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



[issue35460] Add PyDict_GetItemStringWithError

2019-02-10 Thread Ronald Oussoren


Ronald Oussoren  added the comment:

Adding PyDict_GetItemStringWithError makes is possible to migrate existing code 
to a design that does not ignore errors.  I have a significant number of calls 
to PyDict_GetItemString that cannot be switch toed PyDict_GetItem without 
increasing the number of lines of C code I have to write (or in other words, if 
PyDict_GetItemString wouldn't exist I'd have invented this myself for use in 
extensions I write).

Another reason for adding the function is consistency in the API. 

BTW. I've added a function with the same signature as the proposed 
PyDict_GetItemStringWithError to my exension's code base, which is something 
I'd have to do anyway for backward compatibility with older CPython versions.

W.r.t API design: I prefer the interface of _PyObject_LookupAttr to that of 
PyDict_GetItemWithError, even if the additional cost of a call to 
PyErr_Occurred() is insignificant in most of my code (esp. when guarded with a 
test for a NULL return value from PyDict_GetItemWithError).

--

___
Python tracker 

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



[issue12317] inspect.getabsfile() is not documented

2019-02-10 Thread Dong-hee Na


Dong-hee Na  added the comment:

@terry.reedy
I submited the PR 11786 for this issue.
If you are okay can you take a look please?
Thanks!

--

___
Python tracker 

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



[issue35954] Incoherent type conversion in configparser

2019-02-10 Thread Rémi Lapeyre

Change by Rémi Lapeyre :


--
nosy: +remi.lapeyre

___
Python tracker 

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



  1   2   >