[issue32911] Doc strings no longer stored in body of AST

2018-04-12 Thread INADA Naoki

INADA Naoki  added the comment:

> in practice `ast.parse()` is often used with smaller fragments of source code 
> that don't directly correspond to a complete module, and this behaviour makes 
> no sense in such cases.
>
> The resulting bug in kdev-python took a while to track down (because I had no 
> immediate reason to suspect this change), and will be somewhat awkward to 
> workaround.

Would you elaborate it more, please?
Without concrete example, we cannot to decide how it's important problem.

> I would prefer that this be reverted; it's likely to break a variety of users 
> in strange ways.

I don't want to revert, see discussions in this issue and PR-5927.

And would you give us real world example of "variety of users"?
How many applications use ast.parse for such way?

--

___
Python tracker 

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



Installing NETCDF4 in windows using python 3.4

2018-04-12 Thread shalu . ashu50
Hi All,

I have downloaded NETCDF4 module from https://pypi.python.org/pypi/netCDF4 e.g. 
netCDF4-1.3.1-cp34-cp34m-win_amd64.whl

I have installed it using pip install netCDF4-1.3.1-cp34-cp34m-win_amd64.whl

through the command prompt in Spyder. It has successfully installed. 

C:\python3>pip install netCDF4-1.3.1-cp34-cp34m-win_amd64.whl
Processing c:\python3\netcdf4-1.3.1-cp34-cp34m-win_amd64.whl
Requirement already satisfied: numpy>=1.7 in 
c:\python3\winpython-64bit-3.4.4.5qt5\python-3.4.4.amd64\lib\site-packages 
(from netCDF4==1.3.1)
Installing collected packages: netCDF4
  Found existing installation: netCDF4 1.3.2
Uninstalling netCDF4-1.3.2:
  Successfully uninstalled netCDF4-1.3.2
Successfully installed netCDF4-1.3.1


But when I am trying to import, it is giving an error:

import netCDF4 as nc4 Traceback (most recent call last):

File "", line 1, in import netCDF4 as nc4

File 
"C:\python3\WinPython-64bit-3.4.4.5Qt5\python-3.4.4.amd64\lib\site-packages\netCDF4__init__.py",
 line 3, in from ._netCDF4 import *

File "netCDF4_netCDF4.pyx", line 2988, in init netCDF4._netCDF4

AttributeError: type object 'netCDF4._netCDF4.Dimension' has no attribute 
'reduce_cython'

How can I fix it? Suggestions would be appreciated.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to write partial of a buffer which was returned from a C function to a file?

2018-04-12 Thread eryk sun
On Fri, Apr 13, 2018 at 12:38 AM, Jach Fong  wrote:
> Gregory Ewing at 2018/4/13 上午 07:25 wrote:
>
>> To get around this, you may need to declare the return type
>> as POINTER(c_char) instead:
>>
>>> For a general character pointer that may also point to binary data,
>>
>>  > POINTER(c_char) must be used.
>
> I had missed this statement:-(
>
> To make a quick try, I set the function's restype to
> ctypes.POINTER(ctypes.c_ubyte), instead of ctypes.c_char_p. It's amazing,
> the \x00 trap can be avoided in this way. Now I can use "mydata =
> bytes(buf[:n])" to extract n bytes of data and write it to file.

Slicing a ctypes.POINTER(ctypes.c_char) pointer returns bytes without
having to make a third copy via the bytes constructor. (Note that
c_char is the fundamental C char integer type, not to be confused with
c_char_p, which is a char * pointer.) However, if you're working with
multi-megabyte data buffers,it's more efficient and safer to use an
array view (ctypes or NumPy) on the returned buffer.

In most cases, you should free the returned pointer after you're
finished processing the data buffer, else you'll have a memory leak.
The library should export a function for this.
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue33265] contextlib.ExitStack abuses __self__

2018-04-12 Thread Yury Selivanov

Yury Selivanov  added the comment:

Yep, I think this is a good fix!

--

___
Python tracker 

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



Re: How to write partial of a buffer which was returned from a C function to a file?

2018-04-12 Thread Jach Fong


Gregory Ewing at 2018/4/13 上午 07:25 wrote:

On Thu, Apr 12, 2018 at 2:16 PM,   wrote:


This C function returns a buffer which I declared it as a
ctypes.c_char_p. The buffer has size 0x1 bytes long and the valid
data may vary from a few bytes to the whole size.


I think we need to see the code you're using to call this
C function.

The crucial issue is: are *you* allocating this 0x1 byte
buffer and telling the function to read data into it, or
does the function allocate the memory itself and return a
pointer to it?


I am working on a DLL's function.



If the function is allocating the buffer, then I don't
think there's any way to make this work. The ctypes docs
say this:

Fundamental data types, when returned as foreign function call results 
... are
transparently converted to native Python types. In other words, if a 
foreign
function has a restype of c_char_p, you will always receive a Python 
bytes

object, not a c_char_p instance.


The problem is that the only way ctypes can tell how long
a bytes object to create for a c_char_p is by assuming that
it points to a nul-terminated string. If it actually points
to a char array that can legitimately contain zero bytes,
then you're out of luck.

To get around this, you may need to declare the return type
as POINTER(c_char) instead:


For a general character pointer that may also point to binary data,

 > POINTER(c_char) must be used.


I had missed this statement:-(

To make a quick try, I set the function's restype to 
ctypes.POINTER(ctypes.c_ubyte), instead of ctypes.c_char_p. It's 
amazing, the \x00 trap can be avoided in this way. Now I can use "mydata 
= bytes(buf[:n])" to extract n bytes of data and write it to file.


The problem was solved, and thanks for all your help.

--Jach


I'm not sure where to go from here, though, because the
ctypes documentation peters out before explaining exactly
what can be done with a POINTER object.

Another approach would be to allocate the buffer yourself
and pass it into the C function, but whether that's possible
depends on the details of the C API you're using.



---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

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


Re: How to write partial of a buffer which was returned from a C function to a file?

2018-04-12 Thread eryk sun
On Thu, Apr 12, 2018 at 11:25 PM, Gregory Ewing
 wrote:
>
> To get around this, you may need to declare the return type
> as POINTER(c_char) instead:
>
>> For a general character pointer that may also point to binary data,
>
>> POINTER(c_char) must be used.
>
> I'm not sure where to go from here, though, because the
> ctypes documentation peters out before explaining exactly
> what can be done with a POINTER object.

Pointers can be indexed and sliced. You have to be careful, however,
since there's no bounds checking. Alternatively, without copying, you
can create an array view on the buffer, which is bounded and thus
doesn't risk an access violation (segfault). For example:

Say the function returns a pointer to a buffer with the contents
b"spam\x00". Let's simulate the function result using a void * pointer
to initialize a char * pointer:

>>> buf0 = ctypes.create_string_buffer(b'spam')
>>> pvoid = ctypes.c_void_p(ctypes.addressof(buf0))
>>> result = ctypes.POINTER(ctypes.c_char).from_buffer_copy(pvoid)

This pointer object has just the address of the buffer, without
supporting references in _b_base_ or _objects:

>>> result._b_base_ is result._objects is None
True

(In other words, ctypes isn't responsible for the buffer, as simulated
here. Libraries that allocate their own memory for results have to
provide a function to free it. Especially on Windows, you cannot rely
on both Python and the DLL to use the same heap.)

You can slice the pointer:

>>> result[:5]
b'spam\x00'

Or you can access the buffer more safely as a new array view:

>>> array_t = ctypes.c_char * 5
>>> pointer_t = ctypes.POINTER(array_t)
>>> result.contents
c_char(b's')

>>> buf1 = pointer_t(result.contents)[0]
>>> buf1[:]
b'spam\x00'

This buf1 array is a view on the buffer, not a copy. It reflects
whatever changes are made to the underlying buffer:

>>> buf0[:] = b'eggs\x00'
>>> buf1[:]
b'eggs\x00'

As such, ctypes knows it doesn't have to free this memory:

>>> buf1._b_needsfree_
0
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue32911] Doc strings no longer stored in body of AST

2018-04-12 Thread Francis Herne

Francis Herne  added the comment:

Note:

Because this also applies to module-level docstrings, a rather strange effect 
that, for example, `ast.parse("'foo'")` is now an empty module.

While the root node is always an instance of `ast.Module`, in practice 
`ast.parse()` is often used with smaller fragments of source code that don't 
directly correspond to a complete module, and this behaviour makes no sense in 
such cases.

The resulting bug in kdev-python took a while to track down (because I had no 
immediate reason to suspect this change), and will be somewhat awkward to 
workaround.

I would prefer that this be reverted; it's likely to break a variety of users 
in strange ways.

--
nosy: +flherne

___
Python tracker 

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



Re: How to write partial of a buffer which was returned from a C function to a file?

2018-04-12 Thread Cameron Simpson

On 12Apr2018 16:11, Jach Fong  wrote:
This is the first time I am using python-list to interact with 
comp.lang.python forum (because there are so many spam when using 
browser to view it) so forgive me if something goes wrong.


Python already treat the returned buffer as 'bytes'. The problem is 
Python don't know its size (or decides it wrong:-).


I think you'll need to show us your code. It isn't clear to me your problem is.

Cheers,
Cameron Simpson 
--
https://mail.python.org/mailman/listinfo/python-list


Re: How to write partial of a buffer which was returned from a C function to a file?

2018-04-12 Thread Gregory Ewing

On Thu, Apr 12, 2018 at 2:16 PM,   wrote:


This C function returns a buffer which I declared it as a
ctypes.c_char_p. The buffer has size 0x1 bytes long and the valid
data may vary from a few bytes to the whole size.


I think we need to see the code you're using to call this
C function.

The crucial issue is: are *you* allocating this 0x1 byte
buffer and telling the function to read data into it, or
does the function allocate the memory itself and return a
pointer to it?

If the function is allocating the buffer, then I don't
think there's any way to make this work. The ctypes docs
say this:


Fundamental data types, when returned as foreign function call results ... are
transparently converted to native Python types. In other words, if a foreign
function has a restype of c_char_p, you will always receive a Python bytes
object, not a c_char_p instance.


The problem is that the only way ctypes can tell how long
a bytes object to create for a c_char_p is by assuming that
it points to a nul-terminated string. If it actually points
to a char array that can legitimately contain zero bytes,
then you're out of luck.

To get around this, you may need to declare the return type
as POINTER(c_char) instead:


For a general character pointer that may also point to binary data,

> POINTER(c_char) must be used.

I'm not sure where to go from here, though, because the
ctypes documentation peters out before explaining exactly
what can be done with a POINTER object.

Another approach would be to allocate the buffer yourself
and pass it into the C function, but whether that's possible
depends on the details of the C API you're using.

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


[issue33264] Remove to-be-deprecated urllib.request.urlretrieve function reference from HOWTO

2018-04-12 Thread Andrés Delfino

Andrés Delfino  added the comment:

My contributor form shows as received now :)

Don't know how to update the "CLA not signed" label on the PR.

--

___
Python tracker 

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



Making matrix solver/ solver for X

2018-04-12 Thread steffie . booij
Hee guys,

I'm learning Python partly for school and wanted to see if I could figure some 
things out myself.

I wanted to make like a value finder, sort of like numpy.solve (sounds more 
ambitious than it is) but I'm sort of stuck, since I'm a beginner.

Let's say I want to find the values of matrix X with X1, X2, X3 and X4. And 
that X is multiplied with matrix Q and then X substracted from it.

I thought about:

X = np.array(['X1', 'X2', 'X3', 'X4'])

Q = np.array(['Q1', 'Q2', 'Q3', 'Q4'])

P = (X*Q)-X

I chose array's since all the X and Q values can be different.

How would I be able to find the values of X if the Q-array would be given and 
it would have to be solved under the condition that out of 4 P values, at least 
2 would be more or equal to sum of X.

So solve condition:
P[0]+P[1] ,P[0]+P[2] ,P[0]+P[3] ,P[1]+P[2] ,P[1]+P[3] ,P[2]+P[3] >= np.sum(X)

So summary:
If Q is given here, and only X is unknown, and P has only one unknown 
(X-array), how can I calculate the X-matrix with the solve condition?

Can you guys help me? I feel like it's an easy set of lines of code, but like I 
said I'm still trying to learn. And improvise to see if I understand it.
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue33211] lineno and col_offset are wrong on function definitions with decorators

2018-04-12 Thread Ethan Smith

Change by Ethan Smith :


--
pull_requests: +6154

___
Python tracker 

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



[issue33267] ctypes array types create reference cycles

2018-04-12 Thread Josh Rosenberg

Josh Rosenberg  added the comment:

Pretty sure this is a problem with classes in general; classes are 
self-referencing, and using multiplication to create new ctypes array types is 
creating new classes.

--
nosy: +josh.r

___
Python tracker 

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



[issue19993] Pool.imap doesn't work as advertised

2018-04-12 Thread Josh Rosenberg

Josh Rosenberg  added the comment:

Related: issue29842 "Make Executor.map work with infinite/large inputs 
correctly" for a similar problem in concurrent.futures (but worse, since it 
doesn't even allow you to begin consuming results until all inputs are 
dispatched).

A similar approach to my Executor.map patch could probably be used with 
imap/imap_unordered.

--
nosy: +josh.r

___
Python tracker 

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



[issue33217] x in enum.Flag member is True when x is not a Flag

2018-04-12 Thread Ethan Furman

Ethan Furman  added the comment:

DeprecationWarning is in 3.7, now need to raise TypeError in 3.8.

--
stage: patch review -> needs patch
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



[issue33219] x in IntFlag should test raise TypeError if x is not an IntFlag

2018-04-12 Thread Ethan Furman

Ethan Furman  added the comment:

This and issue33217 are similar enough I'm going to track it in issue33217.

--
resolution:  -> duplicate
stage: needs patch -> resolved
status: open -> closed
superseder:  -> x in enum.Flag member is True when x is not a Flag

___
Python tracker 

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



[issue33270] tags for anonymous code objects should be interned

2018-04-12 Thread Daniel Moisset

New submission from Daniel Moisset :

In compile.c, some strings are created to be used as name of anonymous code 
objects: "", "", "", "", "" and 
"".

Only the first two of those are interned (created with 
PyUnicode_InternFromString ), the rest are created with "PyUnicode_FromString". 
Even if they use a static variable to avoid creating multiple instances, not 
interning results in multiple copies when code objects are marshaled into pyc 
files and reloaded (one copy per module).

Always using PyUnicode_InternFromString should be more consistent, and slightly 
more efficient

--
components: Interpreter Core
messages: 315232
nosy: Daniel Moisset
priority: normal
severity: normal
status: open
title: tags for anonymous code objects should be interned

___
Python tracker 

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



[issue19173] Expose Queue maxsize parameter to multiprocessing.Pool class

2018-04-12 Thread Ned Deily

Change by Ned Deily :


--
nosy: +davin, pitrou

___
Python tracker 

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



[issue19993] Pool.imap doesn't work as advertised

2018-04-12 Thread Ned Deily

Change by Ned Deily :


--
nosy: +davin, pitrou

___
Python tracker 

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



Re: How to write partial of a buffer which was returned from a C function to a file?

2018-04-12 Thread Albert-Jan Roskam

On Apr 12, 2018 09:39, jf...@ms4.hinet.net wrote:
>
> Chris Angelico於 2018年4月12日星期四 UTC+8下午1時31分35秒寫道:
> > On Thu, Apr 12, 2018 at 2:16 PM,   wrote:
> > > This C function returns a buffer which I declared it as a 
> > > ctypes.c_char_p. The buffer has size 0x1 bytes long and the valid 
> > > data may vary from a few bytes to the whole size.
> > >
> > > In every call I know how much the valid data size is, but I suppose I 
> > > can't use slice to get it because there may be zero byte in it. What to 
> > > do?
> > >
> >
> > You suppose? Or have you tested it?
> >
> > ChrisA
>
> Yes, I had test it once before. Now, I re-do it again to make sure. After a 
> call which returns 3 bytes of data, I use len(buf) to check the length and 
> get the number 24. I can see the first 24 bytes of data by using buf[:30] but 
> buf[24] will cause an "index out of range" error. I don't know how to see 
> what the buf[24] exactly is but I suppose it might be a zero byte.

Aren't you looking for the .value or the .raw property?
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue19993] Pool.imap doesn't work as advertised

2018-04-12 Thread Alex Garel

Alex Garel  added the comment:

Hello, I think this is a really important feature, it hits me hard those days. 

It would also solve https://bugs.python.org/issue19173 in a nice way.

--
nosy: +alex-garel

___
Python tracker 

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



[issue33266] 2to3 doesn't parse all valid string literals

2018-04-12 Thread Ned Deily

Change by Ned Deily :


--
nosy: +benjamin.peterson

___
Python tracker 

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



[issue32696] Fix pickling exceptions with multiple arguments

2018-04-12 Thread Jason R. Coombs

Jason R. Coombs  added the comment:

Kirill, see https://bugs.python.org/issue1692335#msg310951 in the related issue 
for one possible way to work around the issue on Python 3.

--

___
Python tracker 

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



[issue14573] json iterencode can not handle general iterators

2018-04-12 Thread Ned Deily

Ned Deily  added the comment:

If there is still interest in this, perhaps @Zectbumo could rebase the patch as 
a PR against the master branch of the current python/cpython repo now that 
we've moved to git and GitHub (https://devguide.python.org/pullrequest/).  
There's no guarantee that it will ultimately be accepted but it will make it 
much easier to review.

--
nosy: +ned.deily
versions: +Python 3.8 -Python 3.5

___
Python tracker 

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



[issue33065] IDLE debugger: problem importing user created module

2018-04-12 Thread Brett Cannon

Brett Cannon  added the comment:

Without knowing the exact Python version it's hard to tell as line 59 changed 
between Python 3.5 and where Python 3.6 is now (FYI, the line as it currently 
sits in Python 3.6 is 
https://github.com/python/cpython/blob/e98e3385f2acfc6d98f70f8e66c96b752d003b8f/Lib/importlib/_bootstrap.py#L59).
 But the double-reporting of the same line is a bit odd.

The best I can think of is that IDLE is requesting the __repr__() of `self` 
while still executing `__init__()` but before `self.name` is set, triggering an 
AttributeError (although those lines don't exactly line up with that). 
Otherwise looking at the code for _ModuleLock suggests this really shouldn't 
happen as `self.name` is set in `__init__()` and there's no use of `del` or 
`delattr()` that would cause this.

--

___
Python tracker 

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



[issue33267] ctypes array types create reference cycles

2018-04-12 Thread Ned Deily

Change by Ned Deily :


--
nosy: +amaury.forgeotdarc, belopolsky, meador.inge

___
Python tracker 

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



[issue33269] InteractiveConsole behaves differently when used on terminal and used within script

2018-04-12 Thread Kadir Haldenbilen

Kadir Haldenbilen  added the comment:

Attached is a non working example
I could not attach a second file, which works OK within script I will attach 
separately

--
Added file: https://bugs.python.org/file47533/iitests.py

___
Python tracker 

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



[issue33269] InteractiveConsole behaves differently when used on terminal and used within script

2018-04-12 Thread Kadir Haldenbilen

Kadir Haldenbilen  added the comment:

This script works OK. Compare with iitests.py uploaded before

--
Added file: https://bugs.python.org/file47534/iiteswok.py

___
Python tracker 

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



[issue32696] Fix pickling exceptions with multiple arguments

2018-04-12 Thread Kirill Matsaberydze

Kirill Matsaberydze  added the comment:

Hi, I encounter similar behavior in python 3.6.5 with following code:

import pickle
class CustomException(Exception):
def __init__(self, arg1, arg2):
msg = "Custom message {} {}".format(arg1, arg2)
super().__init__(msg)


obj_dump = pickle.dumps(CustomException("arg1", "arg2"))
obj = pickle.loads(obj_dump)

Traceback (most recent call last):
  File "", line 1, in 
TypeError: __init__() missing 1 required positional argument: 'arg2'

So it looks like it not only python 2.7 problem

--
nosy: +Kirill Matsaberydze

___
Python tracker 

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



Re: Pandas, create new column if previous column(s) are not in [None, '', np.nan]

2018-04-12 Thread zljubisic
On Wednesday, 11 April 2018 21:19:44 UTC+2, José María Mateos  wrote:
> On Wed, Apr 11, 2018, at 14:48, zlj...com wrote:
> > I have a dataframe:
> > [...]
> 
> This seems to work:
> 
> df1 = pd.DataFrame( { 'A' : ['a', 'b', '', None, np.nan],
>   'B'  : [None, np.nan, 'a', 
> 'b', '']})
> df1['C'] = df1[['A', 'B']].apply(lambda x: x[0] if x[1] in [None, '', np.nan] 
> else x[1], axis = 1)
> 
> Two notes:
> 
> - Do apply() on axis = 1, so you process every row.
> - You lambda function wasn't entirely correct, if I understood what you 
> wanted to do.
> 
> Cheers,
> 
> -- 
> José María (Chema) Mateos
> https://rinzewind.org/blog-es || https://rinzewind.org/blog-en

Thanks Jose, this what I needed. Thanks also to all others.
Regards.
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue33269] InteractiveConsole behaves differently when used on terminal and used within script

2018-04-12 Thread Kadir Haldenbilen

New submission from Kadir Haldenbilen :

on terminal push and runcode accepts indentation where required (like for loop 
etc), within script gives error message

on terminal import works properly and objects can be found  as normal, within 
script you may need to add module name upfront

simple example
import code
ii = code.InteractiveConsole()
ii.push("for ii in range(3):")
ii.push("print('i', i)")

you will get normal expected output on terminal, but indentation error within 
script

ii.push("from time import sleep")
ii.push("sleep(1)")
will sleep 1 sec on terminal, but will give name error

--
messages: 315224
nosy: Kadir Haldenbilen
priority: normal
severity: normal
status: open
title: InteractiveConsole behaves differently when used on terminal and used 
within script
type: behavior
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



[issue33266] 2to3 doesn't parse all valid string literals

2018-04-12 Thread Eric V. Smith

Eric V. Smith  added the comment:

Is 2to3 supposed to be able to parse non-python2 files? I don't recall.

--
nosy: +eric.smith

___
Python tracker 

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



[issue14573] json iterencode can not handle general iterators

2018-04-12 Thread Jan Vlcinsky

Jan Vlcinsky  added the comment:

I found proposed change very handy (came here researching why it is not 
behaving that way).

Taking into account:
- Python shines in handling lists, using generators and iterators
- Largest group of python developers develop web apps, and there it is typical 
pattern to iterate across many records and return them as long list of 
dictionaries

I think proposed feature could become very popular.

--
nosy: +vlcinsky

___
Python tracker 

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



Re: How to write partial of a buffer which was returned from a C function to a file?

2018-04-12 Thread Jach Fong
This is the first time I am using python-list to interact with 
comp.lang.python forum (because there are so many spam when using 
browser to view it) so forgive me if something goes wrong.


Python already treat the returned buffer as 'bytes'. The problem is 
Python don't know its size (or decides it wrong:-).


--Jach

Cameron Simpson at 2018/4/12 PM 02:28 wrote:

On 11Apr2018 21:16, jf...@ms4.hinet.net  wrote:
This C function returns a buffer which I declared it as a 
ctypes.c_char_p. The buffer has size 0x1 bytes long and the valid 
data may vary from a few bytes to the whole size.


Could you show us the function?

In every call I know how much the valid data size is, but I suppose I 
can't use slice to get it because there may be zero byte in it. What 
to do?


Why not just return bytes? Allocate one of the correct size and copy the 
bytes into it, then return?


Of course it is all hard to say without seeing some actual code.

Cheers,
Cameron Simpson 





---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

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


Re: How to write partial of a buffer which was returned from a C function to a file?

2018-04-12 Thread jfong
Chris Angelico於 2018年4月12日星期四 UTC+8下午4時05分29秒寫道:
> On Thu, Apr 12, 2018 at 4:20 PM,   wrote:
> > Chris Angelico於 2018年4月12日星期四 UTC+8下午1時31分35秒寫道:
> >> On Thu, Apr 12, 2018 at 2:16 PM,   wrote:
> >> > This C function returns a buffer which I declared it as a 
> >> > ctypes.c_char_p. The buffer has size 0x1 bytes long and the valid 
> >> > data may vary from a few bytes to the whole size.
> >> >
> >> > In every call I know how much the valid data size is, but I suppose I 
> >> > can't use slice to get it because there may be zero byte in it. What to 
> >> > do?
> >> >
> >>
> >> You suppose? Or have you tested it?
> >>
> >> ChrisA
> >
> > Yes, I had test it once before. Now, I re-do it again to make sure. After a 
> > call which returns 3 bytes of data, I use len(buf) to check the length and 
> > get the number 24. I can see the first 24 bytes of data by using buf[:30] 
> > but buf[24] will cause an "index out of range" error. I don't know how to 
> > see what the buf[24] exactly is but I suppose it might be a zero byte.
> >
> 
> If you have 24 bytes, they're numbered 0 through 23. So there is no byte at 
> 24.
> 
> ChrisA

Using a technique you mentioned in subject "how to memory dump an object?" at 
16/5/21, I confirm the length of buf was decided by a \x00 byte:

>>> len(buf)
24
>>> id(buf)
13553888
>>> ptr = ctypes.cast(id(buf), ctypes.POINTER(ctypes.c_ubyte))
>>> buf[:24]
b'\x05ALLOTNPUT_BUFFER_SIZE\x02+'
>>> bytes([ptr[i] for i in range(50)])
b'\x02\x00\x00\x00X\xa1%\x1e\x18\x00\x00\x00\xff\xff\xff\xff\x05ALLOTNPUT_BUFFER_SIZE\x02+\x00\n\x00\x00\x00\x00\x00\x00\xb0\x9b'
>>>

but it won't help on solving my problem. Still need someone's help:-)

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


[issue33265] contextlib.ExitStack abuses __self__

2018-04-12 Thread Nick Coghlan

Nick Coghlan  added the comment:

Yury, could you double check the async exit stack change in the PR? I think 
it's fine since the bound method just passes back the underlying coroutine and 
the tests all still pass, but a second opinion would be good :)

--
nosy: +yselivanov

___
Python tracker 

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



Re: Compression of random binary data

2018-04-12 Thread Ned Batchelder

On 4/11/18 9:29 PM, cuddlycave...@gmail.com wrote:

I’m replying to your post on January 28th
Nice carefully chosen non random numbers  Steven D'Aprano.
Was just doing what you asked, but you don’t remember 


Best practice is to include a quote of the thing you are replying to.  
It makes it much easier for people to follow the thread of the 
discussion, especially when there are large gaps in the timeline.


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


[issue33268] iteration over attrs in metaclass' __new__ affects class' __name__

2018-04-12 Thread tkhyn

tkhyn  added the comment:

oops,  indeed. Sometimes the obvious things are not so obvious ..
Sorry for the noise!

--

___
Python tracker 

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



[issue33268] iteration over attrs in metaclass' __new__ affects class' __name__

2018-04-12 Thread Eric V. Smith

Eric V. Smith  added the comment:

In the loop, you're reassigning the value of name, then using it in the super 
call. If you change the name of the loop variable, your code works.

--
nosy: +eric.smith
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed
type:  -> behavior

___
Python tracker 

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



[issue33268] iteration over attrs in metaclass' __new__ affects class' __name__

2018-04-12 Thread tkhyn

New submission from tkhyn :

The following script, run with python 3.6.5, highlights an issue with the 
class' __name__ attribute being set incorrectly just because of a loop in the 
metaclass' __new__ method:

class MC(type):
def __new__(mcs, name, bases, attrs):
for name, attr in attrs.items():
pass
return super(MC, mcs).__new__(mcs, name, bases, attrs)

class C(metaclass=MC):
a = None

print(C.__name__)


Expected output: "C"
Actual output: "a"

Comment the for loop and you get the expected output!

On Python 2.7.13, the amended code exposes the same bug:

class MC(type):
def __new__(mcs, name, bases, attrs):
for name, attr in attrs.items():
pass
return super(MC, mcs).__new__(mcs, name, bases, attrs)

class C(object):
__metaclass__ = MC
a = None

print C.__name__

output is "__metaclass__" and should be "C"

--
components: Interpreter Core
messages: 315218
nosy: tkhyn
priority: normal
severity: normal
status: open
title: iteration over attrs in metaclass' __new__ affects class' __name__
versions: Python 2.7, 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: beacons and geofences

2018-04-12 Thread Karsten Hilbert
On Thu, Apr 12, 2018 at 12:33:39AM +0200, ElChino wrote:

> Rafal Sikora wrote:
> 
> > Hi! I want users’ devices to be able to monitor the maximum amount of POIs 
> > at
> > once (geo-fences/beacons) and I need to prepare an algorithm solution for
> >  monitoring the POIs. How should it be implemented in Python?
> 
> What? You'll have to describe the problem in more details
> if you want any sensible answers.

I just might so happen that the homework assignment did not
contain much more in terms of description.

Karsten
-- 
GPG key ID E4071346 @ eu.pool.sks-keyservers.net
E167 67FD A291 2BEA 73BD  4537 78B9 A9F9 E407 1346
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to write partial of a buffer which was returned from a C function to a file?

2018-04-12 Thread Cameron Simpson

On 11Apr2018 21:16, jf...@ms4.hinet.net  wrote:

This C function returns a buffer which I declared it as a ctypes.c_char_p. The 
buffer has size 0x1 bytes long and the valid data may vary from a few bytes 
to the whole size.


Could you show us the function?

In every call I know how much the valid data size is, but I suppose I can't 
use slice to get it because there may be zero byte in it. What to do?


Why not just return bytes? Allocate one of the correct size and copy the bytes 
into it, then return?


Of course it is all hard to say without seeing some actual code.

Cheers,
Cameron Simpson 
--
https://mail.python.org/mailman/listinfo/python-list


[issue33267] ctypes array types create reference cycles

2018-04-12 Thread Eric Wieser

Eric Wieser  added the comment:

Apologies, I missed the important part of that snippet:
```
In [3]: gc.collect(); x = make_array_ctype((1,)); del x; gc.collect()
Out[3]: 7
```

--

___
Python tracker 

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



[issue33267] ctypes array types create reference cycles

2018-04-12 Thread Eric Wieser

New submission from Eric Wieser :

Discovered in https://github.com/numpy/numpy/pull/10882/files#r180813166

A reproduction:
```
In [1]: import ctypes

In [2]: def make_array_ctype(shape):
   ...: import ctypes
   ...: ct = ctypes.c_uint8
   ...: for i in shape:
   ...: ct = i * ct
   ...: return ct
   ...:

# all on one line to keep ipython out of this
In [3]: gc.collect(); x = make_array_ctype((1,)); del x; gc.collect()
```

Using the proposed function in https://github.com/numpy/numpy/pull/10891, we 
get a few more details:
```
In [4]: from numpy.testing import assert_no_gc_cycles

In [5]: assert_no_gc_cycles(make_array_ctype, (1,))
AssertionError: Reference cycles were found when calling make_array_ctype: 7 
objects were collected, of which 6 are shown below:
  tuple object with id=282226536:
(,)
  PyCArrayType object with id=286500408:

  getset_descriptor object with id=2822252062256:

  getset_descriptor object with id=2822252062184:

  tuple object with id=2822243712440:
(,
 ,
 ,
 )
  StgDict object with id=286211928:
{'__dict__': ,
 '__doc__': None,
 '__module__': '__main__',
 '__weakref__': ,
 '_length_': 1,
 '_type_': }
```

I suppose this isn't really a bug, but it's not clear to me why a cycle needs 
to be created here.

--
components: ctypes
messages: 315216
nosy: Eric.Wieser
priority: normal
severity: normal
status: open
title: ctypes array types create reference cycles
versions: Python 3.5

___
Python tracker 

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



[issue33266] 2to3 doesn't parse all valid string literals

2018-04-12 Thread Roundup Robot

Change by Roundup Robot :


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

___
Python tracker 

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



[issue33266] 2to3 doesn't parse all valid string literals

2018-04-12 Thread Zsolt Dollenstein

New submission from Zsolt Dollenstein :

For example `rf"blah"` is not tokenized properly.

--
components: 2to3 (2.x to 3.x conversion tool)
messages: 315215
nosy: Zsolt Dollenstein
priority: normal
severity: normal
status: open
title: 2to3 doesn't parse all valid string literals
type: behavior

___
Python tracker 

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



[issue29456] bugs in unicodedata.normalize: u1176, u11a7 and u11c3

2018-04-12 Thread Wonsup Yoon

Wonsup Yoon  added the comment:

Hello!

--

___
Python tracker 

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



Re: How to write partial of a buffer which was returned from a C function to a file?

2018-04-12 Thread Chris Angelico
On Thu, Apr 12, 2018 at 4:20 PM,   wrote:
> Chris Angelico於 2018年4月12日星期四 UTC+8下午1時31分35秒寫道:
>> On Thu, Apr 12, 2018 at 2:16 PM,   wrote:
>> > This C function returns a buffer which I declared it as a ctypes.c_char_p. 
>> > The buffer has size 0x1 bytes long and the valid data may vary from a 
>> > few bytes to the whole size.
>> >
>> > In every call I know how much the valid data size is, but I suppose I 
>> > can't use slice to get it because there may be zero byte in it. What to do?
>> >
>>
>> You suppose? Or have you tested it?
>>
>> ChrisA
>
> Yes, I had test it once before. Now, I re-do it again to make sure. After a 
> call which returns 3 bytes of data, I use len(buf) to check the length and 
> get the number 24. I can see the first 24 bytes of data by using buf[:30] but 
> buf[24] will cause an "index out of range" error. I don't know how to see 
> what the buf[24] exactly is but I suppose it might be a zero byte.
>

If you have 24 bytes, they're numbered 0 through 23. So there is no byte at 24.

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


Re: How to write partial of a buffer which was returned from a C function to a file?

2018-04-12 Thread jfong
Chris Angelico於 2018年4月12日星期四 UTC+8下午1時31分35秒寫道:
> On Thu, Apr 12, 2018 at 2:16 PM,   wrote:
> > This C function returns a buffer which I declared it as a ctypes.c_char_p. 
> > The buffer has size 0x1 bytes long and the valid data may vary from a 
> > few bytes to the whole size.
> >
> > In every call I know how much the valid data size is, but I suppose I can't 
> > use slice to get it because there may be zero byte in it. What to do?
> >
> 
> You suppose? Or have you tested it?
> 
> ChrisA

Yes, I had test it once before. Now, I re-do it again to make sure. After a 
call which returns 3 bytes of data, I use len(buf) to check the length and get 
the number 24. I can see the first 24 bytes of data by using buf[:30] but 
buf[24] will cause an "index out of range" error. I don't know how to see what 
the buf[24] exactly is but I suppose it might be a zero byte.

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


[issue33265] contextlib.ExitStack abuses __self__

2018-04-12 Thread Eric V. Smith

Change by Eric V. Smith :


--
nosy: +ncoghlan

___
Python tracker 

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