ANN: rom 0.29.0 - Redis object mapper for Python

2014-10-08 Thread Josiah Carlson
Hey everyone,

The rom package is a Redis object mapper for Python. It sports an
interface similar to Django's ORM, SQLAlchemy with the declarative base, or
Appengine's datastore.

The changelog for recent releases can be seen below my signature.

You can find the package at:
https://www.github.com/josiahcarlson/rom
https://pypi.python.org/pypi/rom

And docs can be found at:
http://pythonhosted.org/rom/

Please CC me on any replies if you have any questions or comments.

Thank you,
 - Josiah


#-- 0.29.0
---
[added] Query result iterator: query.iter_result(timeout, pagesize) that
automatically wraps query.cached_result(timeout) for convenient
iteration
over all entities in the query. Added at the request of Github user
https://github.com/JamesHutchison .
[added] On delete for OneToMany columns now support 'cascade' for
recursively
deleting all referencing entities. All on delete behavior is checked
before deleting (a restrict in an entity after 100 levels of 'cascade'
will prevent all deletions). Requested by
https://github.com/JamesHutchison and closes issue #39.
[added] OneToMany columns can now include a reference to the foreign model's
ManyToOne column name that references *this* OneToMany. Useful for cases
where models have multiple OneToMany or ManyToOne columns referencing
the
same models. Closes issue #23.
[fixes] Index clearing with util.clean_old_index()
[changed] Index clearing with util.clean_old_index() will also clean out
index
data for entities directly deleted or expired in Redis. Closes issue
#40.
#-- 0.28.0
---
[added] Composite unique constraints like SQLAlchemy's UniqueConstraint()
and
Django's unique_together, spelled and used like Django's
unique_together.
See http://pythonhosted.org//rom/rom.html#rom.Model for details.
[fixed] Deleting entities will no longer leave extra index data around
(regardless of whether the entitiy had any indexes defined).
[added] Convenience function for cleaning out old index data from deleted
entities. See and read the help on util.clean_old_index() .
[added] Convenience function util.show_progress() to show the progress of
util.refresh_indices() and util.clean_old_index() . See and read the
help
on util.show_progress() for usage.
[fixed] Tests to no longer leave testing data in db 15, and running tests
again should clean out the testing data.
[fixed] Incorrect documentation about the String column type.
#-- 0.27.0
---
[changed] Added auto-tagging support for release versions pushed to PyPI.
[added] Foreign key references defined with a OneToMany and ManyToOne
relationship will now have the one side of the relationship deletion
optionally restrict. Thanks to https://github.com/pconerly for the
initial
request and patch.
[added] Additional warnings and tests for future on_delete behavior choices.
[fixed] Re-save issue for datetime objects, as well as any future re-save
issues (like what happened with json columns in rom 0.15). Thanks to
https://github.com/iamkhush for the bug report and example testcase that
lead to the solution.
-- 
https://mail.python.org/mailman/listinfo/python-announce-list

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


[RELEASE] Python 3.4.2 is now available

2014-10-08 Thread Larry Hastings



On behalf of the Python development community and the Python 3.4 release 
team, I'm pleased to announce the availability of Python 3.4.2. Python 
3.4.2 has many bugfixes and other small improvements over 3.4.1.  One 
new feature for Mac OS X users: the OS X installers are now distributed 
as signed installer package files compatible with the OS X Gatekeeper 
security feature.


You can download it here:

   https://www.python.org/download/releases/3.4.2


May the road rise up to meet you,


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

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


Re: operator module functions

2014-10-08 Thread Terry Reedy

On 10/7/2014 9:41 PM, Steven D'Aprano wrote:

Every Python operator has a function version in the operator module:

operator + has function operator.add;
operator - has function operator.sub;
operator * has function operator.mul;

and so forth. Only, that's not quite right... according to the
documentation, the official functions are actually:

operator.__add__;
operator.__sub__;
operator.__mul__;

etc., with the underscore-less versions being provided as a convenience.

Was anyone aware of this?


Of course. It has bugged me a bit for years.  Messy.


Is there anyone who uses or prefers the dunder versions?


I don't and don't, and that seems to be true of other core devs: there 
are no non-test uses of the dunder methods in the stdlib.  Grepping 
/lib/*.py recursively for 'operator.' gives 540 hits, most for 
operator.someop.  Grepping the same for 'operator.__' returns 4 hits for 
operator.__name__ and .__doc__ (not operators) and these 6 tests:


C:\Programs\Python34\Lib\test\test_richcmp.py: 88: lt: (lambda 
a,b: a b, operator.lt, operator.__lt__),
C:\Programs\Python34\Lib\test\test_richcmp.py: 89: le: (lambda 
a,b: a=b, operator.le, operator.__le__),
C:\Programs\Python34\Lib\test\test_richcmp.py: 90: eq: (lambda 
a,b: a==b, operator.eq, operator.__eq__),
C:\Programs\Python34\Lib\test\test_richcmp.py: 91: ne: (lambda 
a,b: a!=b, operator.ne, operator.__ne__),
C:\Programs\Python34\Lib\test\test_richcmp.py: 92: gt: (lambda 
a,b: a b, operator.gt, operator.__gt__),
C:\Programs\Python34\Lib\test\test_richcmp.py: 93: ge: (lambda 
a,b: a=b, operator.ge, operator.__ge_


If there a back-compatibility excuse?  I cannot remember what operator 
had in 1.4 or whenever it was added, if after that.


--
Terry Jan Reedy

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


Re: help with regex

2014-10-08 Thread Peter Otten
James Smith wrote:

 I want the last 1
 I can't this to work:
 
 pattern=re.compile( (\d+)$ )
 match=pattern.match( LINE: 235 : Primary Shelf Number (attempt 1): 1)
 print match.group()

 pattern = re.compile((\d+)$)
 match = pattern.search( LINE: 235 : Primary Shelf Number (attempt 1): 
1)
 match.group()
'1'


See https://docs.python.org/dev/library/re.html#search-vs-match

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


Re: help with regex

2014-10-08 Thread Ben Finney
Peter Otten __pete...@web.de writes:

  pattern = re.compile((\d+)$)
  match = pattern.search( LINE: 235 : Primary Shelf Number (attempt 1): 1)
  match.group()
 '1'

An alternative way to accomplish the above using the ‘match’ method::

 import re
 pattern = re.compile(^.*:(? *)(\d+)$)
 match = pattern.match(LINE: 235 : Primary Shelf Number (attempt 1): 1)
 match.groups()
('1',)

 See https://docs.python.org/dev/library/re.html#search-vs-match

Right. Always refer to the API documentation for the API you're
attempting to use.

-- 
 \“Without cultural sanction, most or all of our religious |
  `\  beliefs and rituals would fall into the domain of mental |
_o__) disturbance.” —John F. Schumaker |
Ben Finney

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


Re: How do I check if a string is a prefix of any possible other string that matches a given regex.

2014-10-08 Thread jonathan . slenders
Le mercredi 8 octobre 2014 01:40:11 UTC+2, MRAB a écrit :
 If you're not interested in generating an actual regex, but only in
 
 matching the prefix, then it sounds like you want partial matching.
 
 
 
 The regex module supports that:
 
 
 
 https://pypi.python.org/pypi/regex

Wow, thanks a lot! That really helps me.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: operator module functions

2014-10-08 Thread marco . nawijn
For me it makes sense. operator.add should be used in a global context
(I don't know how to express it otherwise). So you provide it with the 
two values that you want to add. The .__add__ variants are bound to a
particular instance and you provide it with a single value that you want
to add. 

You also need the dunder versions when you want to implement addition for
user defined types. So although they are similar, I do believe they have
slightly different uses. As an example, you cannot use the dunder versions
for literals.

 2.__add__(3) # Oops, does not work
 a = 2
 a.__add__(3)
5
 import operator
 operator.add(2,3) # Fine

I also think operator.add versus .__add__ is equivalent to the global
getattr() and .__getattr__.

Marco




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


[RELEASE] Python 3.4.2 is now available

2014-10-08 Thread Larry Hastings



On behalf of the Python development community and the Python 3.4 release 
team, I'm pleased to announce the availability of Python 3.4.2. Python 
3.4.2 has many bugfixes and other small improvements over 3.4.1.  One 
new feature for Mac OS X users: the OS X installers are now distributed 
as signed installer package files compatible with the OS X Gatekeeper 
security feature.


You can download it here:

   https://www.python.org/download/releases/3.4.2


May the road rise up to meet you,


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


Re: operator module functions

2014-10-08 Thread Chris Angelico
(You didn't include any context in your post. Please quote as much
text as would be helpful; it's the easiest way to show what you're
talking about.)

On Wed, Oct 8, 2014 at 7:46 PM,  marco.naw...@colosso.nl wrote:
 For me it makes sense. operator.add should be used in a global context
 (I don't know how to express it otherwise). So you provide it with the
 two values that you want to add. The .__add__ variants are bound to a
 particular instance and you provide it with a single value that you want
 to add.

What Steven's talking about is this:

 operator.add is operator.__add__
True

It's the exact same function, just accessed with a different name.

 As an example, you cannot use the dunder versions for literals.

 2.__add__(3) # Oops, does not work
 a = 2
 a.__add__(3)
 5

That's actually just a syntactic issue with integers and the dot. It
works fine if you use any other form of literal, or if you put a space
between the digits and the dot, or use parentheses, or anything; this
is the case with all methods off integers, not just dunder ones.

 2 .__add__(3)
5
 (2).__add__(3)
5
 2.0.__add__(3.0)
5.0

The object is exactly the same whether you reference the literal '2'
or the name 'a' that you've bound to it, so its methods must by
definition all be there.

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


Re: Python 3.4.1 on W2K?

2014-10-08 Thread Pal Acreide
random832 wrote on Tue Oct 7 22:33:23 CEST 2014

On Tue, Oct 7, 2014, at 16:27, Michael Torrie wrote:
That's really interesting.  I looked briefly at the page.  How does your 
python extension work with xywrite?  Does it manipulate xywrite documents 
or does it tie in at runtime with Xywrite somehow?  If so, how does it do 
this?  Crossing the divide into a 16-bit app is pretty impressive.   I 
assume that it uses temporary files (or pipes, don't know if DOS can
 do this), and that DOS programs can execute windows programs with int
 21/4B.

Yup, files. In other words, rubber bands and chewing gum, but it works nicely. 
Here's a short screen video of an XPyL routine that compiles a sorted list of 
all unique words in a text file and reports average word length. Subject file 
is the Gutenberg e-file of Moby-Dick, a 1.2MB text file. It's fast.

http://youtu.be/88isdo-Cch4
BTW, this is Python 3.2.5 running on W2K in VirtualBox.


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


Re: Python 3.4.1 on W2K

2014-10-08 Thread Pal Acreide
Here's another quick one -- under 30 secs. -- and then I'll revert to lurker 
status. It's one of my favorites: Veritas wine  liquor search. (Teetotalers, 
avert your eyes.)


http://youtu.be/jDtm4z7kqyI

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


Re: ruby instance variable in python

2014-10-08 Thread flebber
 The end result of a confusing sentence with no
 
 context is that I have no idea what you are trying to say. Could you try
 
 explaining again please?
 

 
 Steven

No problem my reply from phone at work a little confusing.

So trying to determine what this does.
def ins_var
@ins_var ||= nil
end 

In particular I was guessing at this.

@ins_var ||= nil

Which I have now found on Rubyinside 
http://www.rubyinside.com/21-ruby-tricks-902.html

From there

7 - Cut down on local variable definitions

Instead of defining a local variable with some initial content (often just an 
empty hash or array), you can instead define it on the go so you can perform 
operations on it at the same time:

(z ||= [])  'test'

2009 Update: This is pretty rancid, to be honest. I've changed my mind; you 
shouldn't be doing this :)

So now that I know this I am still further lost to the point of the initially 
posted code so my kubuntu has ruby so I have run it, and honestly I need 
further definition on what that code was trying to acheive.

sayth@sayth-TravelMate-5740G:~/scripts$ ruby --version
ruby 1.9.3p484 (2013-11-22 revision 43786) [x86_64-linux]
sayth@sayth-TravelMate-5740G:~/scripts$ irb
irb(main):001:0 (z ||= [])  'test'
= [test]
irb(main):002:0 @ins_var ||= nil
= nil
irb(main):003:0 def ins_var
irb(main):004:1 @ins_var ||= nil
irb(main):005:1 end
= nil
irb(main):006:0 def m
irb(main):007:1 @ins_var = val
irb(main):008:1 end
= nil
irb(main):009:0 def m2
irb(main):010:1 ins_var #= val
irb(main):011:1 end
= nil
irb(main):012:0 m
= val
irb(main):013:0 m2
= val

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


Re: Pythonic way to iterate through multidimensional space?

2014-10-08 Thread Gelonida N

On 10/7/2014 1:01 PM, Ned Batchelder wrote:

On 10/7/14 2:10 AM, Gelonida N wrote:


Disadvantage of itertools.product() is, that it makes a copy in memory.
Reason ist, that itertools also makes products of generators (meaning of
objects, that one can't iterate several times through)


There are two use cases, that I occasionaly stumble over:

One is making the product over lists(),
product( list_of_lists )

ex:

product( [ [1,2,3], ['A','B'], ['a', 'b', 'c'] ] )

the other one making a product over a list of functions, which will
create generators

ex:
product( [ lambda: [ 'A', 'B' ], lambda: xrange(3) ] )


I personally would also be interested in a fast generic solution that
can iterate through an N-dimensional array and which does not duplicate
the memory or iterate through a list of generator-factories or however
this would be called.


itertools.product makes a copy of the sequences passed in, but it is a
shallow copy. It doesn't copy the objects in the sequences.  It also
doesn't store the entire product.

If you are calling product(j, k, l, m, n), where len(j)==J, the extra
memory is J+K+L+M+N, which is much smaller than the number of iterations
product will produce.  Are you sure that much extra memory use is a
problem?  How large are your lists that you are product'ing together?



Thanks for the clarification.

You are right. Consumption of a shallow copy of each iterator, should 
not be a problem in the cases that I encountered so far.




I don't understand your point about a list of functions that create
generators?  What is the problem there?

The idea was to even avoid the creation of a shallow copy, by having a 
function, that will return the same generator over and over again (thus 
no need for shallow copy)




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


how to add custom importer after the normal imports

2014-10-08 Thread Gelonida N

Hi,


I just read about sys.meta_path, which allows to install custom 
importers *BEFORE* the default importers.


However I have a use case where I would like to add a custom importer 
*AFTER* all other import methods have failed.


Does anybody know how to do this.

One way of implementing this would be to add the default importer as 
first entry in sys.meta_path. My only problem is, that I don't know how 
to create a 'default-importer', such that I can add it into sys.meta_path


Thanks in advance for any suggestions

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


Re: operator module functions

2014-10-08 Thread Steven D'Aprano
marco.naw...@colosso.nl wrote:

 For me it makes sense. operator.add should be used in a global context
 (I don't know how to express it otherwise). So you provide it with the
 two values that you want to add. The .__add__ variants are bound to a
 particular instance and you provide it with a single value that you want
 to add.

That's not correct. You're misunderstanding me, I'm not talking about the
special dunder methods on classes, e.g. (2).__add__(3) - 5. I'm talking
about *functions* in the operator module:

py import operator
py operator.add(2, 3)
5
py operator.__add__(2, 3)
5

According to the documentation, operator.__add__ is the official function,
and operator.add is just there for convenience. Neither of them is the
special method __add__. But it seems that nobody uses the official
operator.__add__ function, and Terry Reedy says there are no tests for it.



-- 
Steven

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


Re: Another time question

2014-10-08 Thread Grant Edwards
On 2014-10-07, Seymore4Head Seymore4Head@Hotmail.invalid wrote:

 I never really cared enough to ask anyone, but something like my cable
 bill is 98$ a month.  Do companies (in general) consider a month every
 30 days or every time the 14th comes around? 

Either/both.

My pre-pay T-Mobile account is every $30 every 30 days, but they call
it $30 a month.  The T-Mobile post-pay contracts were per calendar
month, and the payment was due on the same date every month.

-- 
Grant Edwards   grant.b.edwardsYow! Can you MAIL a BEAN
  at   CAKE?
  gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Practice question

2014-10-08 Thread Rustom Mody
On Tuesday, October 7, 2014 2:19:39 AM UTC+5:30, Steven D'Aprano wrote:

 I have fewer issues with your conclusion and analogy than I do with the 
 basic premise that there is a connection between Seymore's problem here 
 and the use, or non-use, of print in the interactive interpreter. I don't 
 see how replacing interactive use and/or the use of print with functions 
 containing return statements would help Seymore.

The issue is not only that print is bad but that the interpreter is
good for learning and trying out.

Are these two really unconnected. Lets see... One can

- use print without the interpreter
- use the interpreter without print
- use both

But can one use neither? [Assuming telepathy/ESP etc is disallowed]

So pushing beginners away from print can push them up the learning 
curve more quickly
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Practice question

2014-10-08 Thread Chris Angelico
On Thu, Oct 9, 2014 at 3:14 AM, Rustom Mody rustompm...@gmail.com wrote:
 The issue is not only that print is bad but that the interpreter is
 good for learning and trying out.

 Are these two really unconnected. Lets see... One can

 - use print without the interpreter
 - use the interpreter without print
 - use both

 But can one use neither? [Assuming telepathy/ESP etc is disallowed]

 So pushing beginners away from print can push them up the learning
 curve more quickly

(Please be more clear with your terminology; running Python scripts is
still using the interpreter, it's just not using *interactive* Python.
What you're saying above is all about Python's interactive mode.)

Your conclusion doesn't obviously follow from your preceding
statements. How does pushing people away from print push them up?
Which way is up? Is it up to move from interactive Python to
scripts run from the command line? Or is that down? How does the
avoidance of print push anyone anywhere, anyway?

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


Re: Practice question

2014-10-08 Thread Skip Montanaro
On Wed, Oct 8, 2014 at 11:14 AM, Rustom Mody rustompm...@gmail.com wrote:
 So pushing beginners away from print can push them up the learning
 curve more quickly

Or more quickly discourage them. I still use print for all sorts of
things. In my opinion, there is often no need for fancy loggers,
str.format, or the write method of file-like objects. Print will often
get you a good enough result faster than the other means.

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


Re: Practice question

2014-10-08 Thread Rustom Mody
On Wednesday, October 8, 2014 9:58:11 PM UTC+5:30, Skip Montanaro wrote:
 On Wed, Oct 8, 2014 at 11:14 AM, Rustom Mody  wrote:
  So pushing beginners away from print can push them up the learning
  curve more quickly

 Or more quickly discourage them. I still use print for all sorts of
 things. In my opinion, there is often no need for fancy loggers,
 str.format, or the write method of file-like objects. Print will often
 get you a good enough result faster than the other means.

Well I'm not talking of people like you!!
Nor of more sophisticated tools than print.

I am talking of the fact that an absolute basic sine qua non for
beginners is to be able to structure programs:

- breaking up a complex expression into sub-expressions
- abstracting out a sub-expression into a function with an appropriate
  parameterization
- inverses of the above when the current cut is sub-optimal

etc etc... what is nowadays fashionably called 'refactoring'

And for that the noob needs to learn to write return-ing function
where he currently writes a print-ing function.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: High water Memory fragmentation still a thing?

2014-10-08 Thread bryanjugglercryptographer
Chris Angelico wrote:
 Sure, and that's all well and good. But what I just cited there *is* a
 shipping product. That's a live server that runs a game that I'm admin
 of. So it's possible to do without the resource safety net of periodic
 restarts.

Nice that the non-Python server you administer stayed up for 88 weeks, but that 
doesn't really have anything to do with the issue here. The answer to the OP's 
title question is yes, high-water memory fragmentation is a real thing, in 
most platforms including CPython.

The cited article tells of Celery hitting the problem, and the working solution 
was to roll the celery worker processes. That doesn't mean to tell a human 
administrator to regularly restart the server. It's programmatic and it's a 
reasonably simple and well-established design pattern.

  For an example see the Apache HTTP daemon, particularly the classic 
  pre-forking server. There's a configuration parameter, 
  MaxRequestsPerChild, that sets how many requests a process should answer 
  before terminating.
 
 That assumes that requests can be handled equally by any server
 process - and more so, that there are such things as discrete
 requests. That's true of HTTP, but not of everything. 

It's true of HTTP and many other protocols because they were designed to 
support robust operation even as individual components may fail.

 And even with
 HTTP, if you do long polls [1] then clients might remain connected
 for arbitrary lengths of time; either you have to cut them off when
 you terminate the server process (hopefully that isn't too often, or
 you lose the benefit of long polling), or you retain processes for
 much longer.

If you look at actual long-polling protocols, you'll see that the server 
occasionally closing connections is no problem at all. They're actually 
designed to be robust even against connections that drop without proper 
shutdown.

 Restarting isn't necessary. It's like rebooting a computer: people get
 into the habit of doing it, because it fixes problems, but all that
 means is that it allows you to get sloppy with resource management.

CPython, and for that matter malloc/free, have known problems in resource 
management, such as the fragmentation issue noted here. There are more. Try a 
Google site search for memory leak on http://bugs.python.org/. Do you think 
the last memory leak is fixed now?

From what I've seen, planned process replacement is the primary techniques to 
support long-lived mission-critical services in face of resource management 
flaws. Upon process termination the OS recovers the resources. I love CPython, 
but on this point I trust the Linux kernel much more.

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


Re: operator module functions

2014-10-08 Thread Terry Reedy

On 10/8/2014 6:57 AM, Steven D'Aprano wrote:


According to the documentation, operator.__add__ is the official function,
and operator.add is just there for convenience.


You are paraphrasing The function names are those used for special 
class methods; variants without leading and trailing __ are also 
provided for convenience.  But then there is the following:


10.3.1. Mapping Operators to Functions

This table shows how abstract operations correspond to operator symbols 
in the Python syntax and the functions in the operator module.

Operation   Syntax  Function
Additiona + b   add(a, b)

etc, using the 'convenient' names. I would like to deprecate and 
eventually remove the dunder names.  To me, the duplication is not 
'convenient'.


--
Terry Jan Reedy

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


strange numpy behaviour

2014-10-08 Thread George Trojan

This does not look right:

dilbert@gtrojan python3.4
Python 3.4.1 (default, Jul  7 2014, 15:47:25)
[GCC 4.8.3 20140624 (Red Hat 4.8.3-1)] on linux
Type help, copyright, credits or license for more information.
 import numpy as np
 a=np.ma.array([0, 1], dtype=np.int8, mask=[1, 0])
 a
masked_array(data = [-- 1],
 mask = [ True False],
   fill_value = 99)

 a.data
array([0, 1], dtype=int8)
 a.filled()
array([63,  1], dtype=int8) --- Why 63?


What do you think?

George

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


Re: strange numpy behaviour

2014-10-08 Thread Ian Kelly
On Wed, Oct 8, 2014 at 10:29 AM, George Trojan george.tro...@noaa.gov wrote:
 This does not look right:

 dilbert@gtrojan python3.4
 Python 3.4.1 (default, Jul  7 2014, 15:47:25)
 [GCC 4.8.3 20140624 (Red Hat 4.8.3-1)] on linux
 Type help, copyright, credits or license for more information.
 import numpy as np
 a=np.ma.array([0, 1], dtype=np.int8, mask=[1, 0])
 a
 masked_array(data = [-- 1],
  mask = [ True False],
fill_value = 99)

 a.data
 array([0, 1], dtype=int8)
 a.filled()
 array([63,  1], dtype=int8) --- Why 63?


 What do you think?

The datatype is int8, the fill value is the default of 99, and
99  0xff == 63.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: operator module functions

2014-10-08 Thread Ethan Furman

On 10/08/2014 12:09 PM, Terry Reedy wrote:

On 10/8/2014 6:57 AM, Steven D'Aprano wrote:


According to the documentation, operator.__add__ is the official function,
and operator.add is just there for convenience.


You are paraphrasing The function names are those used for special class 
methods; variants without leading and trailing
__ are also provided for convenience.  But then there is the following:

10.3.1. Mapping Operators to Functions

This table shows how abstract operations correspond to operator symbols in the 
Python syntax and the functions in the
operator module.
Operation Syntax Function
Addition a + b add(a, b)

etc, using the 'convenient' names. I would like to deprecate and eventually 
remove the dunder names.  To me, the
duplication is not 'convenient'.


LOL, no kidding!  The main reason I bother using the operator module is for the readability of not seeing the dunders, 
and the writability of not having to type them.


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


Re: operator module functions

2014-10-08 Thread random832


On Wed, Oct 8, 2014, at 15:38, Ethan Furman wrote:
 LOL, no kidding!  The main reason I bother using the operator module is
 for the readability of not seeing the dunders, 
 and the writability of not having to type them.

I'm not sure what situation you would have to type them (as opposed to
simply a + b) that the operator module would help with.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: operator module functions

2014-10-08 Thread Gelonida N

On 10/8/2014 9:09 PM, Terry Reedy wrote:

On 10/8/2014 6:57 AM, Steven D'Aprano wrote:


According to the documentation, operator.__add__ is the official
function,
and operator.add is just there for convenience.


You are paraphrasing The function names are those used for special
class methods; variants without leading and trailing __ are also
provided for convenience.  But then there is the following:

10.3.1. Mapping Operators to Functions

This table shows how abstract operations correspond to operator symbols
in the Python syntax and the functions in the operator module.
Operation Syntax Function
Addition a + b add(a, b)

etc, using the 'convenient' names. I would like to deprecate and
eventually remove the dunder names.  To me, the duplication is not
'convenient'.




I'd be curious about a proposal to obsolete the double underscore 
functions and just keep operator.add or to just keep the operator +


For me they seem rather distinct, though they are interchangable in 
certain situations.


Perhaps I got something wrong, but all dunder functions are 'magic' 
functions. Many of them mostly should ne used when when overloading 
behaviour or when creating a class which should implement operators.


So for implemetation you use __add__ for using you use the operator +
if you need a

class MyClass(object):
def __init__(self, x, y):
self.x = x
self.y = y

# implements + for a certain type
def __add__(self, other):
return MyClass(self.x + other.x, self.y + other.y)

def __repr__(self):
return (%f,%f) % (self.x, self.y)


a = MyClass(1,2)
b = MyClass(4,5)

print(a)
print(b)
print(a+b)

# operator.add is identical to the + operator ,
# BUT it is a function and can thuss be
# assigned to variables passed as parameter

def dosomething(op, val1, val2):
return op(val1, val2)

print(dosomething(operator.add, 1, 2))
print(dosomething(operator.add, a, b))







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


Re: operator module functions

2014-10-08 Thread Ian Kelly
On Wed, Oct 8, 2014 at 3:05 PM, Gelonida N gelon...@gmail.com wrote:
 On 10/8/2014 9:09 PM, Terry Reedy wrote:

 On 10/8/2014 6:57 AM, Steven D'Aprano wrote:

 According to the documentation, operator.__add__ is the official
 function,
 and operator.add is just there for convenience.


 You are paraphrasing The function names are those used for special
 class methods; variants without leading and trailing __ are also
 provided for convenience.  But then there is the following:

 10.3.1. Mapping Operators to Functions

 This table shows how abstract operations correspond to operator symbols
 in the Python syntax and the functions in the operator module.
 Operation Syntax Function
 Addition a + b add(a, b)

 etc, using the 'convenient' names. I would like to deprecate and
 eventually remove the dunder names.  To me, the duplication is not
 'convenient'.



 I'd be curious about a proposal to obsolete the double underscore functions
 and just keep operator.add or to just keep the operator +

 For me they seem rather distinct, though they are interchangable in certain
 situations.

 Perhaps I got something wrong, but all dunder functions are 'magic'
 functions. Many of them mostly should ne used when when overloading
 behaviour or when creating a class which should implement operators.

This isn't about the dunder *method* names. It's about the naming of
the functions in the operator module, e.g. having both operator.add
and operator.__add__ that are two names for the same function.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How do I check if a string is a prefix of any possible other string that matches a given regex.

2014-10-08 Thread Gregory Ewing

jonathan.slend...@gmail.com wrote:


For each non-accepting state, determine whether it has
any transitions that lead in one or more steps to an accepting state.
Modify the FSM so that each such state is also an accepting state.



Thanks, I'll make every state of the FSM an accepting state.


Not *every* state -- that will give you an FSM that
accepts any string!

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


Re: operator module functions

2014-10-08 Thread Gregory Ewing

Chris Angelico wrote:


operator.add is operator.__add__

True


That doesn't always seem to have been the case, however.
In Python 2.7 and 3.3, I get

 operator.add is operator.__add__
False

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


Re: operator module functions

2014-10-08 Thread Ethan Furman

[redirecting back to the list]

On 10/08/2014 02:23 PM, random...@fastmail.us wrote:

On Wed, Oct 8, 2014, at 15:53, Ethan Furman wrote:

On 10/08/2014 12:49 PM, random...@fastmail.us wrote:

On Wed, Oct 8, 2014, at 15:38, Ethan Furman wrote:


LOL, no kidding!  The main reason I bother using the operator module is
for the readability of not seeing the dunders,
and the writability of not having to type them.


I'm not sure what situation you would have to type them (as opposed to
simply a + b) that the operator module would help with.


unittest springs to mind:

self.assertRaises(TypeError, op.add, obj1, obj2)


Er, my point is, that is not a situation where you would be able to use
obj1.__add__ - you'd have to use the operator module *anyway*, and
therefore aren't using it just to get the convenience of a non-dunder
name.


 self.assertRaises(TypeError, lambda x, y: x+y, obj1, obj2)

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


Re: operator module functions

2014-10-08 Thread Chris Kaynor
On Wed, Oct 8, 2014 at 2:05 PM, Gelonida N gelon...@gmail.com wrote:

 On 10/8/2014 9:09 PM, Terry Reedy wrote:

 On 10/8/2014 6:57 AM, Steven D'Aprano wrote:

  According to the documentation, operator.__add__ is the official
 function,
 and operator.add is just there for convenience.


 You are paraphrasing The function names are those used for special
 class methods; variants without leading and trailing __ are also
 provided for convenience.  But then there is the following:

 10.3.1. Mapping Operators to Functions

 This table shows how abstract operations correspond to operator symbols
 in the Python syntax and the functions in the operator module.
 Operation Syntax Function
 Addition a + b add(a, b)

 etc, using the 'convenient' names. I would like to deprecate and
 eventually remove the dunder names.  To me, the duplication is not
 'convenient'.



 I'd be curious about a proposal to obsolete the double underscore
 functions and just keep operator.add or to just keep the operator +

 For me they seem rather distinct, though they are interchangable in
 certain situations.

 Perhaps I got something wrong, but all dunder functions are 'magic'
 functions. Many of them mostly should ne used when when overloading
 behaviour or when creating a class which should implement operators.

 print(dosomething(operator.add, 1, 2))
 print(dosomething(operator.add, a, b))


The thing being purposed to remove, is that you can also do:

print(dosomething(operator.__add__, 1, 2))
print(dosomething(operator.__add__, a, b))

Not that fact that you can define __add__ in the class, or that
operator.add(a, b) is the same as a + b (all of which are quite useful).

Basically, the operator module has a __add__ function in addition to a
add function, and they are both identical (in fact, they are the same
function object):
 import operator
 operator.add
built-in function add
 operator.__add__
built-in function add
 operator.__add__ is operator.add
True
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: operator module functions

2014-10-08 Thread Ben Finney
random...@fastmail.us writes:

 On Wed, Oct 8, 2014, at 15:38, Ethan Furman wrote:
  The main reason I bother using the operator module is for the
  readability of not seeing the dunders, and the writability of not
  having to type them.

 I'm not sure what situation you would have to type them (as opposed to
 simply a + b) that the operator module would help with.

Any situation where you need to refer to a function. ‘+’ is not a
function, whereas ‘operator.add’ is.

import operator
import functools

add_three = functools.partial(operator.add, 3)

foo = list(range(10))
bar = map(add_three, foo)

The above ‘map’ invocation – which is useful because it allows any
arbitrary one-parameter function to be used – cannot be used with ‘+’,
which is not a function.

Likewise, ‘functools.partial’ requires a function, and ‘+’ is not a
function.

There are countless such uses for the functions in the ‘operator’
module.

-- 
 \  “It is the integrity of each individual human that is in final |
  `\examination. On personal integrity hangs humanity's fate.” |
_o__)   —Richard Buckminster Fuller, _Critical Path_, 1981 |
Ben Finney

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


virtualenv question: include just a few site packages

2014-10-08 Thread Gelonida N

virtualenv has the switch
--system-site-packages (including all system site pacgaes)
and the switch
--no-site-packages (to expclude all site packages)


Does anyone know an easy way to include just a few site-packages?
for example (PySide, but not PyQt)

The reason I'm asking is following.
Some site packages  are sometimes raher huge or sometimes refuse to 
compile on certain hosts.


as these packages are already part of the site packages I'd like to 
include them.


You might wonder why I care whether I have more site packages than I 
need. As long as I don't import them,  I shouldn't care about it.

If I really wanted to replace a version I could use pip install -U.

However sometimes I'd like to have a test environment where want to be 
sure, that no module can find certain other modules. so they should not 
be visible.


at the moment I make some experiments with pyinstaller and the module 
pythonqtbindings. and there I'd like to be sure that no PuQt files end 
up in the generated code.



The only idea, that I have so far is to
run virutalanv with --system-side-packages and to manually remove 
modules I don't want or to
run virtualenv without this switch and to manually add links for site 
packages, taht I want. both options don't really feel right for me.



Is there any other way?









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


Re: operator module functions

2014-10-08 Thread Chris Angelico
On Thu, Oct 9, 2014 at 8:37 AM, Gregory Ewing
greg.ew...@canterbury.ac.nz wrote:
 Chris Angelico wrote:

 operator.add is operator.__add__

 True


 That doesn't always seem to have been the case, however.
 In Python 2.7 and 3.3, I get

 operator.add is operator.__add__
 False

Huh. So it is.

rosuav@sikorsky:~$ python3
Python 3.5.0a0 (default:301b9a58021c, Oct  2 2014, 09:20:24)
[GCC 4.7.2] on linux
Type help, copyright, credits or license for more information.
 import operator
 operator.add, operator.__add__
(built-in function add, built-in function add)

rosuav@sikorsky:~$ python
Python 2.7.3 (default, Mar 13 2014, 11:03:55)
[GCC 4.7.2] on linux2
Type help, copyright, credits or license for more information.
 import operator
 operator.add, operator.__add__
(built-in function add, built-in function __add__)


Presumably they have the same code behind them, just different
function names. But anyway, the fact that it doesn't throw back an
AttributeError proves that both functions do at least exist.

Learn something new every day!

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


Re: operator module functions

2014-10-08 Thread Chris Kaynor
On Wed, Oct 8, 2014 at 3:30 PM, Chris Angelico ros...@gmail.com wrote:

 
 
  That doesn't always seem to have been the case, however.
  In Python 2.7 and 3.3, I get
 
  operator.add is operator.__add__
  False

 Huh. So it is.

 rosuav@sikorsky:~$ python3
 Python 3.5.0a0 (default:301b9a58021c, Oct  2 2014, 09:20:24)
 [GCC 4.7.2] on linux
 Type help, copyright, credits or license for more information.
  import operator
  operator.add, operator.__add__
 (built-in function add, built-in function add)
 
 rosuav@sikorsky:~$ python
 Python 2.7.3 (default, Mar 13 2014, 11:03:55)
 [GCC 4.7.2] on linux2
 Type help, copyright, credits or license for more information.
  import operator
  operator.add, operator.__add__
 (built-in function add, built-in function __add__)
 

 Presumably they have the same code behind them, just different
 function names. But anyway, the fact that it doesn't throw back an
 AttributeError proves that both functions do at least exist.

 Learn something new every day!


I only tried it in Python 3.4, and I got true. Perhaps it was optimized
slightly after 3.3?

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


Re: how to add custom importer after the normal imports

2014-10-08 Thread Ian Kelly
On Wed, Oct 8, 2014 at 4:53 AM, Gelonida N gelon...@gmail.com wrote:
 Hi,


 I just read about sys.meta_path, which allows to install custom importers
 *BEFORE* the default importers.

 However I have a use case where I would like to add a custom importer
 *AFTER* all other import methods have failed.

 Does anybody know how to do this.

 One way of implementing this would be to add the default importer as first
 entry in sys.meta_path. My only problem is, that I don't know how to create
 a 'default-importer', such that I can add it into sys.meta_path

As of CPython 3.3 the default importers are already in sys.meta_path,
so you could just add your custom importer to the end. If you need to
support earlier versions or alternate implementations then this may
not be reliable.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: operator module functions

2014-10-08 Thread Terry Reedy

On 10/8/2014 5:49 PM, Ethan Furman wrote:

[redirecting back to the list]



I'm not sure what situation you would have to type them (as opposed to
simply a + b) that the operator module would help with.


unittest springs to mind:

self.assertRaises(TypeError, op.add, obj1, obj2)


Er, my point is, that is not a situation where you would be able to use
obj1.__add__ - you'd have to use the operator module *anyway*, and
therefore aren't using it just to get the convenience of a non-dunder
name.


  self.assertRaises(TypeError, lambda x, y: x+y, obj1, obj2)


That works, but is a bit harder to type (given the import), more 
confusing to read (the extra ',' that does *not* delimit an argument) 
and adds an extra layer to the call stack with each call.  The extra 
layer *could* make a difference in recursion.


--
Terry Jan Reedy

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


Re: operator module functions

2014-10-08 Thread Ethan Furman

On 10/08/2014 03:46 PM, Terry Reedy wrote:

On 10/8/2014 5:49 PM, Ethan Furman wrote:

[redirecting back to the list]



I'm not sure what situation you would have to type them (as opposed to
simply a + b) that the operator module would help with.


unittest springs to mind:

self.assertRaises(TypeError, op.add, obj1, obj2)


Er, my point is, that is not a situation where you would be able to use
obj1.__add__ - you'd have to use the operator module *anyway*, and
therefore aren't using it just to get the convenience of a non-dunder
name.


  self.assertRaises(TypeError, lambda x, y: x+y, obj1, obj2)


That works, but is a bit harder to type (given the import), more confusing to 
read (the extra ',' that does *not*
delimit an argument) and adds an extra layer to the call stack with each call.  
The extra layer *could* make a
difference in recursion.


Indeed, thanks for the corrections.  I was merely replying to the have to use the 
operator module anyway comment.

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


Toggle

2014-10-08 Thread Seymore4Head
I want to toggle between color=Red and color=Blue
Here is one:
if color == Red:
color = Blue
else:
color = Red
Here is two:
if x = True color = Red
else:
color=Blue
x= not x

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


Re:Toggle

2014-10-08 Thread Dave Angel
Seymore4Head Seymore4Head@Hotmail.invalid Wrote in message:
 I want to toggle between color=Red and color=Blue
 Here is one:
 if color == Red:
 color = Blue
 else:
 color = Red
 Here is two:
 if x = True color = Red
 else:
 color=Blue
 x= not x
 
 Others?
 

One looks like it wrks and two looks like nonsense.   Just what
 are you trying to ask?

-- 
DaveA

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


Re: Toggle

2014-10-08 Thread Mark Lawrence

On 09/10/2014 01:11, Seymore4Head wrote:

I want to toggle between color=Red and color=Blue
Here is one:
 if color == Red:
 color = Blue
 else:
 color = Red
Here is two:
if x = True color = Red
else:
color=Blue
x= not x

Others?



Here http://stackoverflow.com/questions/8381735/toggle-a-value-in-python 
but why couldn't you search in the first place?


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


Re: Toggle

2014-10-08 Thread Steven D'Aprano
Seymore4Head wrote:

 I want to toggle between color=Red and color=Blue
 Here is one:
 if color == Red:
 color = Blue
 else:
 color = Red

Apart from the horrible spelling of colour :-) that seems fine to me. You
might wish to include a comment:

# Assumes that color can only take the values Red or Blue.

just before the toggle code. But even better than a comment is an assertion:

assert color in (Red, Blue)
if color == Red:
color = Blue
else:
color = Red

This makes it a checked comment -- the primary purpose of the assert here
is as a comment, but the interpreter will by default actually check that it
is true (although that can be turned off by the user).

You can find out more about good, and bad, uses of assert here:

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


 Here is two:
 if x = True color = Red
 else:
 color=Blue
 x= not x

That gives SyntaxError. And it's wrong because you are confusing the
*string* T r u e with the constant True. It should be:

assert isinstance(x, bool)
if x:  # don't write if x == True since that is redundant
color = 'Red'
else:
color = 'Blue'
x = not x

 
 Others?

color = (Red, Blue)[color == Red]

color = {Red: Blue, Blue: Red}[color]

color = Red if color == Blue else Blue


There may be even more complicated, obscure or obfuscated versions possible.


-- 
Steven

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


Re: operator module functions

2014-10-08 Thread Ned Batchelder

On 10/8/14 5:49 PM, Ethan Furman wrote:

[redirecting back to the list]

On 10/08/2014 02:23 PM, random...@fastmail.us wrote:

On Wed, Oct 8, 2014, at 15:53, Ethan Furman wrote:

On 10/08/2014 12:49 PM, random...@fastmail.us wrote:

On Wed, Oct 8, 2014, at 15:38, Ethan Furman wrote:


LOL, no kidding!  The main reason I bother using the operator
module is
for the readability of not seeing the dunders,
and the writability of not having to type them.


I'm not sure what situation you would have to type them (as opposed to
simply a + b) that the operator module would help with.


unittest springs to mind:

self.assertRaises(TypeError, op.add, obj1, obj2)


Er, my point is, that is not a situation where you would be able to use
obj1.__add__ - you'd have to use the operator module *anyway*, and
therefore aren't using it just to get the convenience of a non-dunder
name.


  self.assertRaises(TypeError, lambda x, y: x+y, obj1, obj2)


Don't forget, in 2.7 you can do:

with self.assertRaises(TypeError):
obj1 + obj2

--
Ned Batchelder, http://nedbatchelder.com

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


Re: Toggle

2014-10-08 Thread Ben Finney
Seymore4Head Seymore4Head@Hotmail.invalid writes:

 I want to toggle between color=Red and color=Blue

It's good to cultivate ongoing familiarity with the standard library
URL:https://docs.python.org/3/library/itertools.html#itertools.cycle
so that you can make use of wheels already invented and maintained::

import itertools

colours = [Red, Blue]
colour_cycle = itertools.cycle(colours)

next(colour_cycle)# → Red
next(colour_cycle)# → Blue
next(colour_cycle)# → Red
next(colour_cycle)# → Blue
next(colour_cycle)# → Red

for colour in colour_cycle:
# … loops indefinitely
# with ‘colour’ bound to each value in turn …

-- 
 \  “My roommate got a pet elephant. Then it got lost. It's in the |
  `\  apartment somewhere.” —Steven Wright |
_o__)  |
Ben Finney

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


Re: Toggle

2014-10-08 Thread Rustom Mody
On Thursday, October 9, 2014 7:12:41 AM UTC+5:30, Ben Finney wrote:
 Seymore4Head writes:

  I want to toggle between color=Red and color=Blue

 It's good to cultivate ongoing familiarity with the standard library

And language. In recent python3:

 class Color(Enum):
...   Red = 0
...   Blue = 1
... 
 Color.Red
Color.Red: 0
 print (Color.Red)
Color.Red

# Not sure what to make of that distinction...

 c=Color.Red
 c = Color.Blue if c==Color.Red else Color.Red
 c
Color.Blue: 1
 

 # Better
 def toggle(c): return Color.Blue if c==Color.Red else Color.Red
... 
 toggle(c)
Color.Blue: 1
 toggle(c)
Color.Blue: 1

# which means the c has not changed



 toggle(toggle(c))
Color.Red: 0


[Yeah and like Steven I find the colour of 'color' colourless]
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Toggle

2014-10-08 Thread Mark Lawrence

On 09/10/2014 02:25, Mark Lawrence wrote:

On 09/10/2014 01:11, Seymore4Head wrote:

I want to toggle between color=Red and color=Blue
Here is one:
 if color == Red:
 color = Blue
 else:
 color = Red
Here is two:
if x = True color = Red
else:
color=Blue
x= not x

Others?



Here http://stackoverflow.com/questions/8381735/toggle-a-value-in-python
but why couldn't you search in the first place?



When I first read this I was extremely jealous of the originator but 
having used it umpteen times I'm still extremely jealous of the 
originator!!!  Why doesn't my mind work like his? :)


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


Re: Toggle

2014-10-08 Thread random832
On Wed, Oct 8, 2014, at 23:02, Mark Lawrence wrote:
 When I first read this I was extremely jealous of the originator but 
 having used it umpteen times I'm still extremely jealous of the 
 originator!!!  Why doesn't my mind work like his? :)

You could also keep the ints in two variables and do a ^= b : b ^= a : a
^= b. Or use a, b = b, a. What I don't see in that answer is any
benchmarking support for his sweeping assertions of what is the fastest
version.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Toggle

2014-10-08 Thread Chris Angelico
On Thu, Oct 9, 2014 at 2:54 PM,  random...@fastmail.us wrote:
 On Wed, Oct 8, 2014, at 23:02, Mark Lawrence wrote:
 When I first read this I was extremely jealous of the originator but
 having used it umpteen times I'm still extremely jealous of the
 originator!!!  Why doesn't my mind work like his? :)

 You could also keep the ints in two variables and do a ^= b : b ^= a : a
 ^= b. Or use a, b = b, a. What I don't see in that answer is any
 benchmarking support for his sweeping assertions of what is the fastest
 version.

Possibly because it doesn't matter. Who cares how fast it is? All you
need to do is go from either of two states to the other. If the
performance of that has any impact whatsoever on your code, there's
something wrong with your design.

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


Re: Toggle

2014-10-08 Thread Steven D'Aprano
On Wed, 08 Oct 2014 19:34:30 -0700, Rustom Mody wrote:

 Color.Red
 Color.Red: 0
 print (Color.Red)
 Color.Red
 
 # Not sure what to make of that distinction...

That's because the interactive interpreter displays the repr() of objects 
(except for None, which it suppresses), while print outputs the str() of 
them.

py class Test:
... def __repr__(self): return repr
... def __str__(self): return str
... 
py x = Test()
py x
repr
py print(x)
str

That's an old, old part of Python, going back to Python 1.5 or older, if 
I remember correctly.



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


Re: Toggle

2014-10-08 Thread Gregory Ewing

Seymore4Head wrote:

I want to toggle between color=Red and color=Blue


toggle = {Red: Blue, Blue: Red}
color = toggle[color]
--
https://mail.python.org/mailman/listinfo/python-list


Re: Toggle

2014-10-08 Thread Travis Griggs

On Oct 8, 2014, at 9:57 PM, Gregory Ewing greg.ew...@canterbury.ac.nz wrote:

 Seymore4Head wrote:
 I want to toggle between color=Red and color=Blue


Don’t forget polymorphic dispatch…

class Red(object):
def toggle(self):
return Blue()

class Blue(object):
def toggle(self):
return Red()


Blue().toggle().toggle().toggle().toggle().toggle() :)

--
Travis Griggs
Objologist
Some of them wanted to sell me snake oil and I'm not necessarily going to 
dismiss all of these, as I have never found a rusty snake. --Terry Pratchett

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


Re: Toggle

2014-10-08 Thread Rustom Mody
On Thursday, October 9, 2014 10:26:41 AM UTC+5:30, Steven D'Aprano wrote:
 On Wed, 08 Oct 2014 19:34:30 -0700, Rustom Mody wrote:

  Color.Red
  print (Color.Red)
  Color.Red
  # Not sure what to make of that distinction...

 That's because the interactive interpreter displays the repr() of objects 
 (except for None, which it suppresses), while print outputs the str() of 
 them.

Yeah...

What I meant to wonder upon was: Is this behavior what the pro-print or the
anti-print folks like?

In any case that the P in REPL is not *exactly* the same as print
(or equivalently the distinction between str and repr) makes for some
intricate noob confusions.

BTW is there some flag that can make them identical?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Toggle

2014-10-08 Thread Chris Angelico
On Thu, Oct 9, 2014 at 4:39 PM, Rustom Mody rustompm...@gmail.com wrote:
 On Thursday, October 9, 2014 10:26:41 AM UTC+5:30, Steven D'Aprano wrote:
 On Wed, 08 Oct 2014 19:34:30 -0700, Rustom Mody wrote:

  Color.Red
  print (Color.Red)
  Color.Red
  # Not sure what to make of that distinction...

 That's because the interactive interpreter displays the repr() of objects
 (except for None, which it suppresses), while print outputs the str() of
 them.

 Yeah...

 What I meant to wonder upon was: Is this behavior what the pro-print or the
 anti-print folks like?

 In any case that the P in REPL is not *exactly* the same as print
 (or equivalently the distinction between str and repr) makes for some
 intricate noob confusions.

 BTW is there some flag that can make them identical?

I haven't used a proprinter since our XL24E died. Never used an
antiprinter, myself.

Here's how to make print() output the repr() of something:

_ORIG_PRINT = print
def print(*args, **kw):
return _ORIG_PRINT(*(repr(arg) for arg in args), **kw)

But what's the point?

(Also: Have fun backporting that to 2.5, it won't be easy.)

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


[issue22477] GCD in Fractions

2014-10-08 Thread gladman

gladman added the comment:

You might be right that it is not worth adding the ability to handle a variable 
number of parameters in the new gcd.  But this depends on whether you are right 
that this would add a significant burden to the implementation.  I am not sure 
that it would.

But for pure Python implementations of gcd and gcdm:

def gcd(a, b):
  while b:
a, b = b, a % b
  return a

def gcdm(a, *r):
  for b in r:
while b:
  a, b = b, a % b
  return a

using the second of these alone when compared with the first plus reduce on a 
1 length sequence of random numbers in 0 = r  10 ** 12 gives speed 
improvement of over 25%.  

And, since we are looking for speed improvements, a further possible 25% is a 
worthwhile gain for a common pattern of gcd use.  Which is why I believe it is 
worth asking the question.

--

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



[issue22524] PEP 471 implementation: os.scandir() directory scanning function

2014-10-08 Thread Antoine Pitrou

Antoine Pitrou added the comment:

I agree that having a high-level wrapper around a low-level C primitive would 
be cool, but someone has to experiment on that to find out how much performance 
it would cost.

You may want to have the C primitive return results in batches (of e.g. 10 or 
100 entries) to limit the overhead, btw.

--

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



[issue22576] ftplib documentation gives a wrong argument name for storbinary

2014-10-08 Thread Roundup Robot

Roundup Robot added the comment:

New changeset 4cc584d47c7d by Berker Peksag in branch '3.4':
Issue #22576: Fix signatures of FTP.storbinary() and FTP.storlines() methods.
https://hg.python.org/cpython/rev/4cc584d47c7d

New changeset f21f0de30544 by Berker Peksag in branch 'default':
Issue #22576: Fix signatures of FTP.storbinary() and FTP.storlines() methods.
https://hg.python.org/cpython/rev/f21f0de30544

--
nosy: +python-dev

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



[issue22576] ftplib documentation gives a wrong argument name for storbinary

2014-10-08 Thread Berker Peksag

Berker Peksag added the comment:

Fixed. Thanks for the report, Derek.

--
assignee: docs@python - berker.peksag
nosy: +berker.peksag
resolution:  - fixed
stage:  - resolved
status: open - closed
versions: +Python 3.4, Python 3.5 -Python 3.3

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



[issue22577] local variable changes lost after pdb jump command

2014-10-08 Thread Xavier de Gaye

New submission from Xavier de Gaye:

With the following pdb_jump.py script:

def foo(x):
import pdb; pdb.set_trace()
lineno = 3
lineno = 4

foo(1)


The change made to 'x' is lost after a jump to line 4:

$ ./python ~/tmp/test/pdb_jump.py
 ~/tmp/test/pdb_jump.py(3)foo()
- lineno = 3
(Pdb) x = 123
(Pdb) jump 4
 ~/tmp/test/pdb_jump.py(4)foo()
- lineno = 4
(Pdb) x
1
(Pdb)


The problem is that the Bdb format_stack_entry() method refers to 
frame.f_locals and thus overwrites the changes made to the f_locals dictionary 
as the f_locals dictionary is updated from the actual frame locals whenever the 
f_locals accessor is called as stated in a comment of the Pdb setup() method.

--
components: Library (Lib)
messages: 228783
nosy: georg.brandl, xdegaye
priority: normal
severity: normal
status: open
title: local variable changes lost after pdb jump command
type: behavior
versions: Python 3.4, Python 3.5

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



[issue22524] PEP 471 implementation: os.scandir() directory scanning function

2014-10-08 Thread STINNER Victor

STINNER Victor added the comment:

 You may want to have the C primitive return results in batches (of e.g. 10 or 
 100 entries) to limit the overhead, btw.

Ah yes, good idea. I read that internally readdir() also fetchs many
entries in a single syscall (prefetch / readahead, I don't know how
to call that).

--

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



[issue22181] os.urandom() should use Linux 3.17 getrandom() syscall

2014-10-08 Thread Christian Heimes

Christian Heimes added the comment:

Let's not be early adopters here. I suggest we wait until glibc has a proper 
interface.

--

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



[issue22524] PEP 471 implementation: os.scandir() directory scanning function

2014-10-08 Thread Ben Hoyt

Ben Hoyt added the comment:

Thanks for the initial response and code review, Victor. I'll take a look and 
respond further in the next few days.

In the meantime, however, I'm definitely open to splitting scandir out into its 
own C file. This will mean a little refactoring (making some functions 
public/non-static).

Based on the numbers so far, I'm not so keen on implementing just the sys calls 
in C and the rest in Python. I already do basically this with ctypes in the 
scandir module, and it's slowish. I'll send proper numbers through soon, but 
here's what I remember from running benchmark.py on my Windows laptop with SSD 
drive:

ctypes version: os.walk() 9x faster with scandir
CPython 3.5 C version (debug): os.walk() 24x faster with scandir
CPython 3.5 C version (release): os.walk() 55x faster with scandir

So you do get a lot of speedup from just the ctypes version, but you get a lot 
more (55/9 = 6x more here) by using the all-C version. Again, these numbers are 
from memory -- I'll send exact ones later.

One of the problems is that creating the DirEntry objects and calling their 
methods is fairly expensive, and if this is all done in Python, you lose a lot. 
I believe scandir() would end up being slower than listdir() in many cases.

--

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



[issue22578] Add addition attributes to re.error

2014-10-08 Thread Serhiy Storchaka

New submission from Serhiy Storchaka:

Proposed patch adds additional attributes to the re.error exception: msg, 
pattern, pos, colno, lineno. It also adds helpful information to error message.

Examples:

 re.compile(rabc\u123)
Traceback (most recent call last):
  File stdin, line 1, in module
  File /home/serhiy/py/cpython/Lib/re.py, line 220, in compile
return _compile(pattern, flags)
  File /home/serhiy/py/cpython/Lib/re.py, line 287, in _compile
p = sre_compile.compile(pattern, flags)
  File /home/serhiy/py/cpython/Lib/sre_compile.py, line 465, in compile
p = sre_parse.parse(p, flags)
  File /home/serhiy/py/cpython/Lib/sre_parse.py, line 797, in parse
p = _parse_sub(source, pattern, 0)
  File /home/serhiy/py/cpython/Lib/sre_parse.py, line 387, in _parse_sub
itemsappend(_parse(source, state))
  File /home/serhiy/py/cpython/Lib/sre_parse.py, line 767, in _parse
code = _escape(source, this, state)
  File /home/serhiy/py/cpython/Lib/sre_parse.py, line 378, in _escape
raise source.error(bogus escape: %s % repr(escape), len(escape))
sre_constants.error: bogus escape: '\\u123' at position 3
 re.compile(
... (?x)
... .++
... )
Traceback (most recent call last):
  File stdin, line 4, in module
  File /home/serhiy/py/cpython/Lib/re.py, line 220, in compile
return _compile(pattern, flags)
  File /home/serhiy/py/cpython/Lib/re.py, line 287, in _compile
p = sre_compile.compile(pattern, flags)
  File /home/serhiy/py/cpython/Lib/sre_compile.py, line 465, in compile
p = sre_parse.parse(p, flags)
  File /home/serhiy/py/cpython/Lib/sre_parse.py, line 797, in parse
p = _parse_sub(source, pattern, 0)
  File /home/serhiy/py/cpython/Lib/sre_parse.py, line 387, in _parse_sub
itemsappend(_parse(source, state))
  File /home/serhiy/py/cpython/Lib/sre_parse.py, line 602, in _parse
source.tell() - here + len(this))
sre_constants.error: multiple repeat at position 16 (line 3, column 7)

See also PEP 473, issue19361 and issue22364.

--
files: re_error_attrs.patch
keywords: patch
messages: 228787
nosy: serhiy.storchaka
priority: normal
severity: normal
status: open
title: Add addition attributes to re.error
Added file: http://bugs.python.org/file36834/re_error_attrs.patch

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



[issue22578] Add addition attributes to re.error

2014-10-08 Thread Serhiy Storchaka

Changes by Serhiy Storchaka storch...@gmail.com:


--
components: +Regular Expressions
nosy: +ezio.melotti, mrabarnett, pitrou
stage:  - patch review
type:  - enhancement
versions: +Python 3.5

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



[issue22578] Add additional attributes to re.error

2014-10-08 Thread Antoine Pitrou

Changes by Antoine Pitrou pit...@free.fr:


--
title: Add addition attributes to re.error - Add additional attributes to 
re.error

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



[issue22578] Add additional attributes to re.error

2014-10-08 Thread Antoine Pitrou

Antoine Pitrou added the comment:

Sounds ok, but it would be nice to add some tests.

--

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



[issue22579] Posix module init function name should not be compiler-dependent

2014-10-08 Thread Jeffrey Armstrong

New submission from Jeffrey Armstrong:

The determination of the name of the posix module's initialization function (at 
Modules/posixmodule.c:12055)  is currently dependent on the compiler being 
used.  For MSVC, Watcom, or Borland, the name is defined as PyInit_nt.  
However, both Open Watcom and Borland have shipped compilers for GNU/Linux (and 
other platforms), making determining the posix module initialization function 
based on compiler incorrect.

Most other places in Modules/posixmodule.c correctly use the MS_WINDOWS 
preprocessor definition to determine if Windows routines should be used.  
Naming the intialization function for the posix module should be dependent on 
this as well rather than compiler identifiers.  

Linking the interpreter natively with Open Watcom fails under GNU/Linux due to 
PyInit_posix being undefined.  This occurs because of the reasons described 
above.  The patch included corrects the issue.

--
components: Interpreter Core
files: posix_init.patch
keywords: patch
messages: 228789
nosy: Jeffrey.Armstrong
priority: normal
severity: normal
status: open
title: Posix module init function name should not be compiler-dependent
type: compile error
versions: Python 3.4
Added file: http://bugs.python.org/file36835/posix_init.patch

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



[issue22181] os.urandom() should use Linux 3.17 getrandom() syscall

2014-10-08 Thread 700eb415

700eb415 added the comment:

OpenBSD already provides high quality pseudorandom numbers from arc4random(). I 
don't think this would make us early adopters since it has been around for 
some time on this platform.

It's also worth mentioning that getentropy() is not recommended in use for 
normal code as per stated in the man page. arc4random() is recommended, but 
there may be a reason the first poster has recommended getentropy()

--

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



[issue22181] os.urandom() should use Linux 3.17 getrandom() syscall

2014-10-08 Thread Arfrever Frehtes Taifersar Arahesis

Changes by Arfrever Frehtes Taifersar Arahesis arfrever@gmail.com:


--
nosy: +Arfrever

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



[issue22181] os.urandom() should use Linux 3.17 getrandom() syscall

2014-10-08 Thread Antoine Pitrou

Antoine Pitrou added the comment:

This issue is about Linux support. Does the glibc have arc4random? I can't find 
it on my Ubuntu 13.10 system.

--
nosy: +pitrou

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



[issue22181] os.urandom() should use Linux 3.17 getrandom() syscall

2014-10-08 Thread Alex Gaynor

Alex Gaynor added the comment:

As I said on the other ticket, using arc4random() indiscriminately would be a 
very poor idea, on some platforms (such as OS X) arc4random() really does use 
ARC4, which means there are serious security concerns with it.

--

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



[issue22578] Add additional attributes to re.error

2014-10-08 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

 Sounds ok, but it would be nice to add some tests.

Thank you. Here is a patch with added test.

--
Added file: http://bugs.python.org/file36836/re_error_attrs2.patch

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22578
___diff -r f21f0de30544 Doc/library/re.rst
--- a/Doc/library/re.rstWed Oct 08 13:15:36 2014 +0300
+++ b/Doc/library/re.rstWed Oct 08 17:19:56 2014 +0300
@@ -726,13 +726,36 @@ form.
Clear the regular expression cache.
 
 
-.. exception:: error
+.. exception:: error(msg, pattern=None, pos=None)
 
Exception raised when a string passed to one of the functions here is not a
valid regular expression (for example, it might contain unmatched 
parentheses)
or when some other error occurs during compilation or matching.  It is 
never an
-   error if a string contains no match for a pattern.
+   error if a string contains no match for a pattern.  The error instance has
+   the following additional attributes:
 
+   .. attribute:: msg
+
+  The unformatted error message
+
+   .. attribute:: pattern
+
+  The regular expression pattern.
+
+   .. attribute:: pos
+
+  The index of *pattern* where compilation failed
+
+   .. attribute:: lineno
+
+  The line corresponding to *pos*
+
+   .. attribute:: colno
+
+  The column corresponding to *pos*
+
+   .. versionchanged:: 3.5
+  Added additional attributes.
 
 .. _re-objects:
 
diff -r f21f0de30544 Lib/sre_constants.py
--- a/Lib/sre_constants.py  Wed Oct 08 13:15:36 2014 +0300
+++ b/Lib/sre_constants.py  Wed Oct 08 17:19:56 2014 +0300
@@ -21,8 +21,37 @@ from _sre import MAXREPEAT, MAXGROUPS
 # should this really be here?
 
 class error(Exception):
-pass
+def __init__(self, msg, pattern=None, pos=None):
+self.msg = msg
+self.pattern = pattern
+self.pos = pos
+if pattern is not None and pos is not None:
+msg = '%s at position %d' % (msg, pos)
+if isinstance(pattern, str):
+newline = '\n'
+else:
+newline = b'\n'
+self.lineno = pattern.count(newline, 0, pos) + 1
+if self.lineno == 1:
+self.colno = pos + 1
+else:
+self.colno = pos - pattern.rindex(newline, 0, pos)
+msg = '%s (line %d, column %d)' % (msg, self.lineno, 
self.colno)
+else:
+self.lineno = self.colno = None
+super().__init__(msg)
 
+def linecol(doc, pos):
+if isinstance(pattern, str):
+newline = '\n'
+else:
+newline = b'\n'
+lineno = pattern.count(newline, 0, pos) + 1
+if lineno == 1:
+colno = pos + 1
+else:
+colno = pos - doc.rindex(newline, 0, pos)
+return lineno, colno
 # operators
 
 FAILURE = failure
diff -r f21f0de30544 Lib/sre_parse.py
--- a/Lib/sre_parse.py  Wed Oct 08 13:15:36 2014 +0300
+++ b/Lib/sre_parse.py  Wed Oct 08 17:19:56 2014 +0300
@@ -207,7 +207,8 @@ class Tokenizer:
 try:
 c = self.string[self.index + 1]
 except IndexError:
-raise error(bogus escape (end of line))
+self.next = None
+raise self.error(bogus escape (end of line), 0)
 if not self.istext:
 c = chr(c)
 char = char + c
@@ -233,9 +234,13 @@ class Tokenizer:
 self.__next()
 return result
 def tell(self):
-return self.index, self.next
+return self.index - len(self.next or '')
 def seek(self, index):
-self.index, self.next = index
+self.index = index
+self.__next()
+
+def error(self, msg, offset):
+return error(msg, self.string, self.tell() - offset)
 
 # The following three functions are not used in this module anymore, but we 
keep
 # them here (with DeprecationWarnings) for backwards compatibility.
@@ -299,8 +304,8 @@ def _class_escape(source, escape):
 escape += source.getwhile(2, OCTDIGITS)
 c = int(escape[1:], 8)
 if c  0o377:
-raise error('octal escape value %r outside of '
-'range 0-0o377' % escape)
+raise source.error('octal escape value %r outside of '
+   'range 0-0o377' % escape, len(escape))
 return LITERAL, c
 elif c in DIGITS:
 raise ValueError
@@ -308,7 +313,7 @@ def _class_escape(source, escape):
 return LITERAL, ord(escape[1])
 except ValueError:
 pass
-raise error(bogus escape: %s % repr(escape))
+raise source.error(bogus escape: %s % repr(escape), len(escape))
 
 def _escape(source, escape, state):
 # handle escape code in expression
@@ -354,21 +359,23 @@ def _escape(source, escape, state):
 escape = escape + 

[issue22181] os.urandom() should use Linux 3.17 getrandom() syscall

2014-10-08 Thread 700eb415

700eb415 added the comment:

While I agree it may not be wise to use arc4random() globally, OpenBSD is 
unlikely to create a duplicate interface since it's already available.

Python is currently unusable in chroots on that platform without reducing the 
security of the host partition by removing the nodev mount flag.

I feel like there must be a good solution to this.

--

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



[issue22181] os.urandom() should use Linux 3.17 getrandom() syscall

2014-10-08 Thread Antoine Pitrou

Antoine Pitrou added the comment:

Since this is a Linux-specific issue (see the title), you should create a 
separate issue for OpenBSD support. Bonus points if you want to submit a patch 
as well :-)

--

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



[issue7830] Flatten nested functools.partial

2014-10-08 Thread Alexander Belopolsky

Alexander Belopolsky added the comment:

I've updated the patch.

--
keywords: +patch
Added file: http://bugs.python.org/file36837/issue7830-2.diff

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



[issue22580] PyUnicode_Tailmatch documentation does not match signature

2014-10-08 Thread Josh Ayers

New submission from Josh Ayers:

The documentation for PyUnicode_Tailmatch says it returns an int:
https://docs.python.org/3/c-api/unicode.html?highlight=pyunicode_tailmatch#c.PyUnicode_Tailmatch


However, the include file shows it returns Py_ssize_t:
https://hg.python.org/cpython/file/f21f0de30544/Include/unicodeobject.h#l1952

--
components: Unicode
messages: 228797
nosy: Josh.Ayers, ezio.melotti, haypo
priority: normal
severity: normal
status: open
title: PyUnicode_Tailmatch documentation does not match signature
versions: Python 3.3

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



[issue11664] Add patch method to unittest.TestCase

2014-10-08 Thread Julien Pagès

Julien Pagès added the comment:

Hi all,

I would like to contribute to Python and I'm interested in working on this. I 
have few questions (I hope you don't mind that I ask here):

 - is this issue still open and needed ?
 - if yes, do I have to work from 3.3 branch, as stated in the issue Versions 
field, or in the default one ?

--
nosy: +parkouss

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



[issue22581] Other mentions of the buffer protocol

2014-10-08 Thread Serhiy Storchaka

New submission from Serhiy Storchaka:

In addition to issue16518. There are other non-fixed messages (may be 
introduced after 3.3):

 b''.join([''])
Traceback (most recent call last):
  File stdin, line 1, in module
TypeError: sequence item 0: expected bytes, bytearray, or an object with the 
buffer interface, str found
 str(42, 'utf8')
Traceback (most recent call last):
  File stdin, line 1, in module
TypeError: coercing to str: need bytes, bytearray or buffer-like object, int 
found
 import array; array.array('B').frombytes(array.array('I'))
Traceback (most recent call last):
  File stdin, line 1, in module
TypeError: string/buffer of bytes required.
 import socket; print(socket.socket.sendmsg.__doc__)
sendmsg(buffers[, ancdata[, flags[, address]]]) - count

Send normal and ancillary data to the socket, gathering the
non-ancillary data from a series of buffers and concatenating it into
a single message.  The buffers argument specifies the non-ancillary
data as an iterable of buffer-compatible objects (e.g. bytes objects).
The ancdata argument specifies the ancillary data (control messages)
as an iterable of zero or more tuples (cmsg_level, cmsg_type,
cmsg_data), where cmsg_level and cmsg_type are integers specifying the
protocol level and protocol-specific type respectively, and cmsg_data
is a buffer-compatible object holding the associated data.  The flags
argument defaults to 0 and has the same meaning as for send().  If
address is supplied and not None, it sets a destination address for
the message.  The return value is the number of bytes of non-ancillary
data sent.

And there are several mentions of buffer-like or buffer-compatible in the 
documentation.

--
assignee: docs@python
components: Documentation
keywords: easy
messages: 228799
nosy: chris.jerdonek, docs@python, eric.araujo, ezio.melotti, flox, 
georg.brandl, pitrou, python-dev, r.david.murray, rhettinger, serhiy.storchaka, 
skrah, terry.reedy
priority: normal
severity: normal
stage: needs patch
status: open
title: Other mentions of the buffer protocol

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



[issue22327] test_gdb failures on Ubuntu 14.10

2014-10-08 Thread Matěj Stuchlík

Matěj Stuchlík added the comment:

FYI I'm seeing the error with the new 3.4.2 release as well.

https://kojipkgs.fedoraproject.org//work/tasks/599/7800599/build.log

--

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



[issue11664] Add patch method to unittest.TestCase

2014-10-08 Thread Antoine Pitrou

Antoine Pitrou added the comment:

Hi Julien and welcome,

 - is this issue still open and needed ?

Yes and perhaps. I have no opinion on whether it is necessary, but other 
people seem to think it's useful.

 - if yes, do I have to work from 3.3 branch, as stated in the issue 
 Versions field, or in the default one ?

No, you should work with the default branch. Other branches only receive bug 
fixes, not improvements such as this.

If you haven't yet done so, you may also take a look at the devguide:
https://docs.python.org/devguide/

--
nosy: +pitrou, rbcollins

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



[issue11664] Add patch method to unittest.TestCase

2014-10-08 Thread Antoine Pitrou

Changes by Antoine Pitrou pit...@free.fr:


--
assignee: michael.foord - 
versions: +Python 3.5 -Python 3.3

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



[issue22462] Modules/pyexpat.c violates PEP 384

2014-10-08 Thread Roundup Robot

Roundup Robot added the comment:

New changeset 5433ef907e4f by Antoine Pitrou in branch '3.4':
Issue #22462: Fix pyexpat's creation of a dummy frame to make it appear in 
exception tracebacks.
https://hg.python.org/cpython/rev/5433ef907e4f

New changeset f2f13aeb590a by Antoine Pitrou in branch 'default':
Issue #22462: Fix pyexpat's creation of a dummy frame to make it appear in 
exception tracebacks.
https://hg.python.org/cpython/rev/f2f13aeb590a

--
nosy: +python-dev

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



[issue22542] Use syscall (eg. arc4random or getentropy) rather than /dev/urandom when possible

2014-10-08 Thread 700eb415

700eb415 added the comment:

I'm reopening this for now as advised from the Linux getrandom() thread.

I agree we should not be using arc4random() blindly. However, in the long run 
it is a necessary change at least on OpenBSD. OpenBSD is not likely to create 
another syscall to avoid portability problems with OS X, so IMO it's best to 
utilize the existing calls on the system.

I'll work on some portable way of deterministically enabling it when needed and 
put a patch out for review. I think the payoff would be good when taking into 
account the security implications and cases where there are no available file 
descriptors.

Hopefully this could then be used as a template for getrandom() when 
implemented on Linux.

--
status: closed - open
versions: +Python 3.5 -Python 3.3

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



[issue22542] Use syscall (eg. arc4random or getentropy) rather than /dev/urandom when possible

2014-10-08 Thread Antoine Pitrou

Changes by Antoine Pitrou pit...@free.fr:


--
components: +Interpreter Core -Build
resolution: duplicate - 
stage:  - needs patch
type:  - enhancement

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



[issue22542] Use arc4random under OpenBSD for os.urandom()

2014-10-08 Thread Antoine Pitrou

Changes by Antoine Pitrou pit...@free.fr:


--
title: Use syscall (eg. arc4random or getentropy) rather than /dev/urandom when 
possible - Use arc4random under OpenBSD for os.urandom()

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



[issue22526] file iteration SystemError for huge lines (2GiB+)

2014-10-08 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Could anyone please test it on Windows?

--

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



[issue22462] Modules/pyexpat.c violates PEP 384

2014-10-08 Thread Antoine Pitrou

Antoine Pitrou added the comment:

Patch pushed. I've kept the changes together :) Hopefully there won't be any 
ctypes regression.

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

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



[issue11664] Add patch method to unittest.TestCase

2014-10-08 Thread Julien Pagès

Julien Pagès added the comment:

Thanks Antoine for the link, and the quick answer;

It seems that it is a sensible subject, adding or not this method, and what it 
should do. I wrote the patch anyway,  but I must confess that somewhere it 
feels strange to me to add such a method in TestCase class.

Nevertheless, it could be useful, and I will let other people decide this. :)

--
Added file: http://bugs.python.org/file36838/issue-11664.patch

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



[issue22550] issubclass can fail after module reloading

2014-10-08 Thread Serhiy Storchaka

Changes by Serhiy Storchaka storch...@gmail.com:


--
resolution:  - wont fix
stage:  - resolved
status: open - closed

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



[issue22582] Segmentation fault with string concatenation

2014-10-08 Thread Kevin Dyer

Kevin Dyer added the comment:

The following can be used to generate a file called ```mega_concat.py```:
```python
N = 2**17
my_array = []
for i in range(N):
  my_array.append(\\)
print '+'.join(my_array)
```

Then:

```console
$ python mega_concat.py 
Segmentation fault (core dumped)
$ python3 mega_concat.py 
RuntimeError: maximum recursion depth exceeded during compilation
```

Trying to debug this and it seems like it's a simple out-of-memory issue.

--
resolution:  - duplicate
status: open - closed

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



[issue22582] Segmentation fault with string concatenation

2014-10-08 Thread Kevin Dyer

New submission from Kevin Dyer:

The following can be used to generate a file called ```mega_concat.py```:
```python
N = 2**17
my_array = []
for i in range(N):
  my_array.append(\\)
print '+'.join(my_array)
```

Then:

```console
$ python mega_concat.py 
Segmentation fault (core dumped)
$ python3 mega_concat.py 
RuntimeError: maximum recursion depth exceeded during compilation
```

Trying to debug this and it seems like it's a simple out-of-memory issue.

--
components: Interpreter Core
messages: 228807
nosy: Kevin.Dyer
priority: normal
severity: normal
status: open
title: Segmentation fault with string concatenation
versions: Python 2.7

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



[issue22583] Segmentation fault with string concatenation

2014-10-08 Thread Kevin Dyer

New submission from Kevin Dyer:

The following can be used to generate a file called mega_concat.py:

N = 2**17
my_array = []
for i in range(N):
  my_array.append(\\)
print '+'.join(my_array)

Then, on Ubuntu 14.04, 32-bit:

$ python mega_concat.py 
Segmentation fault (core dumped)
$ python3 mega_concat.py 
RuntimeError: maximum recursion depth exceeded during compilation

Seems like this is a simple out-of-memory issue.

--
components: Interpreter Core
messages: 228809
nosy: Kevin.Dyer
priority: normal
severity: normal
status: open
title: Segmentation fault with string concatenation
type: crash
versions: Python 2.7

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



[issue11693] memory leak in email.generator.Generator().flatten() method

2014-10-08 Thread Terry J. Reedy

Terry J. Reedy added the comment:

From Anaury's report, this is fixed in 2.7.  Email in current 3.x has been 
re-written.

--
nosy: +terry.reedy
resolution:  - fixed
stage:  - resolved
status: open - closed

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



[issue22582] RuntimeError with string concatenation

2014-10-08 Thread R. David Murray

Changes by R. David Murray rdmur...@bitdance.com:


--
stage:  - resolved
title: Segmentation fault with string concatenation - RuntimeError with string 
concatenation

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



[issue8065] Memory leak in readline.get_current_history_length

2014-10-08 Thread Terry J. Reedy

Terry J. Reedy added the comment:

The leak had been fixed in #9450.

There are still the remaining issues of:
 - better testing for the readline module, and
 - attempting to work around libedit bugs.
Perhaps those should become separate issues, though?

If those are current issues and anyone cares enough, yes, separate issues.

--
nosy: +terry.reedy
resolution:  - duplicate
stage:  - resolved
status: open - closed
superseder:  - readline.replace_history_item leaks memory.

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



[issue16254] Make PyUnicode_AsWideCharString() increase temporary

2014-10-08 Thread Terry J. Reedy

Terry J. Reedy added the comment:

I tried to re-title to describe the enhancement proposal. There are multiple 
API proposals in the two messages above.

--
nosy: +terry.reedy
stage:  - needs patch
title: PyUnicode_AsWideCharString() increases string size - Make 
PyUnicode_AsWideCharString() increase temporary
type:  - enhancement
versions: +Python 3.5 -Python 3.3

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



[issue21715] Chaining exceptions at C level

2014-10-08 Thread Roundup Robot

Roundup Robot added the comment:

New changeset 9af21752ea2a by Serhiy Storchaka in branch '3.4':
Issue #21715: Extracted shared complicated code in the _io module to new
https://hg.python.org/cpython/rev/9af21752ea2a

New changeset 8b1ac1a3d007 by Serhiy Storchaka in branch 'default':
Issue #21715: Extracted shared complicated code in the _io module to new
https://hg.python.org/cpython/rev/8b1ac1a3d007

--
nosy: +python-dev

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



[issue17381] IGNORECASE breaks unicode literal range matching

2014-10-08 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Actually 3.5 patch can be simpler.

--
Added file: http://bugs.python.org/file36839/re_ignore_case_range-3.5_2.patch

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



[issue21715] Chaining exceptions at C level

2014-10-08 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Thank you for the review Antoine.

--
assignee:  - serhiy.storchaka
resolution:  - fixed
stage: patch review - resolved
status: open - closed
versions: +Python 3.4

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



[issue1519638] Unmatched Group issue - workaround

2014-10-08 Thread Antoine Pitrou

Changes by Antoine Pitrou pit...@free.fr:


--
assignee: effbot - 

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



  1   2   >