Re: [Tutor] beginning to code

2017-09-21 Thread Bill

Stefan Ram wrote:

Bill  writes:

"Essential Reference", and I would say that Python is definitely a
bigger, and more complicated language than C++.  In some aspects it has
simpler syntax.  But consider all of the ways that you can pass
arguments to a function, for instance. There are definitely alot more
options than in C/C++. I like the way that both of these languages

   In C++, you can pass:


I used the word *arguments*, not parameters.  FWIW, *const* seems to 
correspond to immutable, pretty well.  I find Python to be more more 
like Java, with regard to "passing objects by reference".





 - by value (with a const or non-const parameter)
   (where the value can be a pointer or a non-pointer
   or a pointer-to-member or a unique_ptr or a shared_ptr)
 - by reference
 - by const reference
 - by rvalue reference
 - by universal reference
 - by name (in macros)
 - you can overload functions with the same name
   but different numbers of parameter or different
   types for their parameters
 - you can write templates for functions with ranges of types
   for a parameter
 - default values can be declared for parameters

   In Python, you pass

 - by value

   The section 6.3.4 on calls "in The Python Language
   Reference, Release 3.6.0" encompasses 1½ pages.


You are sounding like a "know-it-all" again.  I am familiar with such
examples.  One could code in C++ for a long time without a definitive
need for templates.

   Ok, so if we exclude from C++ everything that you have not
   learned yet, than, what is left over, is "much easier" for
   you to read "at a glance". It seems that you want C++ to be
   adjusted to your knowledge of it and your assertions about
   it. I think that one should instead adjust one's assertions
   to the reality.

The Python Language Reference, Release 3.6.0 146 pages
latest ISO-C++ draft (without the library part)  464 pages


Bear in mind that you don't have to know every feature of a language to 
make good use of it, unless, perhaps, that is your job.  I don't believe 
reading the latest "ISO-C++ draft" would be a good use of my time; it 
sounds like a document geared more to compiler designers. I don't even 
try to memorize . If I need a function, I search for it.


There is a reason that C++, Java and Python all coexist. It might be 
helpful for you to try to appreciate that.


Regards,
Bill

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


[issue31452] asyncio.gather does not cancel tasks if one fails

2017-09-21 Thread Yury Selivanov

Yury Selivanov added the comment:

> I'm afraid I no longer have all the details of this design in my head, and I 
> have no idea what the fix does (and no time to read up on everything).

Let's say we have three tasks: t1, t2, t3.  Then we use gather on them:

   await gather(t1, t2, t3)

Let's say that t2 finishes first with an exception.

Currently, both t1 and t3 would continue their execution even though gather 
throws the t2 exception.

The PR for this issue makes 'gather' to cancel both t1 and t3 as soon as t2 
throws an exception.

The question is: I see the point of the PR, but I'm afraid that it's too late 
to change the semantics of asyncio.gather.  Instead we should consider adding 
new TaskGroup API (we discussed it briefly on the sprint).

--

___
Python tracker 

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



Re: Old Man Yells At Cloud

2017-09-21 Thread Steve D'Aprano
On Fri, 22 Sep 2017 02:00 pm, Rick Johnson wrote:

> I think it's grossly unfair to label those who's lives
> have been up-ended by the backwards incompatible changes of
> Python3 as "haters". 

Nobody, not one person, has ever had their life upended by Python 3.

People have their lives upended by war, by disease, by serious injury, by
natural disasters. They have their lives upended by losing their home to the
bank, or in an earthquake, or a hurricane. They have their lives upended by
cancer, by bombs, by serious car accidents, by floods and fires.

Having to spend a few hours being paid to migrate code using "print x"
to "print(x)", or even a few months, is not a life-changing experience.


> Most of these people did not want or 
> even need these changes, 

If they didn't want somebody else making the decision, they should have invented
their own language and used that instead.




-- 
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.

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


Re: Old Man Yells At Cloud

2017-09-21 Thread Rick Johnson
On Thursday, September 21, 2017 at 10:12:25 AM UTC-5, Steve D'Aprano wrote:
> [...]
> And remember that the Python core developers feel your pain
> too. They had to migrate a large code base (the Python std
> library) from 2 to 3. They had to write the 2to3
> translator. And they have to maintain two independent code
> bases, 2 and 3, in parallel, for a decade or more, and put
> up with thousands of internet haters going on and on and on
> and on about "Python 3 is destroying Python", year after
> year after year.
I think it's grossly unfair to label those who's lives
have been up-ended by the backwards incompatible changes of
Python3 as "haters". Most of these people did not want or
even need these changes, and they were just happy to be
using a language that was intuitive, productive and did not
distract them from solving whatever problem happened to need
solving at the moment.

Sure, i think all the changes are great (except for type
hints, and i'm withholding my judgment of async for the time
being...), and had these changes been a part of the original
language, Python would have been a better language for it.

Personally, i will not decide whether or not to migrate
until Python4, and i suspect i am not alone in this regard.
And if Py-dev feels betrayed by the community, well, they
should understand that we feel betrayed as well. We have
invested decades into this language, and to have our
investments ruined by changes we did not ask for is
devastating.

So, can we overcome this devastation?

Possibly.

But Py-dev needs to understand that breaking backwards
compatibility is no small thing, and they also need to
understand that alienating the Python2.X'ers is not helping
the migration to Python3. I assure you, this community
cannot endure another one of these "engineered natural
disasters".

One of the reasons we've been so loyal to Python, is that, at
least historically, we had faith in GvR's judgments. And
while his fabled time machine has saved our bums on more
than one occasion, these days, some of us are not so sure of
our capitan's navigational abilities, and are feeling a bit
like we are the unlucky passengers on the Titanic. Speaking
personally here, i know i could have overcome the backwards
incompatible thing _eventually_, but Python3, followed by
the introduction of type-hints has been such a earth
shattering 1-2-punch, that i'm really struggling to stay on
my feet at this point.

I mean, i guess i could delude myself and imagine that type-
hints don't exist, but that's about as realistic as ignoring
a giant dent in the side of my beautiful car. Sure, the car
drives just fine, but the ugly dent sours the experience.
:-(


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


[issue31550] Inconsistent error message for TypeError with subscripting

2017-09-21 Thread Anthony Sottile

Changes by Anthony Sottile :


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

___
Python tracker 

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



[issue31550] Inconsistent error message for TypeError with subscripting

2017-09-21 Thread Anthony Sottile

New submission from Anthony Sottile:

There's a bit of history I don't understand and couldn't find the appropriate 
trail for.

The original error message from the 2.6 era:

$ python2.6 -c 0[0]
Traceback (most recent call last):
  File "", line 1, in 
TypeError: 'int' object is unsubscriptable


This was changed in 
https://github.com/python/cpython/commit/f5fd5239819c5dfb1d7a33484be49dc705544d02
 for clarity

As seen in 2.7.1

$ ./python2.7.1 -c 0[0]
Traceback (most recent call last):
  File "", line 1, in 
TypeError: 'int' object is not subscriptable


It was later changed in the 2.7 era here: 
https://github.com/python/cpython/commit/7d1483cbadbe48620964348a2039690624e7dc8e


To this error message (as demonstrated with 2.7.12):

$ python2.7 -c 0[0]
Traceback (most recent call last):
  File "", line 1, in 
TypeError: 'int' object has no attribute '__getitem__'


However, this patch never made it into the 3.x branch:

$ python3.6 -c 0[0]
Traceback (most recent call last):
  File "", line 1, in 
TypeError: 'int' object is not subscriptable


Should this patch be (have been) cherry picked into master?

--
components: Interpreter Core
messages: 302736
nosy: Anthony Sottile
priority: normal
severity: normal
status: open
title: Inconsistent error message for TypeError with subscripting
type: behavior
versions: Python 3.7

___
Python tracker 

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



[issue31452] asyncio.gather does not cancel tasks if one fails

2017-09-21 Thread Guido van Rossum

Guido van Rossum added the comment:

I'm afraid I no longer have all the details of this design in my head, and I 
have no idea what the fix does (and no time to read up on everything).

The OP says "If you do not await gather" -- what happens if you *do* await it? 
Do the tasks then get killed?

It seems strange to both cancel the task *and* set its exception.

The docstring for gather() seems to be pretty clear that cancellation and 
failure of one task should not affect other tasks. So this argues against the 
PR.

--

___
Python tracker 

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



Re: [Tutor] beginning to code

2017-09-21 Thread Bill

Stefan Ram wrote:

Bill  writes:

I understand string[::-1] after only studying python for a day or two
(I've only been studying it for 2 weeks at this point).  A student could
study C++ for a semester or more and not encounter templates until they
studied data structures.  So in short, I don't believe that the example
you chose from Python and the one you chose from C++, were at similar
levels (not even close).

   I was responding to your assertion:

|It's much easier to tell what's going on, at a glance, in a
|C++ program.

   and I showed a simple counterexample.

But it was *not* a simple counterexample.

   And above, now, it seems that you /agree/ that one can learn
   Python in a short time, but needs a lot longer to learn C++.
Learning to develop code, in either language, involves much more than 
"learning C++" or "learning Python".  I have been reading Beazley's 
"Essential Reference", and I would say that Python is definitely a 
bigger, and more complicated language than C++.  In some aspects it has 
simpler syntax.  But consider all of the ways that you can pass 
arguments to a function, for instance. There are definitely alot more 
options than in C/C++. I like the way that both of these languages 
(unlike Java) allow you to stick with the procedural paradigm if you 
wish to (which I think is a natural way for a true beginner to start).  
From my perspective, Python's simplicity lies in the fact that an 
entire program does not have to be recompiled if a module is changed. 
Since I was programming in C (and Fortran) before you were born, it's 
syntax does not generally pose a hindrance to me.





   BTW: templates have little to do with data structures. One can
   show resonable examples for function templates that do not use
   any data structure:
You are sounding like a "know-it-all" again.  I am familiar with such 
examples.  One could code in C++ for a long time without a definitive 
need for templates.  It just depends on the application. By trade, I am 
more of a mathematician than a programmer but sometimes my needs and/or 
interests overlap.





template< typename T >
T maximum( T const a, T const b ){ return a > b ? a : b; }

   . The corresponding Python def would be (untested):

def maximum( a, b ): return a if a > b else b

   , that is, because Python is not statically typed, one does
   not need a template for a corresponding definition in Python.



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


Re: Easy way to get a list of tuples.

2017-09-21 Thread Sayth Renshaw

> >
> >  Thanks Thomas yes you are right with append. I have tried it but just 
> > can't get it yet as append takes only 1 argument and I wish to give it 3.
> >
> You have not showed us what you tried, but you are probably missing a pair 
> of brackets.
> 
> C:\Users\User>python
> Python 3.6.0 (v3.6.0:41df79263a11, Dec 23 2016, 08:06:12) [MSC v.1900 64 bit 
> (AMD64)] on win32
> Type "help", "copyright", "credits" or "license" for more information.
> >>> x = []
> >>> x.append(('a', 'b', 'c'))
> >>> x.append(('p', 'q', 'r'))
> >>> x
> [('a', 'b', 'c'), ('p', 'q', 'r')]
> >>>
> 
> Does this help?
> 
> Frank Millman

Oh yes I just had one set of brackets with my append.

Thanks

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


[issue31092] multiprocessing.Manager() race condition

2017-09-21 Thread Prof Plum

Changes by Prof Plum :


--
title: Potential multiprocessing.Manager() race condition -> 
multiprocessing.Manager() race condition

___
Python tracker 

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



Re: [Tutor] beginning to code

2017-09-21 Thread Bill

Stefan Ram wrote:

Just as Python's »string[::-1]« appears "obfuscated"
   to readers who don't know Python.


I understand string[::-1] after only studying python for a day or two 
(I've only been studying it for 2 weeks at this point).  A student could 
study C++ for a semester or more and not encounter templates until they 
studied data structures.  So in short, I don't believe that the example 
you chose from Python and the one you chose from C++, were at similar 
levels (not even close).




   It was the answer to the question "How can I express the
   class I'm in in, when I can't write that classes name
   literally? So, »S« is »example«.

   It works like this: The type of »« is »void ( example::*
   )()«. So, the function-declaration template »T« infers »C«
   to be »example«, and the type of »T(  )« is »example«,
   which then is transferred to the name »S« using typedef.

   This is obvious for C++ programmers, but it takes a lot
   of time to become a C++ programmer, maybe more than it
   takes to become a Python programmer.



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


Re: [Tutor] beginning to code

2017-09-21 Thread Bill

Stefan Ram wrote:

Bill  writes:

Stefan Ram wrote:

bartc  writes:

On 20/09/2017 02:31, Bill wrote:

it's implementation, I would say that C++ has it all over Python from
the point of view of "intuitiveness".  It's much easier to tell what's
going on, at a glance, in a C++ program.

You're being serious, aren't you?

For one example, this is a part of a C++ program:
template< typename C >C T( void ( C::* )() );
. It defines a template T, that can be used in a
class as follows:
struct example { void f(); typedef decltype( T(  )) S; };
. The type »S« now has a certain property, that can
be useful sometimes. What is this property (asking Bill)?As

has already been pointed out, one can write "obfuscating code" in any
language, with little effort.  I strive to write code which is easily
understandable--and I document it. I don't wish to debate whether I
could make more of a mess in Python, or not.

   From the point of view of a C++ programmer,
Oh, we "all look the same", huh?  I know that we've only just met, but I 
will caution that you are coming across as something of a "know-it-all".


Bill





the above
   is not obfuscated, but it is readable and simple C++.
   It is of course not readable for readers who do not know
   C++. Just as Python's »string[::-1]« appears "obfuscated"
   to readers who don't know Python.

   It was the answer to the question "How can I express the
   class I'm in in, when I can't write that classes name
   literally? So, »S« is »example«.

   It works like this: The type of »« is »void ( example::*
   )()«. So, the function-declaration template »T« infers »C«
   to be »example«, and the type of »T(  )« is »example«,
   which then is transferred to the name »S« using typedef.

   This is obvious for C++ programmers, but it takes a lot
   of time to become a C++ programmer, maybe more than it
   takes to become a Python programmer.



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


[issue31544] gettext.Catalog title is not flagged as a class

2017-09-21 Thread Éric Araujo

Éric Araujo added the comment:

Are you talking about 
https://docs.python.org/3/library/gettext.html#the-catalog-constructor ?  I 
think the lack of markup is on purpose, since the text explains that this is a 
compatibility measure (mostly obsolete nowadays).

For future bug reports, please include links or screenshots!  They make it 
easier to communicate.

--
nosy: +merwok
versions:  -Python 3.3, Python 3.4, Python 3.5

___
Python tracker 

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



[issue31543] Optimize wrapper descriptors using FASTCALL

2017-09-21 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

These slots are the only slots that accept keyword arguments and arbitrary 
number of positional parameters. Other slots can use fast calls.

--

___
Python tracker 

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



[issue31549] test_strptime and test_time fail on non-English Windows

2017-09-21 Thread Serhiy Storchaka

New submission from Serhiy Storchaka:

test_strptime and test_time fail on non-English Windows.

For example:

==
FAIL: test_localtime_timezone (test.test_time.TestPytime)
--
Traceback (most recent call last):
  File "C:\Users\Serhiy Storchaka\py\cpython\lib\test\test_time.py", line 643, 
in test_localtime_timezone
self.assertEqual(lt.tm_zone, time.tzname[lt.tm_isdst])
AssertionError: 'O?ieyia?y (e?oi)' != '\xd4\xb3\xed\xeb\xff\xed\xe4\xb3\xff 
(\xeb\xb3\xf2\xee)'
- O?ieyia?y (e?oi)
+ \xd4\xb3\xed\xeb\xff\xed\xe4\xb3\xff (\xeb\xb3\xf2\xee)

Seems there are problems with wrong encodings and lossy encoding on Windows.

>>> '\xd4\xb3\xed\xeb\xff\xed\xe4\xb3\xff (\xeb\xb3\xf2\xee)'
'Ô³íëÿíä³ÿ (ë³òî)'

Looks similar to the string 'O?ieyia?y (e?oi)', isn't?

>>> 'ô³íëÿíä³ÿ (çèìà)'.encode('latin1').decode('cp1251')
'фінляндія (зима)'

Actually it is a string 'фінляндія (зима)' ('Finland (Summer)' in Ukrainian) 
encoded with cp1251 (Cyrillic ANSI encoding) and misinterpreted as encoded with 
Latin1.

--
components: Library (Lib), Windows
messages: 302732
nosy: paul.moore, serhiy.storchaka, steve.dower, tim.golden, zach.ware
priority: normal
severity: normal
status: open
title: test_strptime and test_time fail on non-English Windows
type: behavior
versions: Python 3.7

___
Python tracker 

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



[issue31539] asyncio.sleep may sleep less time then it should

2017-09-21 Thread Yury Selivanov

Yury Selivanov added the comment:

> The performance issue was that the asyncio core loop was running in a loop
but did nothing because of time rounding. When the next event was in a few
nanoseconds, the e event burnt the CPU during  seconds.
It can be 15 ms on Windows or 1 ms when using poll() for example. It's not
just clock resolution, also the resolution of the selector.

Hm.  I glanced through the issues you linked, and it looks like it's a valid 
concern for a micro-benchmark.  But I don't see how a performance of a 
real-world application can be affected here.  IOW, the "self.time() + 
self._clock_resolution" line looks like an optimization for a particular 
micro-benchmark.  I'm sure we can construct another micro-benchmark that would 
benefit from "self.time() - self._clock_resolution".

I think we should value correctness more than micro-benchmarks.

--

___
Python tracker 

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



[issue31539] asyncio.sleep may sleep less time then it should

2017-09-21 Thread STINNER Victor

STINNER Victor added the comment:

Issues:
- bpo-20320
- bpo-20452
- bpo-20505
- bpo-20311

The performance issue was that the asyncio core loop was running in a loop
but did nothing because of time rounding. When the next event was in a few
nanoseconds, the e event burnt the CPU during  seconds.
It can be 15 ms on Windows or 1 ms when using poll() for example. It's not
just clock resolution, also the resolution of the selector.

Hopefully, select and selectors now round towards +inf (rather than
rounding down, towards zero or -inf) and so the selector resolution is no
more an issue if I recall correctly.

--

___
Python tracker 

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



[issue31539] asyncio.sleep may sleep less time then it should

2017-09-21 Thread Yury Selivanov

Yury Selivanov added the comment:

So here's the relevant piece of code:

end_time = self.time() + self._clock_resolution
while self._scheduled:
handle = self._scheduled[0]
if handle._when >= end_time:
break
handle = heapq.heappop(self._scheduled)
handle._scheduled = False
self._ready.append(handle)


As I see it, currently we peek into the future time.  Why don't we do 

end_time = self.time() - self._clock_resolution

to guarantee that timeouts will always be triggered *after* the requested time, 
not before?  I don't see how the performance can become worse if we do this.

--

___
Python tracker 

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



[issue31548] test_os fails on Windows if current directory contains spaces

2017-09-21 Thread Serhiy Storchaka

New submission from Serhiy Storchaka:

I just have built Python on Windows first time and ran tests. test_os fails 
because the current directory path contains spaces.

test_spawnl (test.test_os.SpawnTests) ... C:\Users\Serhiy: can't open file 
'Storchaka\py\cpython\PCBuild\win32\python.exe': [Errno 2] No such file or 
directory
FAIL

--
components: Tests, Windows
files: test_os.log
messages: 302728
nosy: paul.moore, serhiy.storchaka, steve.dower, tim.golden, zach.ware
priority: normal
severity: normal
status: open
title: test_os fails on Windows if current directory contains spaces
type: behavior
versions: Python 3.7
Added file: https://bugs.python.org/file47163/test_os.log

___
Python tracker 

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



[issue31539] asyncio.sleep may sleep less time then it should

2017-09-21 Thread Antoine Pitrou

Changes by Antoine Pitrou :


--
nosy: +gvanrossum

___
Python tracker 

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



[issue31539] asyncio.sleep may sleep less time then it should

2017-09-21 Thread Antoine Pitrou

Antoine Pitrou added the comment:

Le 21/09/2017 à 23:31, STINNER Victor a écrit :
> 
> Yury: asyncio can trigger events earlier than scheduled for performance
> reasons.

If that's true, then it sounds like a bug.  If there is a rationale for
a "fast and imprecise" API, then it would seem ok to add such an API.
But the default API for event scheduling should not take such shortcuts
IMHO.  Most users don't schedule thousands of events at a time, however
they expect timeouts to be observed as rigorously as is possible given
the usual implementation constraints such as GC pauses.

--

___
Python tracker 

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



[issue31539] asyncio.sleep may sleep less time then it should

2017-09-21 Thread STINNER Victor

STINNER Victor added the comment:

IMHO we should either just close the issue, ir document the bad clock
resolution on Windows in the asyncio doc.

Yury: asyncio can trigger events earlier than scheduled for performance
reasons. See end_time in asyncio core loop.

--

___
Python tracker 

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



[issue31539] asyncio.sleep may sleep less time then it should

2017-09-21 Thread Yury Selivanov

Yury Selivanov added the comment:

> it's expected that the sleep time may be *more* than asked for, but not less 
> than.

Exactly, and asyncio tries to ensure that.  It looks like 
"time.get_clock_info('monotonic').resolution" lies about monotonic clock 
resolution on Windows so that might be the actual issue we want to address.

--

___
Python tracker 

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



[issue31543] Optimize wrapper descriptors using FASTCALL

2017-09-21 Thread STINNER Victor

STINNER Victor added the comment:

The most complex slots are __new__, __init__ and __call__ because they
accept keywords. It's hard to design a calling convention which optimize
all cases because of the backward compatibility. The risk is to convert a
dict to args + kwnames (tuple) and then back to a dict: two expensive and
useless conversions.

It's my 3rd or 4th attempt to optimize new/init/call :-) My previous
attempt was to add new tp_fastXXX slots to types, but again thr backward
compatibilty was a major pain.
https://bugs.python.org/issue29358

Here the scope is much small and backward compatibilty shouldn't affect us.

I will try to find a way to optimize these slots as well and complete my
patch.

--

___
Python tracker 

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



[issue31539] asyncio.sleep may sleep less time then it should

2017-09-21 Thread Antoine Pitrou

Changes by Antoine Pitrou :


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



[issue31539] asyncio.sleep may sleep less time then it should

2017-09-21 Thread Antoine Pitrou

Antoine Pitrou added the comment:

I don't think the bug is about real time here, rather about minimal sleep time 
expectations; i.e. it's expected that the sleep time may be *more* than asked 
for, but not less than.

(and I would share that expectation myself)

--

___
Python tracker 

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



[issue31539] asyncio.sleep may sleep less time then it should

2017-09-21 Thread STINNER Victor

STINNER Victor added the comment:

Technically, asyncii cannot wait exactly 100 ms on Windows. It will be more
likely a sleep between 100-15 ms and 100+15 ms. Real time is really a
complex topic. CPython with its stop-the-world garbage collector are not
designed for real time.

--

___
Python tracker 

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



[issue26103] Contradiction in definition of "data descriptor" between (dotted lookup behavior/datamodel documentation) and (inspect lib/descriptor how-to)

2017-09-21 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

The only question is remained -- should *data descriptors* be *descriptors*? 
I.e. is the __get__ method required for data descriptors?

--

___
Python tracker 

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



Re: Convert pandas series to string and datetime object

2017-09-21 Thread Peter Otten
zljubi...@gmail.com wrote:

> I have sliced the pandas dataframe
> 
> end_date = df[-1:]['end']
> 
> type(end_date)
> Out[4]: pandas.core.series.Series
> 
> end_date
> Out[3]:
> 48173   2017-09-20 04:47:59
> Name: end, dtype: datetime64[ns]
> 
> 1.How to get rid of index value 48173 and get only "2017-09-20 
04:47:59"
> string? I have to call REST API with "2017-09-20 04:47:59" as a parameter,
> so I have to get string from pandas datetime64 series.
> 2.How to get rid of index value 48173 and get only datetime object
> [something like datetime.datetime.strptime('2017-09-20 04:47:59',
> '%Y-%m-%d %H:%M:%S')]. Later I will have to check if '2017-09-20 04:47:59'
> < datetime.datetime(2017,1,9)
> 
> How to do these conversions?

After a web search and some trial and error:

>>> d = pd.DataFrame([[1, datetime.datetime.now()], [2, 
datetime.datetime.now()]], columns=["whatever", "end"])
>>> d
   whateverend
0 1 2017-09-21 22:36:52.342757
1 2 2017-09-21 22:36:52.349973

[2 rows x 2 columns]
>>> d["end"].astype(datetime.datetime).values[-1]
datetime.datetime(2017, 9, 21, 22, 36, 52, 349973)


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


[issue31452] asyncio.gather does not cancel tasks if one fails

2017-09-21 Thread Yury Selivanov

Yury Selivanov added the comment:

I looked at the PR, and I'm not so sure about this change.  In short, it can be 
viewed as a backwards incompatible change to asyncio.gather.

Guido, what do you think?

--
nosy: +gvanrossum

___
Python tracker 

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



Re: Convert pandas series to string and datetime object

2017-09-21 Thread MRAB

On 2017-09-21 20:27, zljubi...@gmail.com wrote:

I have sliced the pandas dataframe

end_date = df[-1:]['end']

type(end_date)
Out[4]: pandas.core.series.Series

end_date
Out[3]:
48173   2017-09-20 04:47:59
Name: end, dtype: datetime64[ns]

1.  How to get rid of index value 48173 and get only "2017-09-20 04:47:59" string? I 
have to call REST API with "2017-09-20 04:47:59" as a parameter, so I have to get string 
from pandas datetime64 series.
2.  How to get rid of index value 48173 and get only datetime object 
[something like datetime.datetime.strptime('2017-09-20 04:47:59', '%Y-%m-%d 
%H:%M:%S')]. Later I will have to check if '2017-09-20 04:47:59' < 
datetime.datetime(2017,1,9)

How to do these conversions?

The docs say that pandas.Series is "One-dimensional ndarray with axis 
labels (including time series)", so have you tried indexing, such as 
end_date[1]?

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


[issue31153] Update docstrings of itertools functions

2017-09-21 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

For groupby() see also issue27385.

--

___
Python tracker 

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



[issue30346] Odd behavior when unpacking `itertools.groupby`

2017-09-21 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Ping. Can you make your decision Raymond?

This issue is a stopper for issue30347 which fixes a crash. I don't want to 
merge the fix for issue30347 until this issue be solved, because both proposed 
PRs solve issue30347 too, and I don't want to make unneeded changes or move 
code forth and back.

--

___
Python tracker 

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



Re: iPython ? magic

2017-09-21 Thread Pavol Lisy
On 9/21/17, Steve D'Aprano  wrote:
> In the iPython interactive interpreter, obj? prints information about the
> given
> object. For example:
>
>
> In [11]: None?
> Type:   NoneType
> Base Class: 
> String Form:None
> Namespace:  Python builtin
> Docstring:  
>
>
> Does anyone know that the Namespace field is supposed to show? I can't get
> it to
> display anything except either "Python builtin" or "Interactive".

I discovered that there are 3 default namespaces ->

https://github.com/ipython/ipython/blob/79921f6fe380f57cf353d76615e4fd8472c83118/IPython/core/interactiveshell.py#L1405

But you could somehow change or add other namespaces (maybe ipdb could
add local namespace to evaluate local variables).

You could check thist code:

import IPython
ip = IPython.core.getipython.get_ipython()
print(ip.user_ns)  # this is in 'Interactive' namespace
print(ip.user_global_ns)# this is in 'Interactive (global)' namespace

# next line show how somewhat somewhere could change namespace where
object names are searched
ip._inspect("pinfo", "None", [("my namespace", {"None":None})])
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Test Bank for Management, Operations Management, Supply Chain Management, Project Management for all editions

2017-09-21 Thread louisacorey
Organizational Behavior and Management, 11th Edition by Robert Konopaske and 
John Ivancevich and Michael Matteson
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue31543] Optimize wrapper descriptors using FASTCALL

2017-09-21 Thread Raymond Hettinger

Raymond Hettinger added the comment:

This seems like a straight-forward win.  I don't think we really need to see 
microbenchmarks before going forward with this one.

--
nosy: +rhettinger

___
Python tracker 

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



Re: Re: errors with json.loads

2017-09-21 Thread john polo

On 9/21/2017 10:11 AM, Ned Batchelder wrote:


I can only assume that the actual data being read is different than 
the data they put into the message here.


--Ned.

There was a typo in the file that I had made and saved; an extra comma 
before one of the ":". Apologies to the list for not catching that sooner.



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


Convert pandas series to string and datetime object

2017-09-21 Thread zljubisic
I have sliced the pandas dataframe 

end_date = df[-1:]['end']

type(end_date)
Out[4]: pandas.core.series.Series

end_date
Out[3]: 
48173   2017-09-20 04:47:59
Name: end, dtype: datetime64[ns]

1.  How to get rid of index value 48173 and get only "2017-09-20 04:47:59" 
string? I have to call REST API with "2017-09-20 04:47:59" as a parameter, so I 
have to get string from pandas datetime64 series.
2.  How to get rid of index value 48173 and get only datetime object 
[something like datetime.datetime.strptime('2017-09-20 04:47:59', '%Y-%m-%d 
%H:%M:%S')]. Later I will have to check if '2017-09-20 04:47:59' < 
datetime.datetime(2017,1,9)

How to do these conversions?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How does CPython build it's NEWS or changelog?

2017-09-21 Thread Ben Finney
Stefan Behnel  writes:

> https://docs.python.org/devguide/committing.html#what-s-new-and-news-entries
>
> https://github.com/larryhastings/blurb

Also of interest is the more general-use Town Crier tool:

towncrier is a utility to produce useful, summarised news files for
your project. Rather than reading the Git history as some newer
tools to produce it, or having one single file which developers all
write to, towncrier reads “news fragments” which contain information
useful to end users.



-- 
 \   “The Initial Mystery that attends any journey is: how did the |
  `\   traveller reach his starting point in the first place?” —Louise |
_o__)  Bogan, _Journey Around My Room_ |
Ben Finney

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


Re: [Tutor] beginning to code

2017-09-21 Thread Bill

Stefan Ram wrote:

bartc  writes:

On 20/09/2017 02:31, Bill wrote:

it's implementation, I would say that C++ has it all over Python from
the point of view of "intuitiveness".  It's much easier to tell what's
going on, at a glance, in a C++ program.

You're being serious, aren't you?

   For one example, this is a part of a C++ program:

template< typename C >C T( void ( C::* )() );

   . It defines a template T, that can be used in a
   class as follows:

struct example { void f(); typedef decltype( T(  )) S; };

   . The type »S« now has a certain property, that can
   be useful sometimes. What is this property (asking Bill)?

I'll reveal that I'm not Bjarne Stroustrup.  decltype was introduced in 
C++11, which I haven't explored, and I have never written any code that 
resembles your template.  But it appears that an object of type S may 
behave like a function, which in this case would invoke Example.f().  As 
has already been pointed out, one can write "obfuscating code" in any 
language, with little effort.  I strive to write code which is easily 
understandable--and I document it. I don't wish to debate whether I 
could make more of a mess in Python, or not.


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


[ANN] PyInstaller 3.3

2017-09-21 Thread Hartmut Goebel
Hello,

on behalf of the PyInstaller development team I'm happy to announce
PyInstaller 3.3. Most important change for this release is the support
for Python 3.6.

   http://www.pyinstaller.org


Thanks for all those who contributed questions, bug-reports or
pull-requests.


=== What it is ===

PyInstaller bundles a Python application and all its dependencies into a
single package. The user can run the packaged app without installing a
Python interpreter or any modules.

PyInstaller reads a Python script written by you. It analyzes your code to
discover every other module and library your script needs in order to
execute.
Then it collects copies of all those files – including the active Python
interpreter! – and puts them with your script in a single folder, or
optionally in a single executable file.

PyInstaller is tested against Windows, Mac OS X, and Linux. However, it
is not a cross-compiler: to make a Windows app you run PyInstaller in
Windows; to make a Linux app you run it in Linux, etc. PyInstaller has
been used successfully with AIX, Solaris, and FreeBSD, but is not tested
against them.

=== Installation ===

PyInstaller can be installed from PyPi using

   pip install pyinstaller

=== Important Changes ===

* Add Support for Python 3.6! Many thanks to xiovat! (#2331, #2341)

* New command line options for adding data files (``--datas``, #1990) and
  binaries (``--binaries``, #703)

* Add command line option '--runtime-tmpdir'.

* Bootloaders for Windows are now build using MSVC and statically linked with
  the run-time-library (CRT). This solved a lot of issues related to .dlls
  being incompatible with the ones required by ``python.dll``.

* Bootloaders for GNU/Linux are now officially no LSB binaries. This was
  already the case since release 3.1, but documented the other way round. Also
  the build defaults to non-LSB binaries now. (#2369)

* We improved and stabilized both building the bootloaders and the continuous
  integration tests. See below for details. Many thanks to all who worked on
  this.

* To ease solving issues with packages included wrongly, the html-file with a
  cross-reference is now always generated. It's visual appearance has been
  modernized (#2765).


The full changelog for this release can be found at:

   https://pyinstaller.readthedocs.io/en/v3.3/CHANGES.html


=== Feedback ===

We're eager to listen to your feedback on using PyInstaller:

 Bug tracker: https://github.com/pyinstaller/pyinstaller/issues
 Mailing list: http://groups.google.com/group/PyInstaller

-- 
Schönen Gruß
Hartmut Goebel
Dipl.-Informatiker (univ), CISSP, CSSLP, ISO 27001 Lead Implementer
Information Security Management, Security Governance, Secure Software
Development

Goebel Consult, Landshut
http://www.goebel-consult.de

Blog:
http://www.goebel-consult.de/blog/warum-sie-nicht-perl-programmiern-sollten
Kolumne: http://www.cissp-gefluester.de/2012-02-bring-your-own-life-glosse

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

Support the Python Software Foundation:
http://www.python.org/psf/donations/


Re: Assertions

2017-09-21 Thread Chris Angelico
On Fri, Sep 22, 2017 at 3:49 AM, Steve D'Aprano
 wrote:
> On Fri, 22 Sep 2017 03:31 am, Chris Angelico wrote:
>
>> Impressive. That means that, in 2.7, it's actually equivalent to:
>>
> def test3():
>> ... if not foo: raise AssertionError, "bar baz"
>
> That's nothing. In 1.5 (yes, *one* point five) it's equivalent to something 
> more
> or less like this:
>
> def test4():
> if __debug__:
> if foo:
> return
> raise AssertionError('bar baz')

AIUI, it's still equivalent to that - with the proviso that the
optimizer removes references to __debug__:

>>> def foo():
...   if __debug__: print("Debugging")
...
>>> import dis
>>> dis.dis(foo)
  2   0 LOAD_CONST   1 ('Debugging')
  3 PRINT_ITEM
  4 PRINT_NEWLINE
  5 LOAD_CONST   0 (None)
  8 RETURN_VALUE

and the optimizer may or may not differentiate between the two ways of
writing the code. It is interesting to observe the changes to the
optimizer, but none of them are assert-specific.

(And I just made an assertion about the optimizer and the assert
statement. It is falsifiable, but if true, it is an optimal
optimizer/assertion assertion.)

>> Although in the 2.7 that I have, the assert statement does actually
>> *call* AssertionError (ie it constructs an instance and raises it).
>> What version are you running? Here's mine:
>>
>> $ python2
>> Python 2.7.13 (default, Jan 19 2017, 14:48:08)
>> [GCC 6.3.0 20170118] on linux2
>
> Now that you've showed me yours, I suppose I have to show you mine.
>
> Python 2.7.2 (default, May 18 2012, 18:25:10)
>
> So definitely version dependent.

Yep! Apparently five years of patchlevel changes can include some that
make notable byte-code changes. Which doesn't surprise me, merely
amuses.

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


[issue1612262] Class Browser doesn't show internal classes

2017-09-21 Thread Terry J. Reedy

Terry J. Reedy added the comment:

I am revising the codecontext patch to use comprehensions and the sort key 
option.  I will rename the new function 'collect_objects' (GPolo) / 
'_traverse_node' (CSabella) as 'list_children' and have it return the 
name-object list, ordered by line number, needed by the tree widget.

[The input is a dictionary of children of a node, rather than a node, because 
pyclbr returns the dictionary of the children of the root module node of the 
tree, rather than a root node itself.  Sorting is not actually needed for 3.6/7 
because the dicts are already ordered, but pyclbr does not guarantee this by 
using OrderedDict.  Proposing these two changes is a separate potential issue.]

--

___
Python tracker 

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



Re: Assertions

2017-09-21 Thread Steve D'Aprano
On Fri, 22 Sep 2017 03:31 am, Chris Angelico wrote:

> On Fri, Sep 22, 2017 at 3:23 AM, Steve D'Aprano
>  wrote:
>> That is definitely version-dependent, because I've just tried it and got
>> different byte-code in Python 2.7.
>>
>> py> import dis
>> py> def test1():
>> ... assert foo, "bar baz"
>> ...
>> py> def test2():
>> ... if not foo: raise AssertionError("bar baz")
>> ...
>> py>
>> py> dis.dis(test1)
>>   2   0 LOAD_GLOBAL  0 (foo)
>>   3 POP_JUMP_IF_TRUE15
>>   6 LOAD_GLOBAL  1 (AssertionError)
>>   9 LOAD_CONST   1 ('bar baz')
>>  12 RAISE_VARARGS2
>> >>   15 LOAD_CONST   0 (None)
>>  18 RETURN_VALUE
>> py> dis.dis(test2)
>>   2   0 LOAD_GLOBAL  0 (foo)
>>   3 POP_JUMP_IF_TRUE21
>>   6 LOAD_GLOBAL  1 (AssertionError)
>>   9 LOAD_CONST   1 ('bar baz')
>>  12 CALL_FUNCTION1
>>  15 RAISE_VARARGS1
>>  18 JUMP_FORWARD 0 (to 21)
>> >>   21 LOAD_CONST   0 (None)
>>  24 RETURN_VALUE
> 
> Impressive. That means that, in 2.7, it's actually equivalent to:
> 
 def test3():
> ... if not foo: raise AssertionError, "bar baz"

That's nothing. In 1.5 (yes, *one* point five) it's equivalent to something more
or less like this:

def test4():
if __debug__:
if foo:
return
raise AssertionError('bar baz')


> Although in the 2.7 that I have, the assert statement does actually
> *call* AssertionError (ie it constructs an instance and raises it).
> What version are you running? Here's mine:
> 
> $ python2
> Python 2.7.13 (default, Jan 19 2017, 14:48:08)
> [GCC 6.3.0 20170118] on linux2

Now that you've showed me yours, I suppose I have to show you mine.

Python 2.7.2 (default, May 18 2012, 18:25:10)

So definitely version dependent.


-- 
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.

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


Re: Assertions

2017-09-21 Thread Steve D'Aprano
On Fri, 22 Sep 2017 02:29 am, Tobiah wrote:

> Are these completely equivalent?
> 
> def foo(thing):
> 
> assert(thing > 0), "Thing must be greater than zero"
> 
> 
> def foo(thing):
> 
> if not (thing > 0): raise AssertionError("Thing must be greater than
> zero")
> 
> 
> Other than the fact that the assertion can be turned off
> with -O?

As I replied to Ned just now, the two may compile to slightly different
byte-code. But (apart from the -O optimization) they ought to be semantically
the same, as far as the interpreter goes. I'd be very surprised if the
byte-code differences were ever more than trivial.

But I don't think they are the same as far as the human reader goes. If you
believe the truism that code is written for other people, and only incidentally
to be run by computers, then I think we should say that the two above are very
different.

The first is an actual assertion. It has to be an assertion, because it uses the
assert keyword!

The second is testing a condition, and if need be, raising an exception. Which
looks like an inappropriate exception. Why AssertionError? It looks like it
ought to be a ValueError.

Assertions aren't merely a synonym for testing a condition and raising an
exception if the condition fails. Assertions have semantics to the human
reader. I wrote a blog post explaining why you should use assertions:

- you want a checked comment;
- you have code that can't possibly fail, unless it does;
- you are testing the program logic;
- you are checking a contract;

and when you should not. By using `assert`, you are signalling your intent to do
one of the above.

http://import-that.dreamwidth.org/676.html

But by using an ordinary `if ... raise AssertionError`, the intention is
ambiguous. If you meant for it to be an assertion, why not use assert? If it is
not an assertion, then AssertionError is probably the wrong exception.

(It is okay in a testing framework, like unittest, but a bad idea in a regular
library or an application. Your end-users should never see an AssertionError.)


The bottom line is, if I saw 

if not (thing > 0): raise AssertionError(...)

in a code review, I'd probably insist that either it be changed to use `assert`,
or the exception be changed to ValueError, whichever better expresses the
intention of the code.



-- 
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.

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


Re: Old Man Yells At Cloud

2017-09-21 Thread Chris Angelico
On Fri, Sep 22, 2017 at 3:07 AM, Rhodri James  wrote:
> On 21/09/17 17:31, Chris Angelico wrote:
>>
>> For a good while, I was in the same position. But instead of massively
>> rewriting everything, all I did was to adjust the material to use
>> Py2/Py3 compatible syntax. Adding parens around your print calls won't
>> stop it from being Py2-compatible, and it means that the shift to Py3
>> becomes a lot easier.
>
>
> It's compatible syntax, but it doesn't half look weird in Py2.
>
 x=2
 print("x is", x)
> ('x is', 2)

>
> is very unfriendly to young beginners.  We did consider it, but decided it
> was a non-starter; it was less effort to ignore Py3 entirely.

True, it's only identical if you do the formatting explicitly:

print("x is %s" % x)

But that does happen to be a very common case.

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


Re: Assertions

2017-09-21 Thread Chris Angelico
On Fri, Sep 22, 2017 at 3:23 AM, Steve D'Aprano
 wrote:
> That is definitely version-dependent, because I've just tried it and got
> different byte-code in Python 2.7.
>
> py> import dis
> py> def test1():
> ... assert foo, "bar baz"
> ...
> py> def test2():
> ... if not foo: raise AssertionError("bar baz")
> ...
> py>
> py> dis.dis(test1)
>   2   0 LOAD_GLOBAL  0 (foo)
>   3 POP_JUMP_IF_TRUE15
>   6 LOAD_GLOBAL  1 (AssertionError)
>   9 LOAD_CONST   1 ('bar baz')
>  12 RAISE_VARARGS2
> >>   15 LOAD_CONST   0 (None)
>  18 RETURN_VALUE
> py> dis.dis(test2)
>   2   0 LOAD_GLOBAL  0 (foo)
>   3 POP_JUMP_IF_TRUE21
>   6 LOAD_GLOBAL  1 (AssertionError)
>   9 LOAD_CONST   1 ('bar baz')
>  12 CALL_FUNCTION1
>  15 RAISE_VARARGS1
>  18 JUMP_FORWARD 0 (to 21)
> >>   21 LOAD_CONST   0 (None)
>  24 RETURN_VALUE

Impressive. That means that, in 2.7, it's actually equivalent to:

>>> def test3():
... if not foo: raise AssertionError, "bar baz"
...
>>> dis.dis(test3)
  2   0 LOAD_GLOBAL  0 (foo)
  3 POP_JUMP_IF_TRUE18
  6 LOAD_GLOBAL  1 (AssertionError)
  9 LOAD_CONST   1 ('bar baz')
 12 RAISE_VARARGS2
 15 JUMP_FORWARD 0 (to 18)
>>   18 LOAD_CONST   0 (None)
 21 RETURN_VALUE

Although in the 2.7 that I have, the assert statement does actually
*call* AssertionError (ie it constructs an instance and raises it).
What version are you running? Here's mine:

$ python2
Python 2.7.13 (default, Jan 19 2017, 14:48:08)
[GCC 6.3.0 20170118] on linux2
Type "help", "copyright", "credits" or "license" for more information.

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


Re: Assertions

2017-09-21 Thread Steve D'Aprano
On Fri, 22 Sep 2017 02:59 am, Ned Batchelder wrote:

> On 9/21/17 12:29 PM, Tobiah wrote:
>> Are these completely equivalent?
[... assert, versus test and raise AssertionError ...]

> Let's see:
[...]
> Yes, they are completely equivalent, compiling to precisely the same
> bytecode.


That is definitely version-dependent, because I've just tried it and got
different byte-code in Python 2.7.

py> import dis
py> def test1():
... assert foo, "bar baz"
...
py> def test2():
... if not foo: raise AssertionError("bar baz")
...
py>
py> dis.dis(test1)
  2   0 LOAD_GLOBAL  0 (foo)
  3 POP_JUMP_IF_TRUE15
  6 LOAD_GLOBAL  1 (AssertionError)
  9 LOAD_CONST   1 ('bar baz')
 12 RAISE_VARARGS2
>>   15 LOAD_CONST   0 (None)
 18 RETURN_VALUE
py> dis.dis(test2)
  2   0 LOAD_GLOBAL  0 (foo)
  3 POP_JUMP_IF_TRUE21
  6 LOAD_GLOBAL  1 (AssertionError)
  9 LOAD_CONST   1 ('bar baz')
 12 CALL_FUNCTION1
 15 RAISE_VARARGS1
 18 JUMP_FORWARD 0 (to 21)
>>   21 LOAD_CONST   0 (None)
 24 RETURN_VALUE



So I do not believe that we can say that they will always compile to the same
byte-code. There were differences in past versions, there could be differences
again in the future.


I was going to be cheeky and run the same test with -0, giving:

py> dis.dis(test1)
  2   0 LOAD_CONST   0 (None)
  3 RETURN_VALUE

which of course is a big difference between the two, but it turned out that
there can be other byte-code differences.

So no, I don't believe we can say they are *completely* equivalent, since they
could compile to slightly different byte-code with slightly-different
performance characteristics. But I think we can say that *semantically* the two
ought to be the same.




-- 
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.

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


[issue27099] IDLE: turn built-in extensions into regular modules

2017-09-21 Thread Terry J. Reedy

Terry J. Reedy added the comment:

Two of the TODOs already listed, and 2 more found in review, have been done.  
With these additions, I felt IDLE was ready for the 3.6.3rc1 and 3.7.0a1 
releases last Monday.

#31502 Fix problem with deleting user themes and keysets.
#31480 Disable ZzDummy by default, change tests to match.
#31477 Improve rstrip entry in IDLE doc.
#31488 Make non-key options take affect immediately.  (Parenmatch required 
revision for this to happen for its option in existing windows.  The options 
were previously 'baked in' in the __init__ method.)

The following remaining to be done:
Grey-out code context toggle on non-editor windows.
#31547 Write augmented user keysets back to file.
Call each event_add(pseudoevent, sequence) just once.
Re-evaluate some of options.

--

___
Python tracker 

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



Re: Old Man Yells At Cloud

2017-09-21 Thread Rhodri James

On 21/09/17 17:31, Chris Angelico wrote:

For a good while, I was in the same position. But instead of massively
rewriting everything, all I did was to adjust the material to use
Py2/Py3 compatible syntax. Adding parens around your print calls won't
stop it from being Py2-compatible, and it means that the shift to Py3
becomes a lot easier.


It's compatible syntax, but it doesn't half look weird in Py2.

>>> x=2
>>> print("x is", x)
('x is', 2)
>>>

is very unfriendly to young beginners.  We did consider it, but decided 
it was a non-starter; it was less effort to ignore Py3 entirely.


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


[issue31288] IDLE tests: don't modify tkinter.messagebox.

2017-09-21 Thread Terry J. Reedy

Terry J. Reedy added the comment:

Make sure to return result of messagebox calls, as did in #31287, fixed in 
#31502.

--

___
Python tracker 

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



[issue31443] Possibly out of date C extension documentation

2017-09-21 Thread Stefan Krah

Stefan Krah added the comment:

In fact, building _decimal should also fail on Cygwin if this
were still an issue.

--

___
Python tracker 

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



Re: Assertions

2017-09-21 Thread Ned Batchelder

On 9/21/17 12:29 PM, Tobiah wrote:

Are these completely equivalent?

def foo(thing):

 assert(thing > 0), "Thing must be greater than zero"


def foo(thing):

 if not (thing > 0): raise AssertionError("Thing must be greater than 
zero")


Other than the fact that the assertion can be turned off
with -O?



Let's see:

    Python 3.6.2 (default, Jul 17 2017, 07:05:09)
    [GCC 4.2.1 Compatible Apple LLVM 8.1.0 (clang-802.0.42)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    >>> def foo1(thing):
    ...   assert(thing > 0), "Thing must be greater than zero"
    ...
    >>> def foo2(thing):
    ...   if not (thing > 0): raise AssertionError("Thing must be 
greater than zero")

    ...
    >>> import dis
    >>> dis.dis(foo1)
  2   0 LOAD_FAST    0 (thing)
  2 LOAD_CONST   1 (0)
  4 COMPARE_OP   4 (>)
  6 POP_JUMP_IF_TRUE    16
  8 LOAD_GLOBAL  0 (AssertionError)
 10 LOAD_CONST   2 ('Thing must be greater 
than zero')

 12 CALL_FUNCTION    1
 14 RAISE_VARARGS    1
    >>   16 LOAD_CONST   0 (None)
 18 RETURN_VALUE
    >>> dis.dis(foo2)
  2   0 LOAD_FAST    0 (thing)
  2 LOAD_CONST   1 (0)
  4 COMPARE_OP   4 (>)
  6 POP_JUMP_IF_TRUE    16
  8 LOAD_GLOBAL  0 (AssertionError)
 10 LOAD_CONST   2 ('Thing must be greater 
than zero')

 12 CALL_FUNCTION    1
 14 RAISE_VARARGS    1
    >>   16 LOAD_CONST   0 (None)
 18 RETURN_VALUE
    >>>

Yes, they are completely equivalent, compiling to precisely the same 
bytecode.


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


[issue31547] IDLE: Save definitions added to user keysets

2017-09-21 Thread Terry J. Reedy

New submission from Terry J. Reedy:

User keysets are saved as a complete keyset, but users could edit the file and 
delete event-sequence pairs or add an incomplete set.  When a keyset is used, 
default pairs are added for any that are missing, if the pair does not conflict 
with existing pairs.

When extensions were converted to features #27099, 8 new pairs were added to 
the 'complete' set.  All user keyset are missing these pairs.  I expect that 
other pairs will be added in the future.  I propose that augmented keysets 
should be written back to the file, with notice to the user.

Detail: check when read or when used?  All keysets are written, so fix all?

--
assignee: terry.reedy
components: IDLE
messages: 302712
nosy: terry.reedy
priority: normal
severity: normal
stage: needs patch
status: open
title: IDLE: Save definitions added to user keysets
type: enhancement
versions: Python 3.6, Python 3.7

___
Python tracker 

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



[issue31443] Possibly out of date C extension documentation

2017-09-21 Thread Stefan Krah

Stefan Krah added the comment:

Erik, if you are interested in Cygwin, could you please check that xxmodule.c 
builds on Cygwin with the patch?  You need to uncomment
a couple of lines in setup.py to build 'xx'.

--

___
Python tracker 

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



[issue31543] Optimize wrapper descriptors using FASTCALL

2017-09-21 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

It optimizes the same cases as bpo-31410. bpo-31410 removed a half of the 
overhead for wrapper descriptors, Victor's patch removes the remaining half. 
Actually it makes calling the descriptor faster than calling the corresponding 
builtin! But bpo-31410 changes were simple, just few lines, and PR 3685 looks 
much more complex.

Are non-fast wrappers still needed? If the patch replaces the code instead of 
adding it this would decrease its cost. AFAIK the only descriptors that should 
support non-fast calling convention are __new__, __init__ and __call__.

As for practicality, this change should slightly speed up the code that 
directly calls __eq__, __lt__. For example classes decorated with 
total_ordering. Victor, can you provide microbenchmarks with more practical 
code?

--

___
Python tracker 

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



[issue31443] Possibly out of date C extension documentation

2017-09-21 Thread Stefan Krah

Changes by Stefan Krah :


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

___
Python tracker 

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



[issue31543] Optimize wrapper descriptors using FASTCALL

2017-09-21 Thread STINNER Victor

STINNER Victor added the comment:

> I don't know. What's the point of optimizing `array.array.__len__(obj)`? 
> People usually call `len(obj)` for that...

Right, type.method(self) is less than common than self.method().

I looked at the stdlib. I found that the following method are called using 
wrapper descriptors:

* object.__repr__(self)
* object.__getattribute__(self, name)
* _asyncio.Future.__del__(self)
* int.__str__(obj)
* etc.

But it seems like such calls are rare compared to other kinds of function calls.

--

By the way, _PyMethodDescr_FastCallKeywords() is only called from 
call_function() in Python/ceval.c. It's not used in Objects/call.c. Maybe we 
should use it there as well? It seems like this is a question about tracing. 
But maybe we can copy/paste the code from call_function()?

--

___
Python tracker 

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



iPython ? magic

2017-09-21 Thread Steve D'Aprano
In the iPython interactive interpreter, obj? prints information about the given
object. For example:


In [11]: None?
Type:   NoneType
Base Class: 
String Form:None
Namespace:  Python builtin
Docstring:  


Does anyone know that the Namespace field is supposed to show? I can't get it to
display anything except either "Python builtin" or "Interactive".




-- 
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.

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


Re: errors with json.loads

2017-09-21 Thread Ned Batchelder

On 9/21/17 12:18 PM, john polo wrote:

Bill,
Thanks for the reply. I wasn't sure how to get Python 2 through the 
cmd or IPython, so I went through ArcGIS, but it's mostly the same 
result:


>>> file = open('books.json','r')
>>> text = file.read()
>>> text = json.loads(text)


After the file.read() line, put this:  print(repr(text))  or 
print(ascii(text)) if you are on Python 3.  Show us that output. That 
will make clear what is wrong with the data.


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


Re: Old Man Yells At Cloud

2017-09-21 Thread Chris Angelico
On Fri, Sep 22, 2017 at 1:59 AM, Rhodri James  wrote:
> On 21/09/17 16:12, Steve D'Aprano wrote:
>>
>> On Thu, 21 Sep 2017 08:19 pm, Rhodri James wrote:
>>
>>> (That's basically my gripe against print becoming a function in Python3.
>>>It makes a lot of sense as has already been pointed out, but it breaks
>>> every beginners tutorial.)
>>
>> Nobody made that decision lightly. It wasn't a spur of the moment
>> decision,
>> Guido didn't wake up one morning and say "Hey, how about we break a whole
>> lot
>> of the Python ecosystem for giggles!" You can't fix mistakes without
>> breaking
>> things that depend on those mistakes.
>
>
> Oh, I don't doubt it, and Python3 is the better for it.  It's just that my
> major use for Python at the time was teaching a summer course for 12-15 year
> olds, and switching to Python3 would have involved rewriting almost every
> worksheet we had.  So we didn't.
>
> (Looking at the worksheet sources on Github, the course still hasn't made
> the switch!)

For a good while, I was in the same position. But instead of massively
rewriting everything, all I did was to adjust the material to use
Py2/Py3 compatible syntax. Adding parens around your print calls won't
stop it from being Py2-compatible, and it means that the shift to Py3
becomes a lot easier. A handful of other minor changes here and there
(using the explicit // operator when floor division was important, or
ensuring that obsolete syntax wasn't used), and the course was solidly
in the 2-3 compatibility range. No cost to Py2 compatibility, and the
work could be done progressively.

Teaching people to put parens around their prints won't hurt them, and
might help them. It wasn't hard for us, because all our course
material is online; if you're working with printed worksheets, you may
end up with two versions going around (which would cause confusion -
"why does this have brackets and that not?"), so it could just be left
until there's edits being made for other reasons. Still, it can be on
the list of "if you're making changes, do this", like fixing typos or
spelling errors.

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


Assertions

2017-09-21 Thread Tobiah
Are these completely equivalent?

def foo(thing):

assert(thing > 0), "Thing must be greater than zero"


def foo(thing):

if not (thing > 0): raise AssertionError("Thing must be greater than 
zero")


Other than the fact that the assertion can be turned off
with -O?


Thanks,


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


New security-annou...@python.org mailing list

2017-09-21 Thread Barry Warsaw
I’m happy to announce the availability of a new mailing list, with the mission 
of providing security announcements to the Python community from the Python 
Security Response Team (PSRT):

security-annou...@python.org

You can sign up in the usual Mailman way:

https://mail.python.org/mailman/listinfo/security-announce

This joins our suite of security related forums.  As always, if you believe 
you’ve found a security issue in Python, you should contact the PSRT directly 
and securely via:

secur...@python.org

For more information on how you can contact us, see:

https://www.python.org/news/security/

We also have a public security-focused discussion mailing list that you can 
subscribe and contribute to.

security-...@python.org
https://mail.python.org/mailman/listinfo/security-sig

Please don’t report security vulnerabilities here, since this is a publicly 
archived mailing list.  We welcome you to collaborate here to help make Python 
and its ecosystem even more secure than it already is.

Once a security vulnerability is identified and fixed, it becomes public 
knowledge.  Generally, these are captured in a ReadTheDocs site for posterity:

https://python-security.readthedocs.io/

This new security-announce mailing list fills a void — one-way communication 
about security related matters from the PSRT back to the community.  This is an 
area that we’ve not done a great job at, frankly, and this new announcement 
list is intended to improve that situation.  The PSRT will use this low 
traffic, high value forum as the primary way the PSRT will communicate security 
issues of high importance back to the wider Python community.  All follow-ups 
to postings to this list are redirected to the security-sig mailing list.

Cheers,
-Barry (on behalf of the PSRT)



signature.asc
Description: Message signed with OpenPGP
-- 
https://mail.python.org/mailman/listinfo/python-announce-list

Support the Python Software Foundation:
http://www.python.org/psf/donations/


[issue31546] PyOS_InputHook is not called when waiting for input() in Windows

2017-09-21 Thread Steve Dower

Steve Dower added the comment:

(Belongs inside Parser/myreadline.c in the _PyOS_WindowsConsoleReadline 
function)

--

___
Python tracker 

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



[issue31493] IDLE cond context: fix code update and font update timers

2017-09-21 Thread Terry J. Reedy

Terry J. Reedy added the comment:

The underlying issue is trying to coordinate two somewhat independent object 
systems (Python and Tcl).  I don't know why the after loops were (apparently) 
stopped before #27099 and not after.  The only difference I know of is the 
dropping of the reference to CodeContext instances in .unload_extensions, 
called from ._close.  CodeContext did not have a .close method.

I tried the first thing I thought might work and it did, so I stopped.  I don't 
know why unbinding the toggle function was enough.  I expect that we will 
eventually review ._close.  It should help when the menu and editor are 
separated a bit.

--

___
Python tracker 

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



Re: Re: errors with json.loads

2017-09-21 Thread john polo

On 9/21/2017 4:24 AM, Thomas Jollans wrote:


It looks to me like the root cause of the problem was that they copied
the code from a web page, and the web page contained invalid JSON.


Thank you, Thomas.


John

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


[issue31539] asyncio.sleep may sleep less time then it should

2017-09-21 Thread Mikhail Gerasimov

Mikhail Gerasimov added the comment:

STINNER Victor, thanks for explanation!

I don't know if this issue has practical disadvantages, but such behavior seems 
to be confusing, especially, since it can be reproduced with event_loop.time() 
and asyncio doc says nothing about resolution -
https://docs.python.org/3/library/asyncio-eventloop.html#delayed-calls

Do you think this issue should be closed?
Should I make PR to add info about clock's resolution to asyncio documentation?

--

___
Python tracker 

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



Re: Re: errors with json.loads

2017-09-21 Thread john polo

On 9/20/2017 6:40 PM, Dennis Lee Bieber wrote:

On Wed, 20 Sep 2017 17:13:41 -0500, john polo 
declaimed the following:



and the example code for reading the file is:


file = open('books.json','r')

What encoding is the file? I did a cut from your post into a
file, and the contents (Python 2.7) failed with

Dennis,
I typed it into notepad++ and saved as .json. On the bottom of the 
notepad++ window it says:

Windows (CR LF) UTF-8

I think that answers your question?

Thanks,
John

--
"Ask a man to be quiet,
and he'll be silent for a moment.
Feed a man to a red dragon
and he'll be silent for a lifetime."
-Anne Isabella Thackeray Ritchie

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


[issue31546] PyOS_InputHook is not called when waiting for input() in Windows

2017-09-21 Thread Steve Dower

Steve Dower added the comment:

You're right, we're missing this section of code:

if (PyOS_InputHook != NULL)
(void)(PyOS_InputHook)();

Since we just call it and ignore anything it does, it should be safe enough to 
add it immediately before the ReadConsoleW call (inside the loop).

--

___
Python tracker 

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



[issue31529] IDLE: Add docstrings and tests for editor.py reload functions

2017-09-21 Thread Terry J. Reedy

Terry J. Reedy added the comment:

A good start, and big enough as it is, for the next big revision project ;-).

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



Re: Re: errors with json.loads

2017-09-21 Thread john polo

On 9/20/2017 5:58 PM, Bill wrote:

Interesting problem, John.

I have probably even less experience with json than you do, so I'm 
taking this as an opportunity to learn with you.


Suggestions:

1. Try your example with Python 2 rather than Python 3.

Bill,
Thanks for the reply. I wasn't sure how to get Python 2 through the cmd 
or IPython, so I went through ArcGIS, but it's mostly the same result:


>>> file = open('books.json','r')
>>> text = file.read()
>>> text = json.loads(text)
Runtime error
Traceback (most recent call last):
  File "", line 1, in 
NameError: name 'json' is not defined
>>> import json   #whoops, forget to do that first in this go 'round.
>>> text = json.loads(text)
Runtime error
Traceback (most recent call last):
  File "", line 1, in 
  File "C:\Python27\ArcGIS10.4\Lib\json\__init__.py", line 338, in loads
    return _default_decoder.decode(s)
  File "C:\Python27\ArcGIS10.4\Lib\json\decoder.py", line 366, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "C:\Python27\ArcGIS10.4\Lib\json\decoder.py", line 382, in 
raw_decode

    obj, end = self.scan_once(s, idx)
ValueError: Expecting : delimiter: line 5 column 50 (char 161)
>>>

2. Take your file and make it into a string literal in your program, 
and try calling json.loads with that as an argument. 

I am not sure I follow what you meant, but this was what I did:
In [26]: file2 = open('books.txt')

In [27]: text2 = file2.read()

In [28]: text2 = json.loads(text2)
---
JSONDecodeError   Traceback (most recent call last)
 in ()
> 1 text2 = json.loads(text2)

c:\users\jpolo\appdata\local\programs\python\python36\lib\json\__init__.py 
in lo
ads(s, encoding, cls, object_hook, parse_float, parse_int, 
parse_constant, objec

t_pairs_hook, **kw)
    352 parse_int is None and parse_float is None and
    353 parse_constant is None and object_pairs_hook is 
None and not

 kw):
--> 354 return _default_decoder.decode(s)
    355 if cls is None:
    356 cls = JSONDecoder

c:\users\jpolo\appdata\local\programs\python\python36\lib\json\decoder.py 
in dec

ode(self, s, _w)
    337
    338 """
--> 339 obj, end = self.raw_decode(s, idx=_w(s, 0).end())
    340 end = _w(s, end).end()
    341 if end != len(s):

c:\users\jpolo\appdata\local\programs\python\python36\lib\json\decoder.py 
in raw

_decode(self, s, idx)
    353 """
    354 try:
--> 355 obj, end = self.scan_once(s, idx)
    356 except StopIteration as err:
    357 raise JSONDecodeError("Expecting value", s, 
err.value) from

None

JSONDecodeError: Expecting ':' delimiter: line 5 column 50 (char 161)


best,
John

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


Re: Re: errors with json.loads

2017-09-21 Thread john polo

On 9/20/2017 5:56 PM, John Gordon wrote:

In  john polo 
 writes:


JSONDecodeError: Expecting ':' delimiter: line 5 column 50 (char 161)
?json.loads says that the method is for deserializing "s", with "s"
being a string, bytes, or bytearray.
In [24]: type(text)
Out[24]: str
So "text" seems to be a string. Why does json.loads return an error?

Because, although text is the right type, it does not contain a
valid json string.


Thank you for the reply, John. I am not familiar with how to check 
validity for json. I typed the example into notepad++ and saved as .json 
and didn't take any further steps after that. I'll look into that.



John

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


[issue31546] PyOS_InputHook is not called when waiting for input() in Windows

2017-09-21 Thread Lam Yuen Hei

Lam Yuen Hei added the comment:

Attach python 3.6 call stack of the test script

--
Added file: https://bugs.python.org/file47162/py36_call_stack.png

___
Python tracker 

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



[issue31546] PyOS_InputHook is not called when waiting for input() in Windows

2017-09-21 Thread Lam Yuen Hei

Lam Yuen Hei added the comment:

Attach python 3.5 call stack of the test script

--
Added file: https://bugs.python.org/file47161/py35_call_stack.png

___
Python tracker 

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



[issue31545] Fixing documentation for timedelta.

2017-09-21 Thread Utkarsh Upadhyay

Changes by Utkarsh Upadhyay :


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

___
Python tracker 

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



[issue31546] PyOS_InputHook is not called when waiting for input() in Windows

2017-09-21 Thread Lam Yuen Hei

New submission from Lam Yuen Hei:

Since python 3.6, PyOS_InputHook is not called when waiting for IO in Windows.

This causes issues with GUI framework like tkinter that relys on PyOS_InputHook 
to handle user interaction.

I attached a test script. When running the script with python 3.5, the tkinter 
window will show up properly. But if you run the script with python 3.6, the 
tkinter window will be frozen. 

I believe the issue is introduced in commit 3929499. In commit 3929499, 
_PyOS_WindowsConsoleReadline is added as the new Windows implementation of 
PyOS_StdioReadline. Originally, PyOS_StdioReadline calls my_fgets to read 
input, and my_fgets will call PyOS_InputHook before the calling the real fgets. 
However, _PyOS_WindowsConsoleReadline calls ReadConsoleW instead of my_fgets to 
read input, and PyOS_InputHook is never called.

The bug is first reported in matplotlib.
https://github.com/matplotlib/matplotlib/issues/9206#issuecomment-331192016

--
components: Windows
files: test_tk.py
messages: 302701
nosy: paul.moore, steve.dower, tim.golden, yhlam, zach.ware
priority: normal
severity: normal
status: open
title: PyOS_InputHook is not called when waiting for input() in Windows
type: behavior
versions: Python 3.6, Python 3.7
Added file: https://bugs.python.org/file47160/test_tk.py

___
Python tracker 

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



[issue30302] Improve .__repr__ implementation for datetime.timedelta

2017-09-21 Thread Utkarsh Upadhyay

Changes by Utkarsh Upadhyay :


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

___
Python tracker 

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



Re: Old Man Yells At Cloud

2017-09-21 Thread Rhodri James

On 21/09/17 16:12, Steve D'Aprano wrote:

On Thu, 21 Sep 2017 08:19 pm, Rhodri James wrote:


(That's basically my gripe against print becoming a function in Python3.
   It makes a lot of sense as has already been pointed out, but it breaks
every beginners tutorial.)

Nobody made that decision lightly. It wasn't a spur of the moment decision,
Guido didn't wake up one morning and say "Hey, how about we break a whole lot
of the Python ecosystem for giggles!" You can't fix mistakes without breaking
things that depend on those mistakes.


Oh, I don't doubt it, and Python3 is the better for it.  It's just that 
my major use for Python at the time was teaching a summer course for 
12-15 year olds, and switching to Python3 would have involved rewriting 
almost every worksheet we had.  So we didn't.


(Looking at the worksheet sources on Github, the course still hasn't 
made the switch!)


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


[issue31545] Fixing documentation for timedelta.

2017-09-21 Thread Utkarsh Upadhyay

New submission from Utkarsh Upadhyay:

There are some instances in the documentation of datetime where the repr of 
timedelta is mentioned, which was changed in bpo-30302.


Am making a PR shortly to address them.

--
assignee: docs@python
components: Documentation
messages: 302700
nosy: docs@python, musically_ut
priority: normal
severity: normal
status: open
title: Fixing documentation for timedelta.
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



[issue31539] asyncio.sleep may sleep less time then it should

2017-09-21 Thread STINNER Victor

STINNER Victor added the comment:

Clocks is a very complex topic, especially when you care of portability. See my 
PEP 418.

asyncio uses time.monotonic() clock to not be impacted when the system clock 
("wall clock") is updated by the administrator or automatically by NTP.

On Windows, time.monotonic() is implemented with GetTickCount64() which has a 
bad resolution: around 15 ms. The exact resolution depends on the hardware.

See my PEP 418 which added time.monotonic() for Python 3.3 for much more 
information:
https://www.python.org/dev/peps/pep-0418/#monotonic-clocks

To get the clock resolution, use:

>>> import time; print(time.get_clock_info('monotonic'))

Example on Linux:

>>> import time; print(time.get_clock_info('monotonic'))
namespace(adjustable=False, implementation='clock_gettime(CLOCK_MONOTONIC)', 
monotonic=True, resolution=1e-09)

Well, the announced resolution is 1 nanosecond, but in practice it's more 
around 500 ns. At least, it's better than 15 ms :-)

--

asyncio rounds timings using the clock resolution, 
time.get_clock_info('monotonic').resolution. Search for self._clock_resolution 
in Lib/asyncio/base_events.py.

asyncio is not designed for real time.

--
nosy: +haypo

___
Python tracker 

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



[issue31539] asyncio.sleep may sleep less time then it should

2017-09-21 Thread Antoine Pitrou

Antoine Pitrou added the comment:

AFAIR the Windows clock has a 15ms granularity, so I'm not really surprised. In 
other words, I don't think `asyncio.sleep` sleeps less than expected, but that 
it's the imprecision of time.time() which gives you that impression.

What happens if you replace `time.time()` with `time.perf_counter()` in the 
code above?

--
nosy: +pitrou

___
Python tracker 

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



[issue31543] Optimize wrapper descriptors using FASTCALL

2017-09-21 Thread Antoine Pitrou

Antoine Pitrou added the comment:

> First I would like to know if it's worth it

I don't know. What's the point of optimizing `array.array.__len__(obj)`? People 
usually call `len(obj)` for that...

--
nosy: +pitrou

___
Python tracker 

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



New security-annou...@python.org mailing list

2017-09-21 Thread Barry Warsaw
I’m happy to announce the availability of a new mailing list, with the mission 
of providing security announcements to the Python community from the Python 
Security Response Team (PSRT):

security-annou...@python.org

You can sign up in the usual Mailman way:

https://mail.python.org/mailman/listinfo/security-announce

This joins our suite of security related forums.  As always, if you believe 
you’ve found a security issue in Python, you should contact the PSRT directly 
and securely via:

secur...@python.org

For more information on how you can contact us, see:

https://www.python.org/news/security/

We also have a public security-focused discussion mailing list that you can 
subscribe and contribute to.

security-...@python.org
https://mail.python.org/mailman/listinfo/security-sig

Please don’t report security vulnerabilities here, since this is a publicly 
archived mailing list.  We welcome you to collaborate here to help make Python 
and its ecosystem even more secure than it already is.

Once a security vulnerability is identified and fixed, it becomes public 
knowledge.  Generally, these are captured in a ReadTheDocs site for posterity:

https://python-security.readthedocs.io/

This new security-announce mailing list fills a void — one-way communication 
about security related matters from the PSRT back to the community.  This is an 
area that we’ve not done a great job at, frankly, and this new announcement 
list is intended to improve that situation.  The PSRT will use this low 
traffic, high value forum as the primary way the PSRT will communicate security 
issues of high importance back to the wider Python community.  All follow-ups 
to postings to this list are redirected to the security-sig mailing list.

Cheers,
-Barry (on behalf of the PSRT)



signature.asc
Description: Message signed with OpenPGP
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue31544] gettext.Catalog title is not flagged as a class

2017-09-21 Thread linkid

New submission from linkid:

In the ``gettext`` documentatino, in the title about the ``Catalog`` 
constructor, ``Catalog`` is not flagged as a class.

--
assignee: docs@python
components: Documentation
messages: 302696
nosy: docs@python, linkid
priority: normal
severity: normal
status: open
title: gettext.Catalog title is not flagged as a class
type: enhancement
versions: Python 2.7, Python 3.3, Python 3.4, Python 3.5, Python 3.6, Python 3.7

___
Python tracker 

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



[issue31500] IDLE: Tiny font on HiDPI display

2017-09-21 Thread Terry J. Reedy

Terry J. Reedy added the comment:


New changeset 0c4997f1919d8583353b12537a63dcbe7b9d280f by Terry Jan Reedy in 
branch '3.6':
[3.6] bpo-31500: IDLE: Scale default fonts on HiDPI displays. (GH-3639) (#3686)
https://github.com/python/cpython/commit/0c4997f1919d8583353b12537a63dcbe7b9d280f


--

___
Python tracker 

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



Re: Old Man Yells At Cloud

2017-09-21 Thread Steve D'Aprano
On Thu, 21 Sep 2017 08:19 pm, Rhodri James wrote:

> (That's basically my gripe against print becoming a function in Python3.
>   It makes a lot of sense as has already been pointed out, but it breaks
> every beginners tutorial.)

Nobody made that decision lightly. It wasn't a spur of the moment decision,
Guido didn't wake up one morning and say "Hey, how about we break a whole lot
of the Python ecosystem for giggles!" You can't fix mistakes without breaking
things that depend on those mistakes.

That's why a whole lot of backward-incompatible changes were queued up to 
all happen at once, to minimize the disruption:

- clean up the naming of the standard library;

- make strings proper text rather than bytes;

- fix print and exec;

- get rid of the old, error-prone "except Error, name" syntax;

- get rid of dangerous input and rename raw_input;

- make map and zip iterators;

- get rid of redundant range and rename xrange;

- make dict.keys, items and values views, instead of having three 
  sets of methods (lists, views and iterators);

- get rid of the confusing bytes.encode and str.decode methods;

and any others I missed.

If you think the transition from 2 to 3 was painful, you should consider how it
would have been to introduce all those backward incompatible changes in dribs
and drabs over 2.4, 2.5, 2.6, 2.7 and beyond.

The alternative would be to *not* remove the old versions, and just keep all the
old cruft and obsolete code hanging around forever.

And remember that the Python core developers feel your pain too. They had to
migrate a large code base (the Python std library) from 2 to 3. They had to
write the 2to3 translator. And they have to maintain two independent code
bases, 2 and 3, in parallel, for a decade or more, and put up with thousands of
internet haters going on and on and on and on about "Python 3 is destroying
Python", year after year after year.

They were willing to do all this because they were looking at the long-term
health of the Python language, not just the immediate situation.



-- 
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.

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


Re: errors with json.loads

2017-09-21 Thread Ned Batchelder

On 9/20/17 10:35 PM, Bill wrote:

Ned Batchelder wrote:


On 9/20/17 8:22 PM, Bill wrote:
Apparenty an \xa0 byte corresponds to a "non-breaking space". What 
sort of white space characters are allowed in a json file ( tabs and 
newlines?)?  Just curious. 


These things can be looked up.  From RFC 7159 
(https://tools.ietf.org/html/rfc7159):




Thank you.  So what is most likely the root cause of the original 
poster's problem (assuming he typed out the text with a text editor)?


I can only assume that the actual data being read is different than the 
data they put into the message here.


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


[issue27867] various issues due to misuse of PySlice_GetIndicesEx

2017-09-21 Thread Henk-Jaap Wagenaar

Henk-Jaap Wagenaar added the comment:

@serhiy.storchaka: review done.

--
nosy: +Henk-Jaap Wagenaar

___
Python tracker 

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



The Signature Module for PySide2

2017-09-21 Thread Christian Tismer
Hi friends,

there is the new signature module for PySide2.
It adds the __signature__ attribute to all PySide2
functions and constructors.

Example usage:

>>> PySide2.QtWidgets.QGraphicsAnchorLayout.addAnchors.__signature__
>>> PySide2.QtWidgets.QGraphicsAnchorLayout.__signature__

will print all annotations, defaults and return values.

The feature supports Python 2.7 and Python 3.4 and up.
See further info at

https://bugreports.qt.io/browse/PYSIDE-510


https://github.com/pyside/pyside2-setup/blob/5.6/sources/shiboken2/libshiboken/signature.cpp


https://github.com/pyside/pyside2-setup/tree/5.6/sources/pyside2/PySide2/support/signature

Cheers -- Chris

-- 
Christian Tismer :^)   tis...@stackless.com
Software Consulting  : http://www.stackless.com/
Karl-Liebknecht-Str. 121 : https://github.com/PySide
14482 Potsdam: GPG key -> 0xFB7BEE0E
phone +49 173 24 18 776  fax +49 (30) 700143-0023



signature.asc
Description: OpenPGP digital signature
-- 
https://mail.python.org/mailman/listinfo/python-announce-list

Support the Python Software Foundation:
http://www.python.org/psf/donations/


PyDev 6.0.0 Released

2017-09-21 Thread Fabio Zadrozny
PyDev 6.0.0 Release Highlights

   -

   *Important* PyDev now requires Java 8 and Eclipse 4.6 (Neon) onwards.
   - PyDev 5.2.0 is the last release supporting Eclipse 4.5 (Mars).
   -

   *Interpreter configuration*
   - The *list of packages* installed in the interpreter is shown in the
  IDE (supports either *pip* or *conda*).
  - It's now possible to *install/uninstall* packages using either *pip*
   or *conda* directly from the IDE.
  - Provides a way to *load variables* if interpreter is from a *conda
  environment* (Load conda env vars before run configuration).
  - A default string substitution variable named *PY* is now created
  with the major and minor version of the created interpreter.
  - It's now possible to configure a project to always use a grammar
  compatible with the interpreter version (default for new projects --
  *#PyDev-846*).
   -

   *Editor*
   - *Subword* navigation is now available (and enabled by default -- can
  be customized at *PyDev > Editor*).
  - Changed default config for minimap (smaller and not showing
  elements -- can be customized at *PyDev > Editor > Overview Ruler
  Minimap*).
  - Code completion no longer active in comments in last line of editor
  (*#PyDev-762*).
   -

   *Debugger*
   - Fix find_module signature (patch by James Blackburn).
  - Fix qt_loader to support *PEP 302* correctly.
  - Fix in matplotlib_options from ipython (*#PyDev-779*).
  - When show all uppercase references is used as a filter, only digits
  shouldn't be filtered out in variables view (#PyDev-794).
   -

   *PyLint*
   - Added setting to search *PyLint* installed in interpreter (*#PyDev-811*
  ).
   -

   *Unittest*
   - It's possible to edit a run configuration from dialog to select tests
  to run (Ctrl+F9) (patch by *Robert Gomulka*).
  - Test(s) name is shown in the run configuration (patch by *Robert
  Gomulka* -- *#PyDev-840*).
   -

   *isort integration*
   - The modules that are known to be third party or system modules in the
  PyDev configuration are passed to *isort*.
  - Proper support for *isort:skip* and *isort:skip_file*.
  - Internal isort caches properly being cleared between invocations
  (fix for case where changes to config were not reflected in isort).
   -

   *Others*
   - Fix to properly interrupt infinite loop in the Interactive Console (
  *#PyDev-816*).
  - Fix issue where user could do a drag n drop in system libs which
  could put an entry below another entry, which actually removed
it from the
  config (*#PyDev-821*).
  - Fix where *runfile* was not available on *interactive debugger* when
  python-future is installed (*#PyDev-845*).
  - Fix NullPointerException on code-completion.
  - mutagen added to forced builtins by default (*#PyDev-819*).

What is PyDev?

PyDev is an open-source Python IDE on top of Eclipse for Python, Jython and
IronPython development.

It comes with goodies such as code completion, syntax highlighting, syntax
analysis, code analysis, refactor, debug, interactive console, etc.

Details on PyDev: http://pydev.org
Details on its development: http://pydev.blogspot.com
What is LiClipse?

LiClipse is a PyDev standalone with goodies such as support for Multiple
cursors, theming, TextMate bundles and a number of other languages such as
Django Templates, Jinja2, Kivy Language, Mako Templates, Html, Javascript,
etc.

It's also a commercial counterpart which helps supporting the development
of PyDev.

Details on LiClipse: http://www.liclipse.com/

Cheers,

--
Fabio Zadrozny
--

Software Developer

LiClipse
http://www.liclipse.com

PyDev - Python Development Environment for Eclipse
http://pydev.org
http://pydev.blogspot.com

PyVmMonitor - Python Profiler
http://www.pyvmmonitor.com/
-- 
https://mail.python.org/mailman/listinfo/python-announce-list

Support the Python Software Foundation:
http://www.python.org/psf/donations/


[issue31539] asyncio.sleep may sleep less time then it should

2017-09-21 Thread R. David Murray

R. David Murray added the comment:

I can't reproduce this on a linux VM with 3.7 tip.  I don't currently have a 
windows instance to test against.

--
nosy: +r.david.murray

___
Python tracker 

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



[issue31500] IDLE: Tiny font on HiDPI display

2017-09-21 Thread Terry J. Reedy

Changes by Terry J. Reedy :


--
pull_requests: +3675

___
Python tracker 

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



PyDev 6.0.0 Released

2017-09-21 Thread Fabio Zadrozny
PyDev 6.0.0 Release Highlights

   -

   *Important* PyDev now requires Java 8 and Eclipse 4.6 (Neon) onwards.
   - PyDev 5.2.0 is the last release supporting Eclipse 4.5 (Mars).
   -

   *Interpreter configuration*
   - The *list of packages* installed in the interpreter is shown in the
  IDE (supports either *pip* or *conda*).
  - It's now possible to *install/uninstall* packages using either *pip*
   or *conda* directly from the IDE.
  - Provides a way to *load variables* if interpreter is from a *conda
  environment* (Load conda env vars before run configuration).
  - A default string substitution variable named *PY* is now created
  with the major and minor version of the created interpreter.
  - It's now possible to configure a project to always use a grammar
  compatible with the interpreter version (default for new projects --
  *#PyDev-846*).
   -

   *Editor*
   - *Subword* navigation is now available (and enabled by default -- can
  be customized at *PyDev > Editor*).
  - Changed default config for minimap (smaller and not showing
  elements -- can be customized at *PyDev > Editor > Overview Ruler
  Minimap*).
  - Code completion no longer active in comments in last line of editor
  (*#PyDev-762*).
   -

   *Debugger*
   - Fix find_module signature (patch by James Blackburn).
  - Fix qt_loader to support *PEP 302* correctly.
  - Fix in matplotlib_options from ipython (*#PyDev-779*).
  - When show all uppercase references is used as a filter, only digits
  shouldn't be filtered out in variables view (#PyDev-794).
   -

   *PyLint*
   - Added setting to search *PyLint* installed in interpreter (*#PyDev-811*
  ).
   -

   *Unittest*
   - It's possible to edit a run configuration from dialog to select tests
  to run (Ctrl+F9) (patch by *Robert Gomulka*).
  - Test(s) name is shown in the run configuration (patch by *Robert
  Gomulka* -- *#PyDev-840*).
   -

   *isort integration*
   - The modules that are known to be third party or system modules in the
  PyDev configuration are passed to *isort*.
  - Proper support for *isort:skip* and *isort:skip_file*.
  - Internal isort caches properly being cleared between invocations
  (fix for case where changes to config were not reflected in isort).
   -

   *Others*
   - Fix to properly interrupt infinite loop in the Interactive Console (
  *#PyDev-816*).
  - Fix issue where user could do a drag n drop in system libs which
  could put an entry below another entry, which actually removed
it from the
  config (*#PyDev-821*).
  - Fix where *runfile* was not available on *interactive debugger* when
  python-future is installed (*#PyDev-845*).
  - Fix NullPointerException on code-completion.
  - mutagen added to forced builtins by default (*#PyDev-819*).

What is PyDev?

PyDev is an open-source Python IDE on top of Eclipse for Python, Jython and
IronPython development.

It comes with goodies such as code completion, syntax highlighting, syntax
analysis, code analysis, refactor, debug, interactive console, etc.

Details on PyDev: http://pydev.org
Details on its development: http://pydev.blogspot.com
What is LiClipse?

LiClipse is a PyDev standalone with goodies such as support for Multiple
cursors, theming, TextMate bundles and a number of other languages such as
Django Templates, Jinja2, Kivy Language, Mako Templates, Html, Javascript,
etc.

It's also a commercial counterpart which helps supporting the development
of PyDev.

Details on LiClipse: http://www.liclipse.com/

Cheers,

--
Fabio Zadrozny
--

Software Developer

LiClipse
http://www.liclipse.com

PyDev - Python Development Environment for Eclipse
http://pydev.org
http://pydev.blogspot.com

PyVmMonitor - Python Profiler
http://www.pyvmmonitor.com/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Easy way to get a list of tuples.

2017-09-21 Thread Thomas Jollans
On 2017-09-21 12:38, Sayth Renshaw wrote:
> Thanks Thomas yes you are right with append. I have tried it but just can't 
> get it yet as append takes only 1 argument and I wish to give it 3.
> 
> I am really having trouble creating the groups of 3, since I am getting one 
> consistent stream.

I suggest you have a very close look at my example code :-)



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


[issue31543] Optimize wrapper descriptors using FASTCALL

2017-09-21 Thread STINNER Victor

Changes by STINNER Victor :


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

___
Python tracker 

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



[issue31543] Optimize wrapper descriptors using FASTCALL

2017-09-21 Thread STINNER Victor

New submission from STINNER Victor:

Attached pull request adds a fastpath for wrapper descriptors to use the 
FASTCALL calling convention. It's a follow up of bpo-31410 and all my work on 
FASTCALL during Python 3.6 and 3.7 development cycles.

Microbenchmark:

./python -m perf timeit -s 'import array; obj=array.array("b"); 
wrap=array.array.__len__' 'wrap(obj)'

Result:

haypo@selma$ ./python -m perf compare_to ref.json patch.json 
Mean +- std dev: [ref] 59.2 ns +- 0.6 ns -> [patch] 28.2 ns +- 0.9 ns: 2.10x 
faster (-52%)

It removes 31 nanoseconds on such very fast C function, array_length().

Attached PR is still a work-in-progress. First I would like to know if it's 
worth it because working on polishing the actual code.

--
components: Interpreter Core
messages: 302692
nosy: haypo, inada.naoki, serhiy.storchaka
priority: normal
severity: normal
status: open
title: Optimize wrapper descriptors using FASTCALL
type: performance
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



[issue27541] Repr of collection's subclasses

2017-09-21 Thread STINNER Victor

STINNER Victor added the comment:

> Because reprs of Python implementations of collection use a bare __name__.

Ah, maybe this module should be updated to use qualified name with the name in 
repr()?

> __qualname__ is used only in combination with __module__.

I was thinking at module.qualname, right.

--

___
Python tracker 

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



[issue27541] Repr of collection's subclasses

2017-09-21 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Because reprs of Python implementations of collection use a bare __name__.

__qualname__ is used only in combination with __module__. Using a single 
__qualname__ can be confused: foo.bar looks as a name bar in the module foo. 
Whether in reprs and error messages either full qualified name is used 
("{cls.__module__}.{__qualname__}") or a bare __name__. If a displayed name 
contains a dot it is always a full qualified name.

--

___
Python tracker 

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



Re: Easy way to get a list of tuples.

2017-09-21 Thread Mark Lawrence via Python-list

On 21/09/2017 11:18, Sayth Renshaw wrote:

Hi

I have been toying with json and I particular area where I cannot get the 
desired result a list of tuples as my return. The json from the API is way to 
long but I don't think it will matter.

.. hitting url
data = r.json()

for item in data["RaceDay"]['Meetings'][0]['Races']:
 raceDetails = item['RacingFormGuide']['Event']['Race']
 print(raceDetails)

This returns

{'Number': 1, 'NumberDisplay': '01', 'Distance': 1000, 'DistanceDisplay': '1000 
METRES', 'Name': 'CLASS 3 HANDICAP', 'NameForm': 'HIGHWAY-C3'}
{'Number': 2, 'NumberDisplay': '02', 'Distance': 1600, 'DistanceDisplay': '1600 
METRES', 'Name': 'BM 90 HANDICAP', 'NameForm': 'BM90'}
{'Number': 3, 'NumberDisplay': '03', 'Distance': 1100, 'DistanceDisplay': '1100 
METRES', 'Name': 'HERITAGE STAKES', 'NameForm': 'HERITAGE'}
{'Number': 4, 'NumberDisplay': '04', 'Distance': 1400, 'DistanceDisplay': '1400 
METRES', 'Name': 'BILL RITCHIE HANDICAP', 'NameForm': 'RITCHIE'}
{'Number': 5, 'NumberDisplay': '05', 'Distance': 1400, 'DistanceDisplay': '1400 
METRES', 'Name': 'TEA ROSE STAKES', 'NameForm': 'TEA ROSE'}
{'Number': 6, 'NumberDisplay': '06', 'Distance': 1600, 'DistanceDisplay': '1600 
METRES', 'Name': 'GEORGE MAIN STAKES', 'NameForm': 'GEO MAIN'}
{'Number': 7, 'NumberDisplay': '07', 'Distance': 1100, 'DistanceDisplay': '1100 
METRES', 'Name': 'THE SHORTS', 'NameForm': 'THE SHORTS'}
{'Number': 8, 'NumberDisplay': '08', 'Distance': 2000, 'DistanceDisplay': '2000 
METRES', 'Name': 'KINGTON TOWN STAKES', 'NameForm': 'KING TOWN'}
{'Number': 9, 'NumberDisplay': '09', 'Distance': 1200, 'DistanceDisplay': '1200 
METRES', 'Name': 'BM 84 HANDICAP', 'NameForm': 'BM84'}

My goal is to select a few elements and create a list of 3 element tuples
like this
[('CLASS 3 HANDICAP', 1, 1000), ('BM 90 HANDICAP', 2, 1600), ('HERITAGE 
STAKES', 3, 1100), ('BILL RITCHIE HANDICAP', 4, 1400), ('TEA ROSE STAKES', 5, 
1400), ('GEORGE MAIN STAKES', 6, 1600), ('THE SHORTS', 7, 1100), ('KINGTON TOWN 
STAKES', 8, 2000), ('BM 84 HANDICAP', 9, 1200)]

I get close creating a list of elements but each attempt I try to create the 
list of tuples fails.

This is my closest code

data = r.json()

raceData = []

for item in data["RaceDay"]['Meetings'][0]['Races']:
 raceDetails = item['RacingFormGuide']['Event']['Race']
 raceData += 
(raceDetails['Name'],raceDetails['Number'],raceDetails['Distance'])

print(raceDetails)

which returns

['CLASS 3 HANDICAP', 1, 1000, 'BM 90 HANDICAP', 2, 1600, 'HERITAGE STAKES', 3, 
1100, 'BILL RITCHIE HANDICAP', 4, 1400, 'TEA ROSE STAKES', 5, 1400, 'GEORGE 
MAIN STAKES', 6, 1600, 'THE SHORTS', 7, 1100, 'KINGTON TOWN STAKES', 8, 2000, 
'BM 84 HANDICAP', 9, 1200]

How do I get the tuples?

Cheers

Sayth

---
This email has been checked for viruses by AVG.
http://www.avg.com



After a quick glance and hence completely untested:-

raceData.append((raceDetails['Name'],raceDetails['Number'],raceDetails['Distance']))

--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

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


[issue27541] Repr of collection's subclasses

2017-09-21 Thread STINNER Victor

STINNER Victor added the comment:

Why using type.__name__ rather than type.__qualname__?

--
nosy: +haypo

___
Python tracker 

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



  1   2   >