Re: [Python-Dev] Fuzziness in io module specs - PEP update proposition V2

2009-09-28 Thread Pascal Chambon

Antoine Pitrou a écrit :

Hello,

  

So here is the proposed semantic, which matches established conventions:

*IOBase.truncate(n: int = None) -> int*


[...]

I still don't think there is a sufficient benefit in breaking 
compatibility. If you want the file pointer to remain the same, you can 
save it first and restore it afterwards manually.


  
Sure, but won't this truncate become some kind of a burden for py3k, if 
it's twice misleading (it's not a real truncation since it can extend 
the file, and it's not even a truncation or resizing in posix/win32 
style, since the filepointer is moved) ?
Since it was an undocumented behaviour, and py3k doesn't seem to be 
present yet in production environments (or is it ?), I'd promote this 
late-but-maybe-not-too-late change.
But if the consensus prefers the current behaviour, well, it'll be OK to 
me too, as long as it's sufficiently documented and advertised.



*Propositions of doc update*



Please open tracker issues for these kinds of suggestions.
  
Is the tracker Ok for simple suggestions too ? I thought it was rather 
for obvious bugfixes, and to-be-discused propositions had better be in 
mailing-lists... OK then, I'll open bugtracker issues for these. B-)





Instead of "than size", perhaps "than n".


Whoups, indeed >_<
Actually the signature would rather be:
*IOBase.truncate(size: int = None) -> int*
And I forgot to mention that truncate returns the new file size 
(according to the current PEP)...




Should an exception be raised if start and/or end are out of range?
I'd advocate it yep, for the sake of "explicit errors". However, should 
it be a ValueError (the ones io functions normally use) or an IndexError 
(which is technically more accurate, but might confuse the user) ?



Regards,
Pascal




___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] please consider changing --enable-unicode default to ucs4

2009-09-28 Thread M.-A. Lemburg
Zooko O'Whielacronx wrote:
> Folks:
> 
> I'm sorry, I think I didn't make my concern clear.  My users, and lots
> of other users, are having a problem with incompatibility between
> Python binary extension modules.  One way to improve the situation
> would be if the Python devs would use their "bully pulpit" -- their
> unique position as a source respected by all Linux distributions --
> and say "We recommend that Linux distributions use UCS4 for
> compatibility with one another".  This would not abrogate anyone's
> ability to choose their preferred setting nor, as far as I can tell,
> would it interfere with the ongoing development of Python.

-1

Please note that we did not choose to ship Python as UCS4 binary
on Linux - the Linux distributions did.

The Python default is UCS2 for a good reason: it's a good trade-off
between memory consumption, functionality and performance.

As already mentioned, I also don't understand how the changing
the Python default on Linux would help your users in any way -
if you let distutils compile your extensions, it's automatically
going to use the right Unicode setting for you (as well as your
users).

Unfortunately, this automatic support doesn't help you when
shipping e.g. setuptools eggs, but this is a tool problem,
not one of Python: setuptools completely ignores the fact
that there are two ways to build Python.

I'd suggest you ask the tool maintainers to adjust their tools
to support the Python Unicode option.

> Here are the details:
> 
> I'm the maintainer of several Python packages.  I work hard to make it
> easy for users, even users who don't know anything about Python, to
> use my software.  There have been many pain points in this process and
> I've spent a lot of time on it for about three years now working on
> packaging, including the tools such as setuptools and distutils and
> the new "distribute" tool.  Python packaging has been improving during
> these years -- things are looking up.
> 
> One of the remaining pain points is that I can distribute binaries of
> my Python extension modules for Windows or Mac, but if I distribute a
> binary Python extension module on Linux, then if the user has a
> different UCS2/UCS4 setting then they won't be able to use the
> extension module.  The current de facto standard for Linux is UCS4 --
> it is used by Debian, Ubuntu, Fedora, RHEL, OpenSuSE, etc. etc..  The
> vast majority of Linux users in practice have UCS4, and most binary
> Python modules are compiled for UCS4.
> 
> That means that a few folks will get left out.  Those folks, from my
> experience, are people who built their python executable themselves
> without specifying an override for the default, and the smaller Linux
> distributions who insist on doing whatever upstream Python devs
> recommend instead of doing whatever the other Linux distros are doing.
>  One of the data points that I reported was a Python interpreter that
> was built locally on an Ubuntu server.  Since the person building it
> didn't know to override the default setting of --enable-unicode, he
> ended up with a Python interpreter built for UCS2, even though all the
> Python extension modules shipped by Ubuntu were built with UCS4.

People building their own Python version will usually also build
their own extensions, so I don't really believe that the above
scenario is very common.

Also note that Python will complain loudly when you try to load
a UCS2 extension in a UCS4 build and vice-versa. We've made sure
that any extension using the Python Unicode C API has to be built
for the same UCS version of Python. This is done by using different
names for the C APIs at the C level.

> These are not isolated incidents.  The following google searches
> suggest that a number of people spend time trying to figure out why
> Python extension modules fail on their linux systems:
> 
> http://www.google.com/search?q=PyUnicodeUCS4_FromUnicode+undefined+symbol
> http://www.google.com/search?q=+PyUnicodeUCS2_FromUnicode+undefined+symbol
> http://www.google.com/search?q=_PyUnicodeUCS2_AsDefaultEncodedString+undefined+symbol

Perhaps we should add a FAQ entry for these linker errors
(which are caused by the mentioned C API changes to prevent
mixing UCS version) ?!

Here's a quick way to determine you Python Unicode build type:

python -c "import sys;print((sys.maxunicode<66000)and'UCS2'or'UCS4')"

Perhaps we should include this info as well as an 32/64-bit indicator
and the processor type in the Python startup line:

# python
Python 2.6 (r26:66714, Feb  3 2009, 20:49:49, UCS4, 64-bit, x86_64)
[GCC 4.3.2 [gcc-4_3-branch revision 141291]] on linux2
Type "help", "copyright", "credits" or "license" for more information.

This would help users find the right binaries to install as
extension.

> Another data point is the Mandriva Linux distribution.  It is probably
> much smaller than Debian, Ubuntu, or RedHat, but it is still one of
> the major, well-known distributions.  I requested of the Python
> maintai

Re: [Python-Dev] please consider changing --enable-unicode default to ucs4

2009-09-28 Thread M.-A. Lemburg
M.-A. Lemburg wrote:
> Also note that Python will complain loudly when you try to load
> a UCS2 extension in a UCS4 build and vice-versa. We've made sure
> that any extension using the Python Unicode C API has to be built
> for the same UCS version of Python. This is done by using different
> names for the C APIs at the C level.
> 
>> These are not isolated incidents.  The following google searches
>> suggest that a number of people spend time trying to figure out why
>> Python extension modules fail on their linux systems:
>>
>> http://www.google.com/search?q=PyUnicodeUCS4_FromUnicode+undefined+symbol
>> http://www.google.com/search?q=+PyUnicodeUCS2_FromUnicode+undefined+symbol
>> http://www.google.com/search?q=_PyUnicodeUCS2_AsDefaultEncodedString+undefined+symbol
> 
> Perhaps we should add a FAQ entry for these linker errors
> (which are caused by the mentioned C API changes to prevent
> mixing UCS version) ?!

There already is one:

http://www.python.org/doc/faq/extending/#when-importing-module-x-why-do-i-get-undefined-symbol-pyunicodeucs2

I wonder why it doesn't show up in the Google searches.

> Here's a quick way to determine you Python Unicode build type:
> 
> python -c "import sys;print((sys.maxunicode<66000)and'UCS2'or'UCS4')"
> 
> Perhaps we should include this info as well as an 32/64-bit indicator
> and the processor type in the Python startup line:
> 
> # python
> Python 2.6 (r26:66714, Feb  3 2009, 20:49:49, UCS4, 64-bit, x86_64)
> [GCC 4.3.2 [gcc-4_3-branch revision 141291]] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> 
> This would help users find the right binaries to install as
> extension.

Regards,
-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source  (#1, Sep 28 2009)
>>> Python/Zope Consulting and Support ...http://www.egenix.com/
>>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ...http://python.egenix.com/


::: Try our new mxODBC.Connect Python Database Interface for free ! 


   eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
   Registered at Amtsgericht Duesseldorf: HRB 46611
   http://www.egenix.com/company/contact/
___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] PEP 389: argparse - new command line parsing module

2009-09-28 Thread Floris Bruynooghe
On Mon, Sep 28, 2009 at 06:59:45AM +0300, Yuvgoog Greenle wrote:
> -1 for deprecating getopt. getopt is super-simple and especially useful for
> c programmers learning python.
> 
> +1 for argparse.+1 for eventual deprecation of optparse - optparse and
> argparse have a very similar syntax and having both is just
> confusing. tsboapooowtdi

+1 on all of this :-)

It would be a shame to see getopt go but optparse -> argparse seems
logical.


Floris
___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] IO module precisions and exception hierarchy

2009-09-28 Thread Pascal Chambon




 +-InvalidFileNameError (filepath max lengths, or "? / : " characters 
in a windows file name...)


This might be a bit too precise. Unix just has EINVAL, which
covers any kind of invalid parameter, not just file names.

Allright thanks, an InvalidParameter (or similar) exception should do it 
better then.



Personally I'd love to see a richer set of exceptions for IO errors, 
so long as they can be implemented for all supported platforms and no 
information (err number from the os) is lost.


I've been implementing a fake 'file' type [1] for Silverlight which 
does IO operations using local browser storage. The use case is for an 
online Python tutorial running in the browser [2]. Whilst implementing 
the exception behaviour (writing to a file open in read mode, etc) I 
considered improving the exception messages as they are very poor - 
but decided that being similar to CPython was more important.


Michael

[1] 
http://code.google.com/p/trypython/source/browse/trunk/trypython/app/storage.py 
and 
http://code.google.com/p/trypython/source/browse/trunk/trypython/app/tests/test_storage.py 


[2] http://www.trypython.org/


Cool stuff  :-)
It's indeed quite unsure at the moment which exceptions it will really 
be possible (and relevant) to implement in a cross-platform way... I 
guess I should use my own fileio implementation as a playground and a 
proof of concept, before we specify anything for CPython.



What happens isn't specified, but in practice (with the current 
implementation) the overwriting will happen at the byte level, without 
any check for correctness at the character level.


Actually, read+write text streams are implemented quite crudely, and 
little testing is done of them. The reason, as you discovered, is that 
the semantics are too weak, and it is not obvious how stronger semantics 
could look like. People wanting to do sophisticated random reads+writes 
over a text file should probably handle the encoding themselves and 
access the file at the binary level.
  
It sounds ok to me, as long as we notify users about this danger (I've 
myself just realized about it). Most newcomers may happily open an UTF8 
text file, and read/write in it carelessly, without realizing that the 
characters they write actually screw up the file...



How about just making IOError = OSError, and introducing your proposed 
subclasses? Does the usage of IOError vs OSError have *any* useful 
semantics?


I though that OSError dealt with a larger set of errors than IOError, 
but after checking the errno codes, it seems that they're all more or 
less related to IO problems (if we include interprocess communication in 
I/O). So theoretically, IOErrors and OSErrors might be merged. Note that 
in this case, windowsErrors would have to become children of 
EnvironmentError, because windows error code really seem to go farther 
than io errors (they deal with recursion limits, thousands of PC 
parameters...).
The legacy is so heavy that OSError would have to remain as is, I think, 
but we might simply forget it in new io modules, and concentrate on an 
IOError hierarchy to provide all the info needed by the developer.






Some of the error messages are truly awful though as things stand, 
especially for someone new to Python. Try to read from a file handle 
opened in read mode for example: IOError: [Errno 9] Bad file descriptor

Subdividing the IOError exception won't help with
that, because all you have to go on when deciding
which exception to raise is the error code returned
by the OS. If the same error code results from a
bunch of different things, there's not much Python
can do to sort them out.

Well, you don't only have the error number, you also have the context of 
this exception. IOErrors subclasses would particularly be useful in a 
"high level" IO contect, when each single method can issue lots of 
system calls (to check the file, lock it, edit it...). If the error is 
raised during your locking operation, you can decide to sort it as 
"LockingError" even if the error code provided might appear in several 
different situations.


Regards,
Pascal


___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] IO module precisions and exception hierarchy

2009-09-28 Thread Michael Foord

Greg Ewing wrote:

Michael Foord wrote:

Some of the error messages are truly awful though as things stand, 
especially for someone new to Python. Try to read from a file handle 
opened in read mode for example: IOError: [Errno 9] Bad file descriptor


Subdividing the IOError exception won't help with
that, because all you have to go on when deciding
which exception to raise is the error code returned
by the OS. If the same error code results from a
bunch of different things, there's not much Python
can do to sort them out.



Well, the file type knows what mode it is opened in so catching these 
errors is really not difficult at all.


Michael



The error messages produced for the various error
codes could perhaps be improved, but that's an
orthogonal issue.




--
http://www.ironpythoninaction.com/
http://www.voidspace.org.uk/blog


___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] PEP 389: argparse - new command line parsing module

2009-09-28 Thread Neal Becker
If the plan is to migrate from optparse to argparse, this could be made a 
bit easier.  If it weren't for the fact that some names are different in 
argparse than optparse, I believe many optparse usages could port with no 
change.

___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] PEP 389: argparse - new command line parsing module

2009-09-28 Thread Michael Foord

Neal Becker wrote:
If the plan is to migrate from optparse to argparse, this could be made a 
bit easier.  If it weren't for the fact that some names are different in 
argparse than optparse, I believe many optparse usages could port with no 
change.
  


The new names in argparse fit with the fact that argparse has a 
different 'rationale' than optparse. What about an optparse 
compatibility layer to make porting easier?


Although it can't cover the whole optparse API (as explained in the PEP) 
it could perhaps cover most 'normal' usage?


Michael


___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/fuzzyman%40voidspace.org.uk
  



--
http://www.ironpythoninaction.com/
http://www.voidspace.org.uk/blog


___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] PEP 3144 review.

2009-09-28 Thread R. David Murray

On Mon, 28 Sep 2009 at 05:57, "Martin v. L?wis" wrote:

Finally, to Stephen's point about seeing the other side of the
argument, I wrote this offlist a week ago:

  I *understand* what you're saying, I *understand* that
192.168.1.1/24 isn't a network,


But you still want to treat it as one.

Could you explain what benefit there is for allowing the user to create
network objects that don't represent networks? Is there a use-case
where these networks-that-aren't-networks are something other than a
typo? Under what circumstances would I want to specify a network as
192.168.1.1/24 instead of 192.168.1.0/24?



It's fairly obvious to me why the library should support 192.168.1.1/24
as an input, and return a network.

End-users are likely going to enter such things (e.g. 82.94.164.162/29),
as they will know one IP address in the network (namely, of one machine
that they are looking at), and they will know the prefix length (more
often, how large the network is - 8 or 16 or 32). So very clearly,
end users should not be required to make the computation in their heads.

So Python code has to make the computation, and it seems most natural
that the IP library is the piece of code that is able to compute a
network out of that input.

Does that answer your question?


The fundamental divide here is between two behaviors.

ipaddr:

>>> x = IPv4Network('192.168.1.1/24')
>>> y = IPv4Network('192.168.1.0/24')
>>> x == y
False
>>> x.ip
IPv4Address('192.168.1.1')

desired:

>>> x = IPv4Network('192.168.1.1/24')
>>> y = IPv4Network('192.168.1.0/24')
>>> x == y
True
>>> x.ip
Traceback (most recent call last):
  File "", line 1, in 
AttributeError: 'IPv4Network' object has no attribute 'ip'

Everything else is pretty much bikeshedding and can be dealt with.  This
is fundamental and Peter has indicated he will not change it.

--David___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] PEP 3144 review.

2009-09-28 Thread Eric Smith

R. David Murray wrote:

The fundamental divide here is between two behaviors.

ipaddr:

>>> x = IPv4Network('192.168.1.1/24')
>>> y = IPv4Network('192.168.1.0/24')
>>> x == y
False
>>> x.ip
IPv4Address('192.168.1.1')

desired:

>>> x = IPv4Network('192.168.1.1/24')
>>> y = IPv4Network('192.168.1.0/24')
>>> x == y
True
>>> x.ip
Traceback (most recent call last):
  File "", line 1, in 
AttributeError: 'IPv4Network' object has no attribute 'ip'

Everything else is pretty much bikeshedding and can be dealt with.  This
is fundamental and Peter has indicated he will not change it.


I think that's an excellent summary, David. And I'm -1 unless it changes 
to the "desired" behavior above.


Eric.
___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] PEP 3144 review.

2009-09-28 Thread R. David Murray

On Mon, 28 Sep 2009 at 07:34, R. David Murray wrote:

The fundamental divide here is between two behaviors.

ipaddr:

   > > >  x = IPv4Network('192.168.1.1/24')
   > > >  y = IPv4Network('192.168.1.0/24')
   > > >  x == y
False
   > > >  x.ip
IPv4Address('192.168.1.1')

desired:

   > > >  x = IPv4Network('192.168.1.1/24')
   > > >  y = IPv4Network('192.168.1.0/24')
   > > >  x == y
True
   > > >  x.ip
Traceback (most recent call last):
  File "", line 1, in 
AttributeError: 'IPv4Network' object has no attribute 'ip'

Everything else is pretty much bikeshedding and can be dealt with.  This
is fundamental and Peter has indicated he will not change it.


By the way, I think this is a reasonable position on Peter's part.
He's got an installed base that expects the current behavior (ie: the
"field tested module" has this behavior; making this change would produce
a fundamentally new module that has _not_ been field tested).

But I also think that the current behavior is not a good behavior for
a module in the stdlib.

--David
___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] PEP 3144 review.

2009-09-28 Thread Nick Coghlan
Peter Moody wrote:
>> That is, you've rejected the idea of having:
>>
> IPv4Network(192.168.1.1/24)
>> IPv4Network(192.168.1.0/24)
> 
> yes, I and everyone have rejected that idea. this should either raise
> an  error, or do what it does now, that is, return
> IPv4Network('192.168.1.1/24')

Um, no, several people (me included) have said that defining an
IPNetwork based on its *network address* and its netmask, instead of the
arbitrary hostname.


>> as reducing functionality, presumably because the address 192.168.1.1 is
>> lost.
> 
> good guess.
> 
>> Sounds just like an Address+netmask to me, with added
>> network-like behaviour.
>>
>> Some people have requested a way of explicitly calculating a network
>> from an Address and netmask, and you've been hostile to the idea. But
>> it seems to me that your API does exactly that.
> 
> You mean the suggestion to include an IPv?Network object attribute
> with the IPv?Address objects? I thought that was dropped long ago.

No, we're talking about any way of calculating the canonical network
object given a host within that network and the netmask.

With the current incarnation of ipaddr, the way you do that is to create
an IPNetwork object with net.ip != net.network. But then you get a
bizarre artifact, in that the same network will not compare equal if it
is derived using a different IP address.

There are *3* major concepts in ipaddr:
- single address
- network (defined by network address + net mask)
- arbitrary host associated with a specific network

Since those 3 concepts are being mapped to only two classes, 3 different
ways have been proposed of handling the 3rd concept:
- a "network" attribute on IPAddress objects (rejected, largely by
consensus as far as I can tell)
- a 2-tuple containing an IPAddress object and an IPNetwork object
(rejected implicitly by your refusal to remove the .ip attribute from
IPNetwork objects)
- the current implementation, which uses an IPNetwork object with net.ip
!= net.network.

That 3rd approach would be largely OK, *except* that the current
implementation of it breaks the definition of network equality.

Currently, IPNetwork("192.168.1.0/24") != IPNetwork("192.168.1.1/24"),
despite the fact that they refer to the exact same network. I believe
that is the fundamental point of contention here.

Regards,
Nick.

-- 
Nick Coghlan   |   [email protected]   |   Brisbane, Australia
---
___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] PEP 389: argparse - new command line parsing module

2009-09-28 Thread Nick Coghlan
Doug Hellmann wrote:
> 
> On Sep 27, 2009, at 6:00 PM, Michael Foord wrote:
> 
>> Brett Cannon wrote:
>>> I am going to state upfront that I am +1 for this and I encouraged
>>> Steven to submit this PEP on the stdlib-SIG. I still remember watching
>>> Steven's lightning talk at PyCon 2009 on argparse and being impressed
>>> by it (along with the rest of the audience which was obviously
>>> impressed as well).
>>>
>>> I think argprase is a good improvement over what we have now (getopt
>>> and optparse), it's stable, considered best-of-breed by the community
>>> for a while (as shown as how many times argparse has been suggestion
>>> for inclusion), and Steven is already a core committer so is already
>>> set to maintain the code. That covers the usual checklist we have for
>>> even looking at a PEP to add a module to the standard library.
>>>
>>>
>>
>> I've used argparse and really like it. I could also have done with the
>> subcommand support in recent changes to unittest.
>>
>> +1 for inclusion.
> 
> +1 as well.  I wish I had been able to use this library for a recent
> project using sub-commands.

+1 here as well (although we should definitely find a way to use
str.format strings instead of %-format ones... come to think of it, does
even the logging module support str.format style formatting in Py3k?)

Reading through the argparse vs optparse comparison in the argparse docs
when the topic of possibly adding it came up a few weeks back I kept
going "yep, I've rolled my own version of that, oh, and that, yeah, that
too...".

argparse probably wouldn't have helped me even if I'd known about it
(due to license review overhead), but it certainly addressed a whole
heap of problems I had encountered in practice, and in ways that were a
lot cleaner than the comparatively hacky approaches I had used for my
own purposes (internal testing and diagnostic scripts are like that...).

Cheers,
Nick.

-- 
Nick Coghlan   |   [email protected]   |   Brisbane, Australia
---
___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] PEP 389: argparse - new command line parsing module

2009-09-28 Thread Nick Coghlan
Steven Bethard wrote:
> I feel like I'm repeating the PEP, but here it is again anyway. There
> will be messages in the docs and pending deprecation warnings (which
> don't show up by default but can be requested) starting in Python 2.7
> and 3.2. Regular deprecation warnings wouldn't show up until Python
> 3.4, 3 years away. This compromise was intended exactly to address the
> issue you brought up about people getting over the Python 3
> transition.

For 2.x, I'd go even further and only have the PendingDeprecation
warnings show up under the "-3" command line flag.

Cheers,
Nick.

-- 
Nick Coghlan   |   [email protected]   |   Brisbane, Australia
---
___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] PEP 3144 review.

2009-09-28 Thread Nick Coghlan
R. David Murray wrote:
> On Mon, 28 Sep 2009 at 07:34, R. David Murray wrote:
>> The fundamental divide here is between two behaviors.
>>
>> ipaddr:
>>
>>> > >  x = IPv4Network('192.168.1.1/24')
>>> > >  y = IPv4Network('192.168.1.0/24')
>>> > >  x == y
>> False
>>> > >  x.ip
>> IPv4Address('192.168.1.1')
>>
>> desired:
>>
>>> > >  x = IPv4Network('192.168.1.1/24')
>>> > >  y = IPv4Network('192.168.1.0/24')
>>> > >  x == y
>> True
>>> > >  x.ip
>> Traceback (most recent call last):
>>   File "", line 1, in 
>> AttributeError: 'IPv4Network' object has no attribute 'ip'
>>
>> Everything else is pretty much bikeshedding and can be dealt with.  This
>> is fundamental and Peter has indicated he will not change it.
> 
> By the way, I think this is a reasonable position on Peter's part.
> He's got an installed base that expects the current behavior (ie: the
> "field tested module" has this behavior; making this change would produce
> a fundamentally new module that has _not_ been field tested).
> 
> But I also think that the current behavior is not a good behavior for
> a module in the stdlib.

I should note that I've softened my position slightly from what I posted
yesterday. I could live with the following compromise:

>>> x = IPv4Network('192.168.1.1/24')
>>> y = IPv4Network('192.168.1.0/24')
>>> x == y # Equality is the part I really want to see changed
True
>>> x.ip
IPv4Address('192.168.1.1')
>>> y.ip
IPv4Address('192.168.1.0')

So IPNetwork equality classes would be rendered conceptually coherent
(i.e. list(net1) == list(net2) would imply net1 == net2), but the "Host
with associated network" functionality would also be retained.

To check that the hosts were the same in addition to the network
definition one could easily check the .ip attribute in addition to
checking the networks themselves.

Something I also noticed is that "compare_networks" in the ipaddr
reference implementation doesn't follow the PEP - it defines IPv4
networks as being less than IPv6 networks instead of raising a TypeError.

Cheers,
Nick.

-- 
Nick Coghlan   |   [email protected]   |   Brisbane, Australia
---
___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] IO module precisions and exception hierarchy

2009-09-28 Thread Nick Coghlan
Antoine Pitrou wrote:
> Le Mon, 28 Sep 2009 06:41:17 +1000, Nick Coghlan a écrit :
>> Michael's response cut to the heart of the issue though - a richer IO
>> exception hierarchy can make life interesting for compatibility purposes
>> (especially when creating "file-like" interfaces to non-file objects).
> 
> Well, not more interesting than currently where you need to replicate 
> errno numbers if you want to make the errors precise enough, since an API 
> consumer wanting to check specific error conditions will discriminate on 
> errno.
> 
> If you don't want to go to that level of perfection, you just have to 
> raise a plain IOError (or OSError :-)) without bothering about errno or 
> subclasses; like you would do today.

Fair point.

Cheers,
Nick.

-- 
Nick Coghlan   |   [email protected]   |   Brisbane, Australia
---
___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] PEP 3144 review.

2009-09-28 Thread exarkun

On 03:57 am, [email protected] wrote:

Finally, to Stephen's point about seeing the other side of the
argument, I wrote this offlist a week ago:

  I *understand* what you're saying, I *understand* that
192.168.1.1/24 isn't a network,


But you still want to treat it as one.

Could you explain what benefit there is for allowing the user to 
create

network objects that don't represent networks? Is there a use-case
where these networks-that-aren't-networks are something other than a
typo? Under what circumstances would I want to specify a network as
192.168.1.1/24 instead of 192.168.1.0/24?


It's fairly obvious to me why the library should support 192.168.1.1/24
as an input, and return a network.

End-users are likely going to enter such things (e.g. 
82.94.164.162/29),

as they will know one IP address in the network (namely, of one machine
that they are looking at), and they will know the prefix length (more
often, how large the network is - 8 or 16 or 32). So very clearly,
end users should not be required to make the computation in their 
heads.


So Python code has to make the computation, and it seems most natural
that the IP library is the piece of code that is able to compute a
network out of that input.


And this is a rather classic example of a misfeature.  "(Non-developer) 
End users will type it in" is not argument for supporting a particular 
string format as the primary constructor for an object.  Constructors 
are for *developers*.  They should be made most useful for *developers*. 
The issue of dealing with user input (which may have many other quirks) 
is separate and should be dealt with separately.


Jean-Paul
___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] PEP 389: argparse - new command line parsing module

2009-09-28 Thread Jon Ribbens
On Mon, Sep 28, 2009 at 09:38:20AM +0100, Floris Bruynooghe wrote:
> On Mon, Sep 28, 2009 at 06:59:45AM +0300, Yuvgoog Greenle wrote:
> > -1 for deprecating getopt. getopt is super-simple and especially useful for
> > c programmers learning python.
> > 
> > +1 for argparse.+1 for eventual deprecation of optparse - optparse and
> > argparse have a very similar syntax and having both is just
> > confusing. tsboapooowtdi
> 
> +1 on all of this :-)
> 
> It would be a shame to see getopt go but optparse -> argparse seems
> logical.

+1 from me too - keep getopt, deprecate optparse.
___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] PEP 3144 review.

2009-09-28 Thread Dj Gilcrease
On Mon, Sep 28, 2009 at 5:34 AM, R. David Murray  wrote:
> The fundamental divide here is between two behaviors.
>
> ipaddr:
>
>    >>> x = IPv4Network('192.168.1.1/24')
>    >>> y = IPv4Network('192.168.1.0/24')
>    >>> x == y
>    False
>    >>> x.ip
>    IPv4Address('192.168.1.1')
>
> desired:
>
>    >>> x = IPv4Network('192.168.1.1/24')
>    >>> y = IPv4Network('192.168.1.0/24')
>    >>> x == y
>    True
>    >>> x.ip
>    Traceback (most recent call last):
>      File "", line 1, in 
>    AttributeError: 'IPv4Network' object has no attribute 'ip'


I submitted a patch to ipadrdr http://codereview.appspot.com/124057
which would do
>>> x = IPv4Network('192.168.1.1/24')
>>> y = IPv4Network('192.168.1.0/24')
>>> x == y
True
>>> x.ip
 IPv4Address('192.168.1.1')
___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] PEP 3144 review.

2009-09-28 Thread Nick Coghlan
Greg Ewing wrote:
> Nick Coghlan wrote:
> 
>> The use case for "given a netmask and an arbitrary host on that network,
>> give me the appropriate IPNetwork object" has been well established by
>> this discussion (although still isn't particularly well described even
>> in the latest PEP update). This is what "strict=False" covers,
> 
> I think I'd rather have a separate constructor function
> or method for this, rather than a somewhat cryptically
> named boolean parameter.

Yes, I would prefer a separate method as well. It doesn't bother as much
as the broken definition of equality though.

In fact, if the definition of IPNetwork equality was fixed then leaving
strict mode out entirely would probably be OK.

Cheers,
Nick.

-- 
Nick Coghlan   |   [email protected]   |   Brisbane, Australia
---
___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] PEP 3144 review.

2009-09-28 Thread Daniel Stutzbach
On Mon, Sep 28, 2009 at 7:24 AM, Nick Coghlan  wrote:

> I should note that I've softened my position slightly from what I posted
> yesterday. I could live with the following compromise:
>
>>>> x = IPv4Network('192.168.1.1/24')
>>>> y = IPv4Network('192.168.1.0/24')
> >>> x == y # Equality is the part I really want to see changed
>True
> >>> x.ip
>IPv4Address('192.168.1.1')
>>>> y.ip
> IPv4Address('192.168.1.0')
>

With those semantics, IPv4Network objects with distinct IP addresses (but
the same network) could no longer be stored in a dictionary or set.  IMO, it
is a little counter-intuitive for objects to compare equal yet have
different properties.  I don't think this is a good compromise.

--
Daniel Stutzbach, Ph.D.
President, Stutzbach Enterprises, LLC 
___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] PEP 3144 review.

2009-09-28 Thread Mark Dickinson
On Mon, Sep 28, 2009 at 3:04 PM, Daniel Stutzbach
 wrote:
> On Mon, Sep 28, 2009 at 7:24 AM, Nick Coghlan  wrote:
>>
>> I should note that I've softened my position slightly from what I posted
>> yesterday. I could live with the following compromise:
>>
>>    >>> x = IPv4Network('192.168.1.1/24')
>>    >>> y = IPv4Network('192.168.1.0/24')
>>    >>> x == y # Equality is the part I really want to see changed
>>    True
>>    >>> x.ip
>>    IPv4Address('192.168.1.1')
>>    >>> y.ip
>>    IPv4Address('192.168.1.0')
>
> With those semantics, IPv4Network objects with distinct IP addresses (but
> the same network) could no longer be stored in a dictionary or set.  IMO, it
> is a little counter-intuitive for objects to compare equal yet have
> different properties.  I don't think this is a good compromise.

This worries me too.  It seems like a potentially dangerous half-measure.

Mark
___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] PEP 3144 review.

2009-09-28 Thread Eric Smith

Mark Dickinson wrote:

On Mon, Sep 28, 2009 at 3:04 PM, Daniel Stutzbach
 wrote:

On Mon, Sep 28, 2009 at 7:24 AM, Nick Coghlan  wrote:

I should note that I've softened my position slightly from what I posted
yesterday. I could live with the following compromise:

   >>> x = IPv4Network('192.168.1.1/24')
   >>> y = IPv4Network('192.168.1.0/24')
   >>> x == y # Equality is the part I really want to see changed
   True
   >>> x.ip
   IPv4Address('192.168.1.1')
   >>> y.ip
   IPv4Address('192.168.1.0')

With those semantics, IPv4Network objects with distinct IP addresses (but
the same network) could no longer be stored in a dictionary or set.  IMO, it
is a little counter-intuitive for objects to compare equal yet have
different properties.  I don't think this is a good compromise.


This worries me too.  It seems like a potentially dangerous half-measure.


I agree. I think keeping the concepts distinct and adding 2 new classes 
is a better solution.


Eric.

___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] PEP 389: argparse - new command line parsing module

2009-09-28 Thread Steven Bethard
On Mon, Sep 28, 2009 at 6:03 AM, Jon Ribbens
 wrote:
> On Mon, Sep 28, 2009 at 09:38:20AM +0100, Floris Bruynooghe wrote:
>> On Mon, Sep 28, 2009 at 06:59:45AM +0300, Yuvgoog Greenle wrote:
>> > -1 for deprecating getopt. getopt is super-simple and especially useful for
>> > c programmers learning python.
>> >
>> > +1 for argparse.+1 for eventual deprecation of optparse - optparse and
>> > argparse have a very similar syntax and having both is just
>> > confusing. tsboapooowtdi
>>
>> +1 on all of this :-)
>>
>> It would be a shame to see getopt go but optparse -> argparse seems
>> logical.
>
> +1 from me too - keep getopt, deprecate optparse.

Ok, sounds like there are a number of supporters for keeping getopt
around and just deprecating optparse. For those who'd like to keep
getopt around, I have a few questions:

* Would you be opposed to a note in the getopt documentation
suggesting argparse as an alternative?

* Would you like argparse to grow an add_getopt_arguments method (as
in my other post)?

* If argparse grew an add_getopt_arguments, would you still want to
keep getopt around? And if so, why?

Steve
-- 
Where did you get that preposterous hypothesis?
Did Steve tell you that?
--- The Hiphopopotamus
___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] PEP 3144 review.

2009-09-28 Thread R. David Murray

On Sun, 27 Sep 2009 at 10:06, David Moss wrote:

On 27 Sep 2009, at 07:56, "Martin v. L??wis"  wrote:

 I wouldn't ask for that: it should certainly be possible to supply
 masks. However, I would want to reject masks that don't correspond to
 a prefix, and have only the prefix length in the internal representation.

+1 on rejection of netmasks without direct CIDR prefix equivalents. AFAIK 
Cisco routers accept them but I don't see how they would be useful in 
practice (unless someone can demonstrate their need for this).


Several years ago I ran into a network with a non-CIDR netmask.  This
was in the early days of CIDR, and I hope that that network is no longer
configured that way

A little googling produced this hit:

http://tools.ietf.org/wg/mip4/draft-ietf-mip4-nemo-v4-base/draft-ietf-mip4-nemo-v4-base-11-from-10.diff.txt

which while not a standard itself clearly believes that non-contiguous
netmasks are valid, and is dated 2008.  Earlier RFCs (950 and 1219)
give them as valid but discouraged.

The linux stack (or at least the ifconfig command on my system) does not
appear to support non-contiguous netmasks.  From a brief search on Cisco's
site it looks like Cisco only partially supports non-contiguous masks
(you can use them in wildmasks in access lists, but not in subnet masks
on interfaces).  (I just tried setting a non-contiguous netmask on an
interface on one of my Ciscos, and it gave me a 'bad mask' error message.)

I think support for non-contiguous netmasks could be safely omitted,
but it would mean the module did not fully support the standards, which
should be noted in the docs (and why).

--David___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] PEP 389: argparse - new command line parsing module

2009-09-28 Thread Steven D'Aprano
On Mon, 28 Sep 2009 06:59:32 am Steven Bethard wrote:

> Why aren't getopt and optparse enough?
[snip]

As a newbie, I found optparse intimidating because it provided so many 
features. I expect argparse will be the same, only more so. 
(Disclaimer: I haven't used argparse, I'm merely making a prediction 
based on the available functionality.)

As it turned out, optparse wasn't anywhere near as difficult to use as I 
expected it to be, but I suggest that newbies will have the same 
response to argparse as I had to optparse -- "this looks complicated, 
I'll just roll my own". At least I had the option to use getopt.

Not every module needs to be newbie-friendly, but something as 
fundamental as argument parsing should at least provide a gentle 
learning curve.

Currently, getopt more-or-less plays the role of "bare-bones" command 
line parsing, which I think is important. Assuming argparse is added to 
the std lib, I'm -0.5 on deprecating getopt, 0 on deprecating optparse.



-- 
Steven D'Aprano
___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] PEP 3144 review.

2009-09-28 Thread Dj Gilcrease
On Mon, Sep 28, 2009 at 8:04 AM, Daniel Stutzbach
 wrote:
> On Mon, Sep 28, 2009 at 7:24 AM, Nick Coghlan  wrote:
>>
>> I should note that I've softened my position slightly from what I posted
>> yesterday. I could live with the following compromise:
>>
>>    >>> x = IPv4Network('192.168.1.1/24')
>>    >>> y = IPv4Network('192.168.1.0/24')
>>    >>> x == y # Equality is the part I really want to see changed
>>    True
>>    >>> x.ip
>>    IPv4Address('192.168.1.1')
>>    >>> y.ip
>>    IPv4Address('192.168.1.0')
>
> With those semantics, IPv4Network objects with distinct IP addresses (but
> the same network) could no longer be stored in a dictionary or set.  IMO, it
> is a little counter-intuitive for objects to compare equal yet have
> different properties.  I don't think this is a good compromise.

Thats not true, the patch I submitted
http://codereview.appspot.com/124057 still allows the networks to be
included in a set or as a dict key

>>> net1 = IPNetwork("10.1.2.3/24")
>>> net2 = IPNetwork("10.1.2.0/24")
>>> print hash(net1) == hash(net2)
False
>>> print net1 == net2
True
>>> test = {net1: "something", net2: "something else"}
>>> print test
{IPv4Network('10.1.2.0/24'): 'something else',
IPv4Network('10.1.2.3/24'): 'something'}
>>> test2 = set([net1, net2])
>>> print test2
set([IPv4Network('10.1.2.0/24'), IPv4Network('10.1.2.3/24')])
___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] PEP 389: argparse - new command line parsing module

2009-09-28 Thread Steven Bethard
On Mon, Sep 28, 2009 at 4:09 AM, Neal Becker  wrote:
> If the plan is to migrate from optparse to argparse, this could be made a
> bit easier.  If it weren't for the fact that some names are different in
> argparse than optparse, I believe many optparse usages could port with no
> change.

I could conceivably add an OptionParser class which::

* Has an add_option method which delegates to add_argument

* Has a parse_args method which delegates to parse_known_args

* Registers the string names for types that optparse uses

That might allow some users to just switch their import as long as
they're not using any callbacks, catching any exceptions, extending
any APIs, etc. I'm not 100% convinced that it's good to add a subtly
different API that people would have to unlearn, but if there's enough
support for this, I'm open to the idea.

Steve
-- 
Where did you get that preposterous hypothesis?
Did Steve tell you that?
--- The Hiphopopotamus
___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] PEP 389: argparse - new command line parsing module

2009-09-28 Thread skip

Nick> +1 here as well (although we should definitely find a way to use
Nick> str.format strings instead of %-format ones... come to think of
Nick> it, does even the logging module support str.format style
Nick> formatting in Py3k?)

Assuming argparse currently works with versions of Python < 2.6 I see no
reason to make such a change.  This would just introduce needless
differences between the version delivered with Python and the PyPI version
and make it more difficult for the author to keep the two code bases in
sync.

Skip
___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] PEP 3144 review.

2009-09-28 Thread Guido van Rossum
On Mon, Sep 28, 2009 at 7:42 AM, Dj Gilcrease  wrote:
> On Mon, Sep 28, 2009 at 8:04 AM, Daniel Stutzbach
>  wrote:
>> On Mon, Sep 28, 2009 at 7:24 AM, Nick Coghlan  wrote:
>>>
>>> I should note that I've softened my position slightly from what I posted
>>> yesterday. I could live with the following compromise:
>>>
>>>    >>> x = IPv4Network('192.168.1.1/24')
>>>    >>> y = IPv4Network('192.168.1.0/24')
>>>    >>> x == y # Equality is the part I really want to see changed
>>>    True
>>>    >>> x.ip
>>>    IPv4Address('192.168.1.1')
>>>    >>> y.ip
>>>    IPv4Address('192.168.1.0')
>>
>> With those semantics, IPv4Network objects with distinct IP addresses (but
>> the same network) could no longer be stored in a dictionary or set.  IMO, it
>> is a little counter-intuitive for objects to compare equal yet have
>> different properties.  I don't think this is a good compromise.
>
> Thats not true, the patch I submitted
> http://codereview.appspot.com/124057 still allows the networks to be
> included in a set or as a dict key
>
 net1 = IPNetwork("10.1.2.3/24")
 net2 = IPNetwork("10.1.2.0/24")
 print hash(net1) == hash(net2)
> False
 print net1 == net2
> True

Hold it right there! That's wrong. You can't have two objects that
compare equal but whose hashes differ. It will break dict lookup. The
other way around is fine: two objects may differ and still have the
same hash.

 test = {net1: "something", net2: "something else"}
 print test
> {IPv4Network('10.1.2.0/24'): 'something else',
> IPv4Network('10.1.2.3/24'): 'something'}
 test2 = set([net1, net2])
 print test2
> set([IPv4Network('10.1.2.0/24'), IPv4Network('10.1.2.3/24')])
> ___
> Python-Dev mailing list
> [email protected]
> http://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe: 
> http://mail.python.org/mailman/options/python-dev/guido%40python.org
>



-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)
___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] PEP 3144 review.

2009-09-28 Thread Mark Dickinson
On Mon, Sep 28, 2009 at 3:42 PM, Dj Gilcrease  wrote:
> On Mon, Sep 28, 2009 at 8:04 AM, Daniel Stutzbach
>  wrote:
>> On Mon, Sep 28, 2009 at 7:24 AM, Nick Coghlan  wrote:
>>>
>>> I should note that I've softened my position slightly from what I posted
>>> yesterday. I could live with the following compromise:
>>>
>>>    >>> x = IPv4Network('192.168.1.1/24')
>>>    >>> y = IPv4Network('192.168.1.0/24')
>>>    >>> x == y # Equality is the part I really want to see changed
>>>    True
>>>    >>> x.ip
>>>    IPv4Address('192.168.1.1')
>>>    >>> y.ip
>>>    IPv4Address('192.168.1.0')
>>
>> With those semantics, IPv4Network objects with distinct IP addresses (but
>> the same network) could no longer be stored in a dictionary or set.  IMO, it
>> is a little counter-intuitive for objects to compare equal yet have
>> different properties.  I don't think this is a good compromise.
>
> Thats not true, the patch I submitted
> http://codereview.appspot.com/124057 still allows the networks to be
> included in a set or as a dict key
>
 net1 = IPNetwork("10.1.2.3/24")
 net2 = IPNetwork("10.1.2.0/24")
 print hash(net1) == hash(net2)
> False
 print net1 == net2
> True

In that case, your patch breaks the rather fundamental rule that
Python objects that compare equal should have equal hash.  :-)

Relying on hashes to be distinct isn't safe.

Mark
___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] PEP 3144 review.

2009-09-28 Thread Antoine Pitrou
Dj Gilcrease  gmail.com> writes:
> 
> >>> net1 = IPNetwork("10.1.2.3/24")
> >>> net2 = IPNetwork("10.1.2.0/24")
> >>> print hash(net1) == hash(net2)
> False
> >>> print net1 == net2
> True

Ouch :-)
It is very bad practice for equal objects to hash differently. Differing hashes
are supposed to imply non-equal objects, so as to allow the implementation of
associative containers with good performance characteristics.

Regards

Antoine.


___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] PEP 3144 review.

2009-09-28 Thread Daniel Stutzbach
On Mon, Sep 28, 2009 at 9:35 AM, R. David Murray wrote:

> A little googling produced this hit:
>
>
> http://tools.ietf.org/wg/mip4/draft-ietf-mip4-nemo-v4-base/draft-ietf-mip4-nemo-v4-base-11-from-10.diff.txt
>
> which while not a standard itself clearly believes that non-contiguous
> netmasks are valid, and is dated 2008.  Earlier RFCs (950 and 1219)
> give them as valid but discouraged.
>

That's a draft for RFC 5177.  In the RFC, all references to non-contiguous
subnets have been removed.

http://tools.ietf.org/html/rfc5177

--
Daniel Stutzbach, Ph.D.
President, Stutzbach Enterprises, LLC 
___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] PEP 389: argparse - new command line parsing module

2009-09-28 Thread M.-A. Lemburg
Antoine Pitrou wrote:
> 
> Hello,
> 
> I am neutral on the idea of adding argparse. However, I'm -1 on deprecating
> optparse. It is very widely used (tons of scripts use it), and ok for many 
> uses;
> deprecating it is totally unhelpful and gratuitous.

You can add me to that camp as well:

+0 on adding argparse
-1 on deprecating wide-used modules such as getopt and optparse

Note that the last -1 only applies to the module APIs, not the
code in those modules.

If argparse provides an API compatibility layer for getopt and
optparse, the original code of getopt and optparse could go
without problem, IMHO, leaving only the mostly empty modules
together with compatibility layers.

OTOH, as discussed on the stdlib SIG list, those two modules
hardly ever require any maintenance, so keeping them as they
are is certainly an option as well.

-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source  (#1, Sep 28 2009)
>>> Python/Zope Consulting and Support ...http://www.egenix.com/
>>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ...http://python.egenix.com/


::: Try our new mxODBC.Connect Python Database Interface for free ! 


   eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
   Registered at Amtsgericht Duesseldorf: HRB 46611
   http://www.egenix.com/company/contact/
___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] PEP 389: argparse - new command line parsing module

2009-09-28 Thread Michael Foord

M.-A. Lemburg wrote:

Antoine Pitrou wrote:
  

Hello,

I am neutral on the idea of adding argparse. However, I'm -1 on deprecating
optparse. It is very widely used (tons of scripts use it), and ok for many uses;
deprecating it is totally unhelpful and gratuitous.



You can add me to that camp as well:

+0 on adding argparse
-1 on deprecating wide-used modules such as getopt and optparse

Note that the last -1 only applies to the module APIs, not the
code in those modules.

If argparse provides an API compatibility layer for getopt and
optparse, the original code of getopt and optparse could go
without problem, IMHO, leaving only the mostly empty modules
together with compatibility layers.

OTOH, as discussed on the stdlib SIG list, those two modules
hardly ever require any maintenance, so keeping them as they
are is certainly an option as well.

  
Although as also discussed on the stdlib-sig there is also a cost to 
leaving unmaintained and unneeded modules in the standard library. As we 
are 'end-of-lifing' Python 2.X there seems to be little point in going 
down the deprecation route (there won't be enough releases to ever get 
to module removal) but discussion about the standard library in 
situations like this is badly needed for 3.X.


Certainly a slow deprecation procedure, as suggested by Steven, is 
warranted.


Michael

--
http://www.ironpythoninaction.com/
http://www.voidspace.org.uk/blog


___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] PEP 3144 review.

2009-09-28 Thread Steven D'Aprano
On Mon, 28 Sep 2009 01:57:04 pm Martin v. Löwis wrote:
> >> Finally, to Stephen's point about seeing the other side of the
> >> argument, I wrote this offlist a week ago:
> >>
> >>   I *understand* what you're saying, I *understand* that
> >> 192.168.1.1/24 isn't a network,
> >
> > But you still want to treat it as one.
> >
> > Could you explain what benefit there is for allowing the user to
> > create network objects that don't represent networks? Is there a
> > use-case where these networks-that-aren't-networks are something
> > other than a typo? Under what circumstances would I want to specify
> > a network as 192.168.1.1/24 instead of 192.168.1.0/24?
>
> It's fairly obvious to me why the library should support
> 192.168.1.1/24 as an input, and return a network.
>
> End-users are likely going to enter such things (e.g.
> 82.94.164.162/29), as they will know one IP address in the network
> (namely, of one machine that they are looking at), and they will know
> the prefix length (more often, how large the network is - 8 or 16 or
> 32). So very clearly, end users should not be required to make the
> computation in their heads.

Thank you Martin.

I had somehow -- justifiably or not, it doesn't matter -- got the 
impression from Peter off-list that this was *not* a use-case he gave 
any credence to, but of course the current API supports it, which 
confused me no end.

I'm not sure that just because the user enters '82.94.164.162/29' into 
the UI, the API must accept it. As Jean-Paul suggests, the issue of 
dealing with user-input is different from API aimed at developers. 
There are at least three options:

(1) The status quo: IPv4Network accepts the host address plus mask, and 
returns an object which behaves like a network but remembers the host 
address.

(2) Like (1), but the address is normalised to the canonical network 
address (which if I've calculated it correctly should be 
'82.94.164.160').

In this case, whether the user enters '82.94.164.162/29' 
or '82.94.164.169/29', the network returned will be the same. If the 
developer wants to save the host address as well as the network for 
some reason, he should store the host address as a separate object.

(3) Like (2), except the constructor is strict and only accepts the 
canonical network address, and will raise an exception if 
given '82.94.164.162/29'. This may require at least one helper function 
to calculate the network/mask from the address/mask.


The PEP now states:

"It should be understood that, above all, this module is designed with 
the network administrator in mind.  In practice, this means that a 
number of assumptions are made with regards to common usage and the 
library prefers the usefulness of accepted practice over strict 
adherence to RFCs. For example, ipaddr accepts '192.168.1.1/24' as a 
network definition because this is a very common way of describing an 
address + netmask despite the fact that 192.168.1.1 is actually an IP 
address on the network 192.168.1.0/24. ..."

which nicely explains why (3) is not used, but doesn't explain why (1) 
should be preferred over (2).



-- 
Steven D'Aprano
___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] please consider changing --enable-unicode default to ucs4

2009-09-28 Thread James Y Knight

On Sep 28, 2009, at 4:25 AM, M.-A. Lemburg wrote:

Distributions should really not be put in charge of upstream
coding design decisions.


I don't think you can blame distros for this one

From PEP 0261:
It is also proposed that one day --enable-unicode will just
default to the width of your platforms wchar_t.

On linux, wchar_t is 4 bytes.

If there's a consensus amongst python upstream that all the distros  
should be shipping Python with UCS2 unicode strings, you should reach  
out to them and say this, in a rather more clear fashion. Currently,  
most signs point towards UCS4 builds as being the better option.


Or, one might reasonably wonder why UCS-4 is an option at all, if  
nobody should enable it.



People building their own Python version will usually also build
their own extensions, so I don't really believe that the above
scenario is very common.


I'd just like to note that I've run into this trap multiple times. I  
built a custom python, and expected it to work with all the existing,  
installed, extensions (same major version as the system install, just  
patched). And then had to build it again with UCS4, for it to actually  
work. Of course building twice isn't the end of the world, and I'm  
certainly used to having to twiddle build options on software to get  
it working, but, this *does* happen, and *is* a tiny bit irritating.


James
___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] PEP 389: argparse - new command line parsing module

2009-09-28 Thread Yuvgoog Greenle
>
> * Would you be opposed to a note in the getopt documentation suggesting
> argparse as an alternative?


from the top of http://docs.python.org/library/getopt.html - "A more
convenient, flexible, and powerful alternative is the optparse module."I
think this statement should be emphasized better but it's already there so
no worries.

* Would you like argparse to grow an add_getopt_arguments method (as in my
> other post)?

* If argparse grew an add_getopt_arguments, would you still want to keep
> getopt around? And if so, why?


Argparse/optparse use a parser instance and getopt doesn't. I think that's a
saved line you have to keep saving so this would be the better syntax imho:
optlist, args = argparse.getopt(args, 'abc:d:')

I was thinking on the general issue of what's better for the std-lib:
1. Mini modules - 3+ small modules in each subject that can be useful in
different contexts. For example the xml libs.
or
2. Big modules - 1 uber-module for each subject that does everything. Maybe
logging is an example of this.

I think in general python std-lib went the path of mini modules. Its
advantages
1. Each mini module can be coherent and while python isn't really
OnlyOneWayToDoIt, each module in itself has OnlyOneWayToDoIt.
2. Documentation is less cluttered by a large amount of functions that all
do the same thing but differently. This is very important for python's
learning curve.

disadvantages:
1. You have to craft your documentation carefully as to be very explicit on
why you have all these modules for the same thing. Probably each module
should explain it's purpose in relation to the other modules and this
explanation should appear at the top of the documentation of each of the
mini modules in the subject. Today it would be very hard for me to figure
out how the xml modules interrelate, urllib has improved in python3 but
still isn't perfect.
2. I could be using some silly way of doing things (getopt) while I really
wanted to do it the good way (argparse).

I think that while adding getopt functionality to argparse might be nice but
would eventually cause clutter.
___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] PEP 389: argparse - new command line parsing module

2009-09-28 Thread m h
Perhaps this is OT, but since command line parsing is part of
configuration, I figure I'd throw it out there.  My scripts often have
configuration that the command line can override and I loosely follow
the example hierarchy[0] listed in The Art of Unix Programming.

Some configuration I want in a config file (but I want to override
from the command line) and sometimes it's very nice to use environment
variables for configuration.  So I do something like this:


Chaining Configuration
--

Ugly code to cascade configuration

>>> class Unset(object): pass
>>> def cascade_value(opt=None, opt_name=None, env_name=None, cfg=None, 
>>> cfg_section=None, cfg_name=None, default=None):
..."""
...opt - result of OptionParser.parse_args
...opt_name - string of opt name you want to access
..."""
...# get from cmd line
...value = Unset()
...if opt and opt_name:
...try:
...value = opt.__getattr__(opt_name)
...except AttributeError, e:
...pass
...if not isinstance(value, Unset):
...return value
...# get from ENV
...if env_name:
...try:
...value = os.environ[env_name]
...except KeyError, e:
...pass
...if not isinstance(value, Unset):
...return value
...# get from config file
...if cfg and cfg_section and cfg_name:
...try:
...value = cfg.get(cfg_section, cfg_name)
...except ConfigParser.NoOptionError, e:
...pass
...if not isinstance(value, Unset):
...return value
...return default


>>> cascade_value(opt=opt, opt_name='author', cfg=cfg, 
>>> cfg_section='Properties', cfg_name='author')
'Matt'

Does anyone else have interest in such functionality?  Is it outside
the realm of this PEP?  Ideally I'd like to have something like
``env_name``, ``config_key`` named parameters for options, then pass
an optional list of configs files to the parser instance.  Then rather
than looking solely at command line options, argparse could also pull
values from config files, then env and finally the command line.

cheers,

matt harrison


0 - http://www.faqs.org/docs/artu/ch10s02.html
___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] PEP 3144 review.

2009-09-28 Thread Paul Moore
2009/9/28 Peter Moody :
>> That is, you've rejected the idea of having:
>>
> IPv4Network(192.168.1.1/24)
>> IPv4Network(192.168.1.0/24)
>
> yes, I and everyone have rejected that idea. this should either raise
> an  error, or do what it does now, that is, return
> IPv4Network('192.168.1.1/24')

Speaking as a member of the group "everyone", I have not rejected that
idea. It seems perfectly sensible to me. Yes, it "loses" the
information about the full IP address 192.168.1.1, but in my view,
that's what I asked it to do by requesting a network object back.

2009/9/28 R. David Murray :
> The fundamental divide here is between two behaviors.
>
> ipaddr:
>
>    >>> x = IPv4Network('192.168.1.1/24')
>    >>> y = IPv4Network('192.168.1.0/24')
>    >>> x == y
>    False
>    >>> x.ip
>    IPv4Address('192.168.1.1')
>
> desired:
>
>    >>> x = IPv4Network('192.168.1.1/24')
>    >>> y = IPv4Network('192.168.1.0/24')
>    >>> x == y
>    True
>    >>> x.ip
>    Traceback (most recent call last):
>      File "", line 1, in 
>    AttributeError: 'IPv4Network' object has no attribute 'ip'
>
> Everything else is pretty much bikeshedding and can be dealt with.  This
> is fundamental and Peter has indicated he will not change it.

Agreed. I would prefer the option marked "desired". As a naive "casual
user" of the module, I claim that the current behaviour is
non-intuitive and I anticipate it causing me issues (not many, and I
won't use the module often, so I concede - before someone asks - that
it'll be a minor inconvenience to me).

Given that I am a minor user, as noted above, I remain -1 on
inclusion, largely because it feels to me like the module will suffer
the same fate as optparse - rejecting certain changes which have
relatively widespread support on essentially philosophical grounds.

Paul.
___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] PEP 389: argparse - new command line parsing module

2009-09-28 Thread Michael Foord

m h wrote:

Perhaps this is OT, but since command line parsing is part of
configuration, I figure I'd throw it out there.  My scripts often have
configuration that the command line can override and I loosely follow
the example hierarchy[0] listed in The Art of Unix Programming.

Some configuration I want in a config file (but I want to override
from the command line) and sometimes it's very nice to use environment
variables for configuration.  So I do something like this:

  


Integration with command line options is an occasionally-requested 
feature for ConfigObj. I've always said I would be open to patches...


In other words, yes I think there is demand for it. Whether it belongs 
*immediately* in the standard library is another matter, but if you 
wrote a layer that unified ConfigParser and argparse I think you will 
find that people use it.


It is well outside the realm of this PEP however.

All the best,

Michael Foord


Chaining Configuration
--

Ugly code to cascade configuration

  

class Unset(object): pass
def cascade_value(opt=None, opt_name=None, env_name=None, cfg=None, 
cfg_section=None, cfg_name=None, default=None):


..."""
...opt - result of OptionParser.parse_args
...opt_name - string of opt name you want to access
..."""
...# get from cmd line
...value = Unset()
...if opt and opt_name:
...try:
...value = opt.__getattr__(opt_name)
...except AttributeError, e:
...pass
...if not isinstance(value, Unset):
...return value
...# get from ENV
...if env_name:
...try:
...value = os.environ[env_name]
...except KeyError, e:
...pass
...if not isinstance(value, Unset):
...return value
...# get from config file
...if cfg and cfg_section and cfg_name:
...try:
...value = cfg.get(cfg_section, cfg_name)
...except ConfigParser.NoOptionError, e:
...pass
...if not isinstance(value, Unset):
...return value
...return default


  

cascade_value(opt=opt, opt_name='author', cfg=cfg, cfg_section='Properties', 
cfg_name='author')


'Matt'

Does anyone else have interest in such functionality?  Is it outside
the realm of this PEP?  Ideally I'd like to have something like
``env_name``, ``config_key`` named parameters for options, then pass
an optional list of configs files to the parser instance.  Then rather
than looking solely at command line options, argparse could also pull
values from config files, then env and finally the command line.

cheers,

matt harrison


0 - http://www.faqs.org/docs/artu/ch10s02.html
___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/fuzzyman%40voidspace.org.uk
  



--
http://www.ironpythoninaction.com/
http://www.voidspace.org.uk/blog


___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] PEP 389: argparse - new command line parsing module

2009-09-28 Thread Steven D'Aprano
On Tue, 29 Sep 2009 12:28:39 am Steven Bethard wrote:

> Ok, sounds like there are a number of supporters for keeping getopt
> around and just deprecating optparse. For those who'd like to keep
> getopt around, I have a few questions:
>
> * Would you be opposed to a note in the getopt documentation
> suggesting argparse as an alternative?

+1

> * Would you like argparse to grow an add_getopt_arguments method (as
> in my other post)?

0

> * If argparse grew an add_getopt_arguments, would you still want to
> keep getopt around? And if so, why?

Simplicity of the learning curve. Using it is as simple as:

getopt.getopt(sys.argv[1:], "a:b", ["alpha=", "beta"])

Does argparse allow anything as simple as that?




-- 
Steven D'Aprano
___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Application configuration (was: PEP 389: argparse)

2009-09-28 Thread Oleg Broytman
On Mon, Sep 28, 2009 at 09:23:22AM -0600, m h wrote:
> Perhaps this is OT, but since command line parsing is part of
> configuration, I figure I'd throw it out there.  My scripts often have
> configuration that the command line can override and I loosely follow
> the example hierarchy[0] listed in The Art of Unix Programming.
> 
> Some configuration I want in a config file (but I want to override
> from the command line) and sometimes it's very nice to use environment
> variables for configuration.

   The idea was discussed in the list many years ago but it seems to be
forgotten now.

> Does anyone else have interest in such functionality?  Is it outside
> the realm of this PEP?

   It is outside the scope of this particular PEP, but it is certainly an
interesting idea.
   Actually it is the Right Thing, but I doubt it is possible to implement
such a generic configuration *framework* in the Python standard *library*.
Applications use different configfile layouts, some programs use w32
registry instead of configfiles...

Oleg.
-- 
 Oleg Broytmanhttp://phd.pp.ru/[email protected]
   Programmers don't die, they just GOSUB without RETURN.
___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] PEP 389: argparse - new command line parsing module

2009-09-28 Thread Jesse Noller
On Sun, Sep 27, 2009 at 4:57 PM, Brett Cannon  wrote:
> I am going to state upfront that I am +1 for this and I encouraged
> Steven to submit this PEP on the stdlib-SIG. I still remember watching
> Steven's lightning talk at PyCon 2009 on argparse and being impressed
> by it (along with the rest of the audience which was obviously
> impressed as well).
>
> I think argprase is a good improvement over what we have now (getopt
> and optparse), it's stable, considered best-of-breed by the community
> for a while (as shown as how many times argparse has been suggestion
> for inclusion), and Steven is already a core committer so is already
> set to maintain the code. That covers the usual checklist we have for
> even looking at a PEP to add a module to the standard library.

+1 to what brett said.

jesse
___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] PEP 389: argparse - new command line parsing module

2009-09-28 Thread Steven Bethard
On Mon, Sep 28, 2009 at 8:26 AM, Michael Foord
 wrote:
> m h wrote:
>>
>> Perhaps this is OT, but since command line parsing is part of
>> configuration, I figure I'd throw it out there.  My scripts often have
>> configuration that the command line can override and I loosely follow
>> the example hierarchy[0] listed in The Art of Unix Programming.
>>
>> Some configuration I want in a config file (but I want to override
>> from the command line) and sometimes it's very nice to use environment
>> variables for configuration.  So I do something like this:
>
> Integration with command line options is an occasionally-requested feature
> for ConfigObj. I've always said I would be open to patches...
>
> In other words, yes I think there is demand for it. Whether it belongs
> *immediately* in the standard library is another matter, but if you wrote a
> layer that unified ConfigParser and argparse I think you will find that
> people use it.
>
> It is well outside the realm of this PEP however.

What Michael said. ;-) If you'd like to provide a patch for argparse
that provides such functionality, I'd be happy to review it.

Steve
-- 
Where did you get that preposterous hypothesis?
Did Steve tell you that?
--- The Hiphopopotamus
___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] PEP 3144 review.

2009-09-28 Thread Dj Gilcrease
On Mon, Sep 28, 2009 at 8:56 AM, Guido van Rossum  wrote:
> Hold it right there! That's wrong. You can't have two objects that
> compare equal but whose hashes differ. It will break dict lookup. The
> other way around is fine: two objects may differ and still have the
> same hash.


mm I never knew that, guess I'll go fix my patch to change the
__hash__ method as well, though when I tested it dict lookup seemed to
work fine


>>> net1 = IPNetwork("10.1.2.0/29")
>>> i = 0
>>> test = {}
>>> for ip in net1:
test[IPNetwork("%s/29" %(ip))] = i
i += 1


>>> print test[IPv4Network('10.1.2.4/29')]
4
>>> print test
{IPv4Network('10.1.2.0/29'): 0, IPv4Network('10.1.2.1/29'): 1,
IPv4Network('10.1.2.2/29'): 2, IPv4Network('10.1.2.3/29'): 3,
IPv4Network('10.1.2.4/29'): 4, IPv4Network('10.1.2.5/29'): 5,
IPv4Network('10.1.2.6/29'): 6, IPv4Network('10.1.2.7/29'): 7}
>>>
___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] PEP 389: argparse - new command line parsing module

2009-09-28 Thread Steven Bethard
On Mon, Sep 28, 2009 at 8:27 AM, Steven D'Aprano  wrote:
> On Tue, 29 Sep 2009 12:28:39 am Steven Bethard wrote:
>> * Would you like argparse to grow an add_getopt_arguments method (as
>> in my other post)?
>
> 0
>
>> * If argparse grew an add_getopt_arguments, would you still want to
>> keep getopt around? And if so, why?
>
> Simplicity of the learning curve. Using it is as simple as:
>
> getopt.getopt(sys.argv[1:], "a:b", ["alpha=", "beta"])

You forgot the for-loop, nested if/else statements and type conversions. ;-)

> Does argparse allow anything as simple as that?

If you mean, does argparse allow configuration to be specified using
the getopt style ("a:b", ["alpha=", "beta"]), no, it currently
doesn't. But if this is useful functionality, and would reasonably
replace the getopt use cases, then I'd be happy to add it. In the
simplest version, we might add something like::

options, args = argparse.getopt("a:b", ["alpha=", "beta"])

where you could then use "options" without any looping::

alpha = options.a or options.alpha
beta = options.b or options.beta

But if people still like the traditional getopt loop with nested
if/elses better, then we might as well just keep getopt around and not
add anything to argparse. I'm fine with that too, I just want to make
sure that there isn't an obvious deficiency in argparse that we could
easily fix.

Steve
-- 
Where did you get that preposterous hypothesis?
Did Steve tell you that?
--- The Hiphopopotamus
___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] PEP 389: argparse - new command line parsing module

2009-09-28 Thread Floris Bruynooghe
On Mon, Sep 28, 2009 at 07:28:39AM -0700, Steven Bethard wrote:
> Ok, sounds like there are a number of supporters for keeping getopt
> around and just deprecating optparse. For those who'd like to keep
> getopt around, I have a few questions:
> 
> * Would you be opposed to a note in the getopt documentation
> suggesting argparse as an alternative?

No, I'd encourage such a note.

> * Would you like argparse to grow an add_getopt_arguments method (as
> in my other post)?

That looks nice indeed.

> * If argparse grew an add_getopt_arguments, would you still want to
> keep getopt around? And if so, why?

If clearly documented as "Hey, getopt users, check this out!" then I'd
be indifferent to the proposed deprecation of getopt.

Regards
Floris
___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Application configuration (was: PEP 389: argparse)

2009-09-28 Thread Olemis Lang
On Mon, Sep 28, 2009 at 10:33 AM, Oleg Broytman  wrote:
> On Mon, Sep 28, 2009 at 09:23:22AM -0600, m h wrote:
>
>> Does anyone else have interest in such functionality?  Is it outside
>> the realm of this PEP?
>
>   It is outside the scope of this particular PEP, but it is certainly an
> interesting idea.

:)

>   Actually it is the Right Thing, but I doubt it is possible to implement
> such a generic configuration *framework* in the Python standard *library*.
> Applications use different configfile layouts, some programs use w32
> registry instead of configfiles...
>

If this is the only reason :

Q:
  - What if only INI files are considered ?

In the end, that's the format included in stdlib and used by stdlib
commands (e.g. distutils ;o), and also by others (e.g. Trac, Hg, ...).
Reducing the scope in this direction could yield good results.

OTOH, if other cfg need to be supported, then possibly an «object
layer» (e.g. compatible with ConfigParser) could be used in order to
support further config layouts built outside stdlib. For instance, in
the case of WinReg :

{{{
#!python

RegParser = RegConfigParser(HKEY_CURRENT_USER, r'Software\MyApp\xxx')
RegParser.sections() # Children of this reg key
RegParser.options('s1')  # Values under
   #
HKEY_CURRENT_USER\Software\MyApp\xxx\s1
...
}}}

... and similar solutions could be implemented outside stdlib for e.g. YAML, ...

PS: BTW, is there something like this already for WinReg ?

-- 
Regards,

Olemis.

Blog ES: http://simelo-es.blogspot.com/
Blog EN: http://simelo-en.blogspot.com/

Featured article:
Sobrepasa las 300 descargas el módulo dutest  -
http://feedproxy.google.com/~r/simelo-es/~3/U5rff5iTQPI/sobrepasa-las-300-descargas-el-modulo.html
___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] please consider changing --enable-unicode default to ucs4

2009-09-28 Thread M.-A. Lemburg
James Y Knight wrote:
> On Sep 28, 2009, at 4:25 AM, M.-A. Lemburg wrote:
>> Distributions should really not be put in charge of upstream
>> coding design decisions.
> 
> I don't think you can blame distros for this one
>
> From PEP 0261:
> It is also proposed that one day --enable-unicode will just
> default to the width of your platforms wchar_t.
> 
> On linux, wchar_t is 4 bytes.

The PEP also has this to say:

This has the effect of doubling the size of most Unicode
strings. In order to avoid imposing this cost on every
user, Python 2.2 will allow the 4-byte implementation as a
build-time option. Users can choose whether they care about
wide characters or prefer to preserve memory.

And that's still true today. It was the main reason for not
making it the default on those days. Today, Python 3.x
uses Unicode for all strings, so while the RAM situation has
changed somewhat since Python 2.2, the change has a much
wider effect on the Python memory foot-print than in late 2001.

> If there's a consensus amongst python upstream that all the distros
> should be shipping Python with UCS2 unicode strings, you should reach
> out to them and say this, in a rather more clear fashion. Currently,
> most signs point towards UCS4 builds as being the better option.

UCS4 is the better option if you use lots of non-BMP code points
and if you have to regularly interface with C APIs using wchar_t
on Unix.

> Or, one might reasonably wonder why UCS-4 is an option at all, if nobody
> should enable it.

See above: there are use cases where this does make a lot of sense.

E.g. non-BMP code points can only be represented using surrogates on
UCS2 builds and these can be tricky to deal with (or at least
many people feel like it's tricky to deal with them ;-).

>> People building their own Python version will usually also build
>> their own extensions, so I don't really believe that the above
>> scenario is very common.
> 
> I'd just like to note that I've run into this trap multiple times. I
> built a custom python, and expected it to work with all the existing,
> installed, extensions (same major version as the system install, just
> patched). And then had to build it again with UCS4, for it to actually
> work. Of course building twice isn't the end of the world, and I'm
> certainly used to having to twiddle build options on software to get it
> working, but, this *does* happen, and *is* a tiny bit irritating.

Which is why I think that Python should include some more information
on the type of built being used, e.g. by placing the information
prominently on the startup line.

I still don't believe the above use case is a common one, though.

That said, Zooko's original motivation for the proposed change
is making installation of extensions easier for users. That's
a tools question much more than a Python Unicode one.

Aside: --enable-unicode is gone in Python 3.x. You now only
have the choice to use the default (which is UCS2) or switch on
the optional support for UCS4 by using --with-wide-unicode.

-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source  (#1, Sep 28 2009)
>>> Python/Zope Consulting and Support ...http://www.egenix.com/
>>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ...http://python.egenix.com/


::: Try our new mxODBC.Connect Python Database Interface for free ! 


   eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
   Registered at Amtsgericht Duesseldorf: HRB 46611
   http://www.egenix.com/company/contact/
___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] PEP 3144 review.

2009-09-28 Thread Dj Gilcrease
Ok updated patch so it meets the following conditions

>>> IPv4Network(192.168.1.1/24)
IPv4Network(192.168.1.0/24)

>>> x = IPv4Network('192.168.1.1/24')
>>> y = IPv4Network('192.168.1.0/24')
>>> x == y
True
>>> hash(x) == hash(y)
True

The ip you instantiated the Network with is still accessible though, so
>>> x.ip
IPv4Address('192.168.1.1')
>>> y.ip
IPv4Address('192.168.1.0')

I left it this way since there seems to be conflicting opinions on if
this should exist in the Network object or not

http://codereview.appspot.com/124057
___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] PEP 3144 review, and the inclusion process

2009-09-28 Thread Guido van Rossum
On Sun, Sep 27, 2009 at 5:32 PM, Antoine Pitrou  wrote:
> Peter Moody  hda3.com> writes:
>>
>> I've never said otherwise. In fact, from an email last night, "If what
>> the community requires is the library you've described, then ipaddr is
>> not that library." The changes *you* require make ipaddr significantly
>> less useful to me. I'm not prepared to make those changes in an
>> attempt seek acceptance to the stdlib, especially if the stdlib is in
>> such flux that I'll get to do this again in 18 months.
>
> Well, then I'm not sure why we have a PEP at all.
> If you don't want any significant changes and if you consider it to be *your*
> library, ipaddr can remain a third-party package that interested people can
> easily install (no pun ;-)) since AFAIK it's pure Python. It will also make
> maintenance easier for you, while freeing us (core developers) from having to
> bother about it in our daily development tasks.
>
> At least that's what I would advocate right now - not sure about what others
> think.

I think Peter is pretty frustrated by the many attacks on "his"
library. There are probably a number of different things going on
simultaneous: Peter has been driven into the defense by attacks both
reasonable and unreasonable, there have been misunderstandings all
around, teasing out use cases (by both parties) has been a problem.

Things might have gone differently if the PEP had started out with
multiple authors. Maybe it's not too late to add one or more other
interested parties to the PEP with the purpose of making the PEP more
clearly the result of a consensus-gathering process.  Any volunteers?

At the same time I don't think a complete reset of the proposed API is
necessary.  I am rather more thinking of judicious API tweaks in order
to cover some new use cases, without requiring a complete rewrite or
destroying the usability of the proposal for Peter's original use
cases. (In general I am pretty happy with the ipaddr code and API; it
looks like what I would have done, but then I am blissfully unaware of
some of the issues brought up in this thread.)

-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)
___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] PEP 389: argparse - new command line parsing module

2009-09-28 Thread Robert Kern

On 2009-09-28 10:37 AM, Steven Bethard wrote:

On Mon, Sep 28, 2009 at 8:26 AM, Michael Foord
  wrote:

m h wrote:


Perhaps this is OT, but since command line parsing is part of
configuration, I figure I'd throw it out there.  My scripts often have
configuration that the command line can override and I loosely follow
the example hierarchy[0] listed in The Art of Unix Programming.

Some configuration I want in a config file (but I want to override
from the command line) and sometimes it's very nice to use environment
variables for configuration.  So I do something like this:


Integration with command line options is an occasionally-requested feature
for ConfigObj. I've always said I would be open to patches...

In other words, yes I think there is demand for it. Whether it belongs
*immediately* in the standard library is another matter, but if you wrote a
layer that unified ConfigParser and argparse I think you will find that
people use it.

It is well outside the realm of this PEP however.


What Michael said. ;-) If you'd like to provide a patch for argparse
that provides such functionality, I'd be happy to review it.


cfgparse appears to fill this role for optparse. It might be straightforward to 
port it to argparse.


http://cfgparse.sourceforge.net/

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco

___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] PEP 3144 review, and the inclusion process

2009-09-28 Thread Peter Moody
[cc += david moss]

On Mon, Sep 28, 2009 at 9:39 AM, Guido van Rossum  wrote:
> On Sun, Sep 27, 2009 at 5:32 PM, Antoine Pitrou  wrote:
>> Peter Moody  hda3.com> writes:
>>>
>>> I've never said otherwise. In fact, from an email last night, "If what
>>> the community requires is the library you've described, then ipaddr is
>>> not that library." The changes *you* require make ipaddr significantly
>>> less useful to me. I'm not prepared to make those changes in an
>>> attempt seek acceptance to the stdlib, especially if the stdlib is in
>>> such flux that I'll get to do this again in 18 months.
>>
>> Well, then I'm not sure why we have a PEP at all.
>> If you don't want any significant changes and if you consider it to be *your*
>> library, ipaddr can remain a third-party package that interested people can
>> easily install (no pun ;-)) since AFAIK it's pure Python. It will also make
>> maintenance easier for you, while freeing us (core developers) from having to
>> bother about it in our daily development tasks.
>>
>> At least that's what I would advocate right now - not sure about what others
>> think.
>
> I think Peter is pretty frustrated by the many attacks on "his"
> library. There are probably a number of different things going on
> simultaneous: Peter has been driven into the defense by attacks both
> reasonable and unreasonable, there have been misunderstandings all
> around, teasing out use cases (by both parties) has been a problem.
>
> Things might have gone differently if the PEP had started out with
> multiple authors. Maybe it's not too late to add one or more other
> interested parties to the PEP with the purpose of making the PEP more
> clearly the result of a consensus-gathering process.  Any volunteers?

David called me a little over a week ago and expressed an interest in
doing exactly this cross continent/ocean coordination has been a
little difficult thus far and I'm not certain what his feelings on
this are now.

> At the same time I don't think a complete reset of the proposed API is
> necessary.  I am rather more thinking of judicious API tweaks in order
> to cover some new use cases, without requiring a complete rewrite or
> destroying the usability of the proposal for Peter's original use
> cases. (In general I am pretty happy with the ipaddr code and API; it
> looks like what I would have done, but then I am blissfully unaware of
> some of the issues brought up in this thread.)
>
> --
> --Guido van Rossum (home page: http://www.python.org/~guido/)
> ___
> Python-Dev mailing list
> [email protected]
> http://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe: 
> http://mail.python.org/mailman/options/python-dev/python-dev%40hda3.com
>
___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Fuzziness in io module specs - PEP update proposition V2

2009-09-28 Thread Guido van Rossum
On Sun, Sep 27, 2009 at 3:44 PM, Antoine Pitrou  wrote:
> Le Sun, 27 Sep 2009 14:24:52 -0700, Guido van Rossum a écrit :
> [truncate()]
>>
>> What compatibility, though?
>
> Compatibility accross the 3.x line.

Well, in this case, maybe compatibility with 2.x is more important --
this isn't something we can easily warn about in 2.6+. In addition
there's the POSIX rules.

>> f.truncate() behaves different in 2.x than
>> in 3.x, and in 2.x it seems to match the POSIX semantics (i.e. the seek
>> position is unchanged even though the file size is). Perhaps the changed
>> semantics was an oversight or a mistake?
>
> Perhaps it was, indeed. I don't know who made that decision in the first
> place.

It might well have been me (when implementing the earliest version of
io.py), and I might well have *though* that I implemented the same
rules as 2.x, and never bothered to check. :-(

All in all I think we should change this before it's too late; it will
affect a very small number of apps (perhaps none?), but I would rather
have the right semantics in the future. Also, it's trivial to write
code that doesn't care (in fact code running under 2.x and 3.x
probably will have to be written so that it doesn't care) so it's not
like changing this is going to make life harder for people wanting
multiple-version support.

-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)
___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] PEP 3144 review, and the inclusion process

2009-09-28 Thread Antoine Pitrou
Guido van Rossum  python.org> writes:
> 
> At the same time I don't think a complete reset of the proposed API is
> necessary.  I am rather more thinking of judicious API tweaks in order
> to cover some new use cases, without requiring a complete rewrite or
> destroying the usability of the proposal for Peter's original use
> cases.

I think the current API is mostly fine as well, except for one roadblock for
which several people has raised concerns, and that Peter stated he doesn't want
to change.

Regards

Antoine.


___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] PEP 3144 review, and the inclusion process

2009-09-28 Thread Steven D'Aprano
On Tue, 29 Sep 2009 02:39:06 am Guido van Rossum wrote:

> I think Peter is pretty frustrated by the many attacks on "his"
> library. There are probably a number of different things going on
> simultaneous: Peter has been driven into the defense by attacks both
> reasonable and unreasonable, there have been misunderstandings all
> around, teasing out use cases (by both parties) has been a problem.

As one of those people who has been critical of parts of Peter's module, 
I'd like to publicly say that I *mostly* like it. Sometimes we focus 
too much on the negatives and don't remember to give credit where 
credit is due.

Hopefully we can reach consensus, or at least understanding, on the 
remaining issue(s).



-- 
Steven D'Aprano
___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] PEP 389: argparse - new command line parsing module

2009-09-28 Thread m h
On Mon, Sep 28, 2009 at 9:37 AM, Steven Bethard
 wrote:
> On Mon, Sep 28, 2009 at 8:26 AM, Michael Foord
>  wrote:
>> m h wrote:
>>>
>>> Perhaps this is OT, but since command line parsing is part of
>>> configuration, I figure I'd throw it out there.  My scripts often have
>>> configuration that the command line can override and I loosely follow
>>> the example hierarchy[0] listed in The Art of Unix Programming.
>>>
>>> Some configuration I want in a config file (but I want to override
>>> from the command line) and sometimes it's very nice to use environment
>>> variables for configuration.  So I do something like this:
>>
>> Integration with command line options is an occasionally-requested feature
>> for ConfigObj. I've always said I would be open to patches...
>>
>> In other words, yes I think there is demand for it. Whether it belongs
>> *immediately* in the standard library is another matter, but if you wrote a
>> layer that unified ConfigParser and argparse I think you will find that
>> people use it.

Having it integrated with the option parser is ideal.  More people
will use it if it is in the stdlib.  Just like more people will use
argparse.

>>
>> It is well outside the realm of this PEP however.
>
> What Michael said. ;-) If you'd like to provide a patch for argparse
> that provides such functionality, I'd be happy to review it.
>

Patch submitted [0].  Accidentally marked as "Defect" instead of enhancement.
Comments/critiques welcome.

0 - http://code.google.com/p/argparse/issues/detail?id=35&q=label%3AType-Defect

Cheers,

-matt

> Steve
> --
> Where did you get that preposterous hypothesis?
> Did Steve tell you that?
>        --- The Hiphopopotamus
>
___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] PEP 3144 review, and the inclusion process

2009-09-28 Thread DrKJam
2009/9/28 Peter Moody 

> [cc += david moss]
>
> On Mon, Sep 28, 2009 at 9:39 AM, Guido van Rossum 
> wrote:
> > On Sun, Sep 27, 2009 at 5:32 PM, Antoine Pitrou 
> wrote:
> >> Peter Moody  hda3.com> writes:
> >>>
> >>> I've never said otherwise. In fact, from an email last night, "If what
> >>> the community requires is the library you've described, then ipaddr is
> >>> not that library." The changes *you* require make ipaddr significantly
> >>> less useful to me. I'm not prepared to make those changes in an
> >>> attempt seek acceptance to the stdlib, especially if the stdlib is in
> >>> such flux that I'll get to do this again in 18 months.
> >>
> >> Well, then I'm not sure why we have a PEP at all.
> >> If you don't want any significant changes and if you consider it to be
> *your*
> >> library, ipaddr can remain a third-party package that interested people
> can
> >> easily install (no pun ;-)) since AFAIK it's pure Python. It will also
> make
> >> maintenance easier for you, while freeing us (core developers) from
> having to
> >> bother about it in our daily development tasks.
> >>
> >> At least that's what I would advocate right now - not sure about what
> others
> >> think.
> >
> > I think Peter is pretty frustrated by the many attacks on "his"
> > library. There are probably a number of different things going on
> > simultaneous: Peter has been driven into the defense by attacks both
> > reasonable and unreasonable, there have been misunderstandings all
> > around, teasing out use cases (by both parties) has been a problem.
> >
> > Things might have gone differently if the PEP had started out with
> > multiple authors. Maybe it's not too late to add one or more other
> > interested parties to the PEP with the purpose of making the PEP more
> > clearly the result of a consensus-gathering process.  Any volunteers?
>
> David called me a little over a week ago and expressed an interest in
> doing exactly this cross continent/ocean coordination has been a
> little difficult thus far and I'm not certain what his feelings on
> this are now.
>
>
Sure, I'm happy to volunteer and help out. Let's have a good hard look at
all this and see what we can come up with.


> > At the same time I don't think a complete reset of the proposed API is
> > necessary.  I am rather more thinking of judicious API tweaks in order
> > to cover some new use cases, without requiring a complete rewrite or
> > destroying the usability of the proposal for Peter's original use
> > cases. (In general I am pretty happy with the ipaddr code and API; it
> > looks like what I would have done, but then I am blissfully unaware of
> > some of the issues brought up in this thread.)
> >
> > --
> > --Guido van Rossum (home page: 
> > http://www.python.org/~guido/
> )
> > ___
> > Python-Dev mailing list
> > [email protected]
> > http://mail.python.org/mailman/listinfo/python-dev
> > Unsubscribe:
> http://mail.python.org/mailman/options/python-dev/python-dev%40hda3.com
> >
>
___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] PEP 3144 review, and the inclusion process

2009-09-28 Thread Guido van Rossum
On Mon, Sep 28, 2009 at 11:17 AM, Antoine Pitrou  wrote:
> Guido van Rossum  python.org> writes:
>>
>> At the same time I don't think a complete reset of the proposed API is
>> necessary.  I am rather more thinking of judicious API tweaks in order
>> to cover some new use cases, without requiring a complete rewrite or
>> destroying the usability of the proposal for Peter's original use
>> cases.
>
> I think the current API is mostly fine as well, except for one roadblock for
> which several people has raised concerns, and that Peter stated he doesn't 
> want
> to change.

Well, I'm sure somebody can come up with a compromise that works for everyone.

Assuming this is the issue about e.g. IPNetwork('7.7.7.7/30') !=
IPNetwork('7.7.7.4/30') even though these describe the same network
(and in fact their .network and .broadcast attributes have the same
values), there are several compromises; I don't know the use cases
well enough to pick one:

- There could be an optional keyword parameter that decides whether
the last bits are cleared or not (one would have to argue which
behavior to use by default).

- The __eq__ (and hence __hash__) could be made to return equality
even though the .ip attribute returns a different value and the repr()
is different. This is not unheard-of; Python's __eq__ is best thought
of as some sort of equivalence. For example two dicts that only differ
in the order of the items still compare equal (even though .keys() and
repr() return different values).

I note that it's easy to convert the unnormalized form to the normalized form:

a = IPNetwork('7.7.7.7/30')
b = IPNetwork(a.network, a.prefixlen)

It would also be easy to have a property or method that returns the
normalized version; as an optimization it could return self if self is
already normalized. And there could be an explicit API to test whether
a network is normalized (something more explicit than a.network ==
a.ip).

I'll leave it to others to discuss the pros and cons of each
alternative. I don't know why Peter wants to preserve the unnormalized
data but I'm sure he has a good use case, otherwise he wouldn't be so
adamant to keep it. :-)

-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)
___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] PEP 3144 review.

2009-09-28 Thread Martin v. Löwis
> The fundamental divide here is between two behaviors.
> 
> ipaddr:
> 
> >>> x = IPv4Network('192.168.1.1/24')
> >>> y = IPv4Network('192.168.1.0/24')
> >>> x == y
> False
> >>> x.ip
> IPv4Address('192.168.1.1')
> 
> desired:
> 
> >>> x = IPv4Network('192.168.1.1/24')
> >>> y = IPv4Network('192.168.1.0/24')
> >>> x == y
> True
> >>> x.ip
> Traceback (most recent call last):
>   File "", line 1, in 
> AttributeError: 'IPv4Network' object has no attribute 'ip'

I can understand the debate around the comparison.

I cannot understand the complaint that networks where the base
address is not null-terminated should be banned, or useless
(which was the original concern that I responded to).

> Everything else is pretty much bikeshedding and can be dealt with.  This
> is fundamental and Peter has indicated he will not change it.

I can see why either behavior is desirable (i.e. comparison should
either use the specified address, or the network address); following
the Python Zen, we should refuse the temptation to guess.

Unfortunately, that would mean that we should provide two comparison
operations, and have neither available as == (unless one is more clearly
right than the other, which I'm skeptical about).

Regards,
Martin
___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] PEP 3144 review.

2009-09-28 Thread Martin v. Löwis
>> It's fairly obvious to me why the library should support 192.168.1.1/24
>> as an input, and return a network.
>>
>> End-users are likely going to enter such things (e.g. 82.94.164.162/29),
>> as they will know one IP address in the network (namely, of one machine
>> that they are looking at), and they will know the prefix length (more
>> often, how large the network is - 8 or 16 or 32). So very clearly,
>> end users should not be required to make the computation in their heads.
>>
>> So Python code has to make the computation, and it seems most natural
>> that the IP library is the piece of code that is able to compute a
>> network out of that input.
> 
> And this is a rather classic example of a misfeature.  "(Non-developer)
> End users will type it in" is not argument for supporting a particular
> string format as the primary constructor for an object.  Constructors
> are for *developers*.  They should be made most useful for *developers*.
> The issue of dealing with user input (which may have many other quirks)
> is separate and should be dealt with separately.

Still, people proposing that 192.168.1.1/24 should be rejected (I still
don't know whether anybody is actually proposing that) *have* to provide
a proposal how this should be input instead. Otherwise, such proposals
must be rejected, since there is a clear and evident need to support
such input somehow.

Regards,
Martin
___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] PEP 389: argparse - new command line parsing module

2009-09-28 Thread Brett Cannon
On Mon, Sep 28, 2009 at 08:49, Steven Bethard  wrote:
> On Mon, Sep 28, 2009 at 8:27 AM, Steven D'Aprano  wrote:
>> On Tue, 29 Sep 2009 12:28:39 am Steven Bethard wrote:
>>> * Would you like argparse to grow an add_getopt_arguments method (as
>>> in my other post)?
>>
>> 0
>>
>>> * If argparse grew an add_getopt_arguments, would you still want to
>>> keep getopt around? And if so, why?
>>
>> Simplicity of the learning curve. Using it is as simple as:
>>
>> getopt.getopt(sys.argv[1:], "a:b", ["alpha=", "beta"])
>
> You forgot the for-loop, nested if/else statements and type conversions. ;-)
>

=) I do wonder if people who are advocating for getopt sticking around
realize how much extra code must be written to make sure what it gives
back to you is in some sane manner.

Let's take ``getopt.getopt(sys.argv[1:], "a:b", ["alpha=", "beta"])``
as an example and simply assume that 'alpha' takes a string as an
argument and that it's required and that 'beta' is a boolean flag. To
pull everything out you could do::

  options, args = getopt.getopt(sys.argv[1:], "a:b", ["alpha=", "beta"])
  options_dict = dict(options)
  alpha = options_dict.get('-a', options_dict.get('--alpha', ''))
  beta = '-b' in options_dict or '--beta' in options_dict

  main(alpha, beta, args)

Obviously if one of the getopt supporters has a better way of doing
this then please speak up.

Now, Steven, can you show how best to do this in argparse? I am
willing to bet that the total number of lines to do this is not that
much more and does not require you to know to use 'or' or the dict
constructor along with dict.get() in order to keep it compact. I can
only imagine what some newbie might try to do in order to be correct
(if they even try).

-Brett
___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] PEP 389: argparse - new command line parsing module

2009-09-28 Thread Steven Bethard
On Mon, Sep 28, 2009 at 12:22 PM, Brett Cannon  wrote:
> On Mon, Sep 28, 2009 at 08:49, Steven Bethard  
> wrote:
>> On Mon, Sep 28, 2009 at 8:27 AM, Steven D'Aprano  wrote:
>>> On Tue, 29 Sep 2009 12:28:39 am Steven Bethard wrote:
 * Would you like argparse to grow an add_getopt_arguments method (as
 in my other post)?
>>>
>>> 0
>>>
 * If argparse grew an add_getopt_arguments, would you still want to
 keep getopt around? And if so, why?
>>>
>>> Simplicity of the learning curve. Using it is as simple as:
>>>
>>> getopt.getopt(sys.argv[1:], "a:b", ["alpha=", "beta"])
>>
>> You forgot the for-loop, nested if/else statements and type conversions. ;-)
>>
>
> =) I do wonder if people who are advocating for getopt sticking around
> realize how much extra code must be written to make sure what it gives
> back to you is in some sane manner.
>
> Let's take ``getopt.getopt(sys.argv[1:], "a:b", ["alpha=", "beta"])``
> as an example and simply assume that 'alpha' takes a string as an
> argument and that it's required and that 'beta' is a boolean flag. To
> pull everything out you could do::
>
>  options, args = getopt.getopt(sys.argv[1:], "a:b", ["alpha=", "beta"])
>  options_dict = dict(options)
>  alpha = options_dict.get('-a', options_dict.get('--alpha', ''))
>  beta = '-b' in options_dict or '--beta' in options_dict
>
>  main(alpha, beta, args)
>
> Obviously if one of the getopt supporters has a better way of doing
> this then please speak up.
>
> Now, Steven, can you show how best to do this in argparse?

Here's the same option parsing in argparse:

parser = argparse.ArgumentParser()
parser.add_argument('-a', '--alpha')
parser.add_argument('-b', '--beta', action='store_true')
args = parser.parse_args()

main(args.alpha, args.beta)

Or if those final positional arguments were actually meaningful, then
you would add one more argument like this::

parser = argparse.ArgumentParser()
parser.add_argument('-a', '--alpha')
parser.add_argument('-b', '--beta', action='store_true')
parser.add_argument('gammas', nargs='*')
args = parser.parse_args()

main(args.alpha, args.beta, args.gammas)

Steve
-- 
Where did you get that preposterous hypothesis?
Did Steve tell you that?
--- The Hiphopopotamus
___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] PEP 3144 review.

2009-09-28 Thread Martin v. Löwis
> Martin v. Löwis  v.loewis.de> writes:
>>> Could you explain what benefit there is for allowing the user to create 
>>> network objects that don't represent networks? Is there a use-case 
>>> where these networks-that-aren't-networks are something other than a 
>>> typo? Under what circumstances would I want to specify a network as 
>>> 192.168.1.1/24 instead of 192.168.1.0/24?
>>>
> [...]
>> So Python code has to make the computation, and it seems most natural
>> that the IP library is the piece of code that is able to compute a
>> network out of that input.
> 
> The thing is, it doesn't create a network, it creates a hybrid "network plus
> host" which retains knowledge about the original host (that is, 192.168.1.1
> rather than simply 192.168.1.0, if you enter "192.168.1.1/24").
> 
> That's what the OP meant with "networks-that-aren't-networks", and that's what
> people are objecting to.

That's not the question that was asked, though - the question asked
was "Under what circumstances would I want to specify...". I hope
most people agree that it is desirable to be able to specify a network
not just by its network address.

Regards,
Martin
___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] PEP 3144 review.

2009-09-28 Thread Antoine Pitrou

> Unfortunately, that would mean that we should provide two comparison
> operations, and have neither available as == (unless one is more clearly
> right than the other, which I'm skeptical about).

That's probably why some people have argued to have two separate classes for the
case of "networks" with significant lower bits.

(by "lower bits" I mean bits which would be zeroed when ANDing with the netmask)


___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] PEP 3144 review.

2009-09-28 Thread Antoine Pitrou
Martin v. Löwis  v.loewis.de> writes:
> 
> Still, people proposing that 192.168.1.1/24 should be rejected (I still
> don't know whether anybody is actually proposing that) *have* to provide
> a proposal how this should be input instead.

It was proposed to have a dedicated function or class method which would parse
such strings and return a (Network, Address) tuple corresponding to the two
objects that are described by that single notation.

  >>> parse_network_and_host('192.168.1.1/24')
  (Network('192.168.1.0/24'), Address('192.168.1.1'))


Regards

Antoine.


___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] PEP 3144 review.

2009-09-28 Thread Scott Dial
Martin v. Löwis wrote:
>> Martin v. Löwis  v.loewis.de> writes:
 Could you explain what benefit there is for allowing the user to create 
 network objects that don't represent networks? Is there a use-case 
 where these networks-that-aren't-networks are something other than a 
 typo? Under what circumstances would I want to specify a network as 
 192.168.1.1/24 instead of 192.168.1.0/24?

>> [...]
>>> So Python code has to make the computation, and it seems most natural
>>> that the IP library is the piece of code that is able to compute a
>>> network out of that input.
>> The thing is, it doesn't create a network, it creates a hybrid "network plus
>> host" which retains knowledge about the original host (that is, 192.168.1.1
>> rather than simply 192.168.1.0, if you enter "192.168.1.1/24").
>>
>> That's what the OP meant with "networks-that-aren't-networks", and that's 
>> what
>> people are objecting to.
> 
> That's not the question that was asked, though - the question asked
> was "Under what circumstances would I want to specify...". I hope
> most people agree that it is desirable to be able to specify a network
> not just by its network address.

I can't help but feel that you and many others jumping on Antoine et al.
have skipped reading or only skimmed this topic of discussion.

Antoine Pitrou wrote:
> We just need a factory function which returns a tuple after parsing:
>
> >>> addr, net = parse_address_with_mask('192.168.1.1/24')
> >>> addr == IPv4Address('192.168.1.1')
> True
> >>> net == IPv4Network('192.168.1.0/24')
> True

I still back this suggestion. I would also support a "loose=True" flag
for the IPNetwork constructor, which would allow host bits to be non-zero.

However, I will *never* support a proposal that includes retaining the
host address. I believe I am not alone in that. However, Peter has made
it quite clear that he will *never* change that about the IPNetwork classes.

I would be quite glad to not have ipaddr included in the stdlib. As I
can only imagine code that uses it being quite confusing to maintain
(e.g., "wait is that actually a network or is that someone using
IPNetwork to be an IPAddressWithMask?").

-1.

-- 
Scott Dial
[email protected]
[email protected]
___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] PEP 3144 review.

2009-09-28 Thread Antoine Pitrou
Le lundi 28 septembre 2009 à 22:11 +0200, "Martin v. Löwis" a écrit :
> 
> That's not the question that was asked, though - the question asked
> was "Under what circumstances would I want to specify...". I hope
> most people agree that it is desirable to be able to specify a network
> not just by its network address.

To me it makes no sense to "specify a network not just by its network
address", because by definition a prefix + mask is all that
characterizes a network: that's all you need to specify it entirely. 
Adding a "base address" would be like adding a "port number" attribute
to the Address class: it's abusing an existing class by adding
irrelevant information.

I may be mistaken, but it seems to me that, in the IP world, nowhere
does such a "network + host" hybrid appear. You find networks (prefix +
mask) in routing protocols, and host addresses in applicative protocols.


___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] PEP 3144 review.

2009-09-28 Thread R. David Murray

On Mon, 28 Sep 2009 at 22:11, "Martin v. L??wis" wrote:

Martin v. L??wis  v.loewis.de> writes:

Could you explain what benefit there is for allowing the user to create
network objects that don't represent networks? Is there a use-case
where these networks-that-aren't-networks are something other than a
typo? Under what circumstances would I want to specify a network as
192.168.1.1/24 instead of 192.168.1.0/24?


[...]

So Python code has to make the computation, and it seems most natural
that the IP library is the piece of code that is able to compute a
network out of that input.


The thing is, it doesn't create a network, it creates a hybrid "network plus
host" which retains knowledge about the original host (that is, 192.168.1.1
rather than simply 192.168.1.0, if you enter "192.168.1.1/24").

That's what the OP meant with "networks-that-aren't-networks", and that's what
people are objecting to.


That's not the question that was asked, though - the question asked
was "Under what circumstances would I want to specify...". I hope
most people agree that it is desirable to be able to specify a network
not just by its network address.


But then it's not a network, it is an ipaddress-plus-mask.  It is exactly
that conflation that we are objecting to.  There is no question about
the use case of _specifying_ a network ip plus a netmask and deriving
a network object from that.  That is unquestionably required by any
useful API.  The argument is about whether the object returned is a
Network object, or a hybrid object representing _both_ an IP address
and a network.  It is the latter, which ipaddr does, which many of us
find problematic and likely to lead to hard to read programs that will
probably produce maintenance errors.

I observe that this line in the current PEP rationale:

IP addresses and IP networks are distinct.

is not in fact achieved by the reference implementation.  Peter, however,
clearly thinks it is, since it is listed as a design goal of ipaddr.
This is a language disconnect I don't understand, which I think has
been the source of a lot of the difficulties in this thread.

--David___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] PEP 389: argparse - optparse compatibility

2009-09-28 Thread Antoine Pitrou
Steven Bethard  gmail.com> writes:
> 
> I could conceivably add an OptionParser class which::
> [...]

Actually, I think that would be a waste of time. It would be less time-consuming
to keep optparse.py than write a whole new compatibility bridge that you'll have
to debug and maintain anyway, with the added problem of making people annoyed by
whatever difference in behaviour happens to bite them. (*)

So I think the two only reasonable options are:

1. either keep optparse durably
2. or deprecate it

Given your precision about the proposed deprecation period (with the module
vanishing in 3.5), I guess I'm only -0.5 on it, rather than -1.

(*) (but of course I'm not against anyone wasting their time if they want to 
:-))

Regards

Antoine.


___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] PEP 3144 review.

2009-09-28 Thread Guido van Rossum
On Mon, Sep 28, 2009 at 1:36 PM, R. David Murray  wrote:
> On Mon, 28 Sep 2009 at 22:11, "Martin v. Löwis" wrote:
>>>
>>> Martin v. Löwis  v.loewis.de> writes:
>
> Could you explain what benefit there is for allowing the user to create
> network objects that don't represent networks? Is there a use-case
> where these networks-that-aren't-networks are something other than a
> typo? Under what circumstances would I want to specify a network as
> 192.168.1.1/24 instead of 192.168.1.0/24?
>
>>> [...]

 So Python code has to make the computation, and it seems most natural
 that the IP library is the piece of code that is able to compute a
 network out of that input.
>>>
>>> The thing is, it doesn't create a network, it creates a hybrid "network
>>> plus
>>> host" which retains knowledge about the original host (that is,
>>> 192.168.1.1
>>> rather than simply 192.168.1.0, if you enter "192.168.1.1/24").
>>>
>>> That's what the OP meant with "networks-that-aren't-networks", and that's
>>> what
>>> people are objecting to.
>>
>> That's not the question that was asked, though - the question asked
>> was "Under what circumstances would I want to specify...". I hope
>> most people agree that it is desirable to be able to specify a network
>> not just by its network address.
>
> But then it's not a network, it is an ipaddress-plus-mask.  It is exactly
> that conflation that we are objecting to.  There is no question about
> the use case of _specifying_ a network ip plus a netmask and deriving
> a network object from that.  That is unquestionably required by any
> useful API.  The argument is about whether the object returned is a
> Network object, or a hybrid object representing _both_ an IP address
> and a network.  It is the latter, which ipaddr does, which many of us
> find problematic and likely to lead to hard to read programs that will
> probably produce maintenance errors.
>
> I observe that this line in the current PEP rationale:
>
>    IP addresses and IP networks are distinct.
>
> is not in fact achieved by the reference implementation.  Peter, however,
> clearly thinks it is, since it is listed as a design goal of ipaddr.
> This is a language disconnect I don't understand, which I think has
> been the source of a lot of the difficulties in this thread.

I say the case has been argued extensively, let's wait for Peter to respond.

I would say that there certainly are precedents in other areas for
keeping the information about the input form around. For example,
occasionally it would be handy if parsing a hex integer returned an
object that was compatible with other integers but somehow kept a hint
that would cause printing it to use hex by default.

I see keeping around the IP address used to create a network object as
a similar edge case. I would probably define the __eq__ method to
implement equivalency (ignoring the form of the input), just as I
would in the case of the (hypothetical) hex integers. If you wanted to
do a comparison that includes the input IP address, you could use (a,
a.ip) == (b, b.ip).

-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)
___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] PEP 3144 review.

2009-09-28 Thread R. David Murray

On Mon, 28 Sep 2009 at 22:32, Antoine Pitrou wrote:

Le lundi 28 septembre 2009 ?? 22:11 +0200, "Martin v. L??wis" a ??crit :


That's not the question that was asked, though - the question asked
was "Under what circumstances would I want to specify...". I hope
most people agree that it is desirable to be able to specify a network
not just by its network address.


To me it makes no sense to "specify a network not just by its network
address", because by definition a prefix + mask is all that
characterizes a network: that's all you need to specify it entirely.
Adding a "base address" would be like adding a "port number" attribute
to the Address class: it's abusing an existing class by adding
irrelevant information.

I may be mistaken, but it seems to me that, in the IP world, nowhere
does such a "network + host" hybrid appear. You find networks (prefix +
mask) in routing protocols, and host addresses in applicative protocols.


You do find "address plus mask" when specifying an IP address for an
interface.  This is a shorthand for specifying the IP address plus the
network, since the network can be derived from the IP plus the mask.
But it is a _shorthand_, it isn't an entity in its own right.  There is
no such thing as "a network that has an IP", there is only an
_interface configuration_ that has an IP _and_ an associated network.

--David___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] PEP 389: argparse - new command line parsing module

2009-09-28 Thread Yuvgoog Greenle
for a live demo of how getopt is useful and flexible, I like how Audacity
uses it:
http://www.google.com/codesearch/p?hl=en&sa=N&cd=6&ct=rc#_hWFOhGz9lE/mezzo/scons/sconsign.py&q=getopt%20%22import%20getopt%22%20file:%5C.py$&l=264

To answer your question, it goes like this:
options, args = getopt.getopt(sys.argv[1:], "a:b", ["alpha=", "beta"])
for o, a in options:
if o in ('-a', '--alpha'):
alpha = a
elif o in ('-b', '--beta'):
beta = a
main(alpha, beta, args)

Notice a few things:
1. There is no chance of the script killing itself. In argparse and optparse
exit() is called on every parsing error (btw because of this it sucks to
debug parse_args in an interpreter).
2. There is no chance the parser will print things I don't want it to print.
3. You can do whatever you want using this flow - call a function, a binary
operator (ie | is used in audacity scons example above)
4. in argparse this flow can be emulated and would be nicer, in ('-a',
'--alpha') becomes == 'alpha'

In a perfect world, getopt would be the low level parser that argparse and
optparse rely on. This is not too far fetched btw, all that needs to be done
is add another optional argument to getopt that would allow '-' and '--' to
be replaced with arbitrary signs, OR moving the parsing code from argparse
into getopt.

On Mon, Sep 28, 2009 at 10:57 PM, Steven Bethard
wrote:

> On Mon, Sep 28, 2009 at 12:22 PM, Brett Cannon  wrote:
> > On Mon, Sep 28, 2009 at 08:49, Steven Bethard 
> wrote:
> >> On Mon, Sep 28, 2009 at 8:27 AM, Steven D'Aprano 
> wrote:
> >>> On Tue, 29 Sep 2009 12:28:39 am Steven Bethard wrote:
>  * Would you like argparse to grow an add_getopt_arguments method (as
>  in my other post)?
> >>>
> >>> 0
> >>>
>  * If argparse grew an add_getopt_arguments, would you still want to
>  keep getopt around? And if so, why?
> >>>
> >>> Simplicity of the learning curve. Using it is as simple as:
> >>>
> >>> getopt.getopt(sys.argv[1:], "a:b", ["alpha=", "beta"])
> >>
> >> You forgot the for-loop, nested if/else statements and type conversions.
> ;-)
> >>
> >
> > =) I do wonder if people who are advocating for getopt sticking around
> > realize how much extra code must be written to make sure what it gives
> > back to you is in some sane manner.
> >
> > Let's take ``getopt.getopt(sys.argv[1:], "a:b", ["alpha=", "beta"])``
> > as an example and simply assume that 'alpha' takes a string as an
> > argument and that it's required and that 'beta' is a boolean flag. To
> > pull everything out you could do::
> >
> >  options, args = getopt.getopt(sys.argv[1:], "a:b", ["alpha=", "beta"])
> >  options_dict = dict(options)
> >  alpha = options_dict.get('-a', options_dict.get('--alpha', ''))
> >  beta = '-b' in options_dict or '--beta' in options_dict
> >
> >  main(alpha, beta, args)
> >
> > Obviously if one of the getopt supporters has a better way of doing
> > this then please speak up.
> >
> > Now, Steven, can you show how best to do this in argparse?
>
> Here's the same option parsing in argparse:
>
>parser = argparse.ArgumentParser()
>parser.add_argument('-a', '--alpha')
>parser.add_argument('-b', '--beta', action='store_true')
>args = parser.parse_args()
>
>main(args.alpha, args.beta)
>
> Or if those final positional arguments were actually meaningful, then
> you would add one more argument like this::
>
>parser = argparse.ArgumentParser()
>parser.add_argument('-a', '--alpha')
>parser.add_argument('-b', '--beta', action='store_true')
>parser.add_argument('gammas', nargs='*')
>args = parser.parse_args()
>
>main(args.alpha, args.beta, args.gammas)
>
> Steve
> --
> Where did you get that preposterous hypothesis?
> Did Steve tell you that?
>--- The Hiphopopotamus
> ___
> Python-Dev mailing list
> [email protected]
> http://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe:
> http://mail.python.org/mailman/options/python-dev/ubershmekel%40gmail.com
>
___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] PEP 3144 review.

2009-09-28 Thread Martin v. Löwis
> You do find "address plus mask" when specifying an IP address for an
> interface.  This is a shorthand for specifying the IP address plus the
> network, since the network can be derived from the IP plus the mask.
> But it is a _shorthand_

Just as he says.

Martin
___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] PEP 3144 review.

2009-09-28 Thread Martin v. Löwis
> I would say that there certainly are precedents in other areas for
> keeping the information about the input form around. For example,
> occasionally it would be handy if parsing a hex integer returned an
> object that was compatible with other integers but somehow kept a hint
> that would cause printing it to use hex by default.

At the risk of bringing in false analogies: it seems that Python
typically represents values of some type in their canonical form,
rather than remembering the form in which they arrived in the program:
- integer values "forget" how many preceding zeroes they have
- string literals forget which of the characters had been escaped, and
  whether the string was single- or double-quoted
- floating point values forget a lot more about their literal
  representation (including even the literal decimal value)

I guess a close case would be rational numbers: clearly, 3÷2 == 6÷4;
would a Python library still remember (and repr) the original numerator
and denominator?

Regards,
Martin
___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] PEP 3144 review.

2009-09-28 Thread Daniel Stutzbach
On Mon, Sep 28, 2009 at 4:29 PM, "Martin v. Löwis" wrote:

> I guess a close case would be rational numbers: clearly, 3÷2 == 6÷4;
> would a Python library still remember (and repr) the original numerator
> and denominator?
>

No need for a hypothetical, rational numbers were added in Python 2.6:

Python 2.6.2 (r262:71600, Apr 15 2009, 07:20:39)
[GCC 3.4.4 (cygming special, gdc 0.12, using dmd 0.125)] on cygwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import fractions
>>> fractions.Fraction(6,4)
Fraction(3, 2)

--
Daniel Stutzbach, Ph.D.
President, Stutzbach Enterprises, LLC 
___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] PEP 389: argparse - new command line parsing module

2009-09-28 Thread Cameron Simpson
On 27Sep2009 21:24, Steven Bethard  wrote:
| On Sun, Sep 27, 2009 at 9:09 PM, "Martin v. Löwis"  wrote:
| >> If you think getopt and optparse should stick around in 3.X, why is
| >> that? If you think there are things that getopt and optparse do better
| >> than argparse, could you please give some examples?
| >
| > I personally consider getopt superior to both optparse and argparse.
| > Those are terribly verbose in specifying arguments, whereas getopt's
| > sequence-of-letters is really nice and compact.
| 
| Thanks for the concrete example. Although I'm unconvinced that the
| characters you save in the sequence of letters in the getopt.getopt
| call aren't afterwards wasted on type conversions, if/else statements
| and variable assignments in the subsequent loop, it would be pretty
| simple to add to argparse something like::
| 
| ArgumentParser.add_getopt_arguments(options[, long_options])

Yes please!

I'm also very fond of the succinct getopt sequence-of-letters style;
it works really well for the simple cases.

Disclaimer: I've not used the optparse et al modules because getopt has
covered my needs and my C background made getopt the natural module to
start with. I have written simple getopt-equivalent option parsers a
number of times though. (Of course, that choice also drives me to adapt
my option wishes to stuff that getopt can do:-)

Clarification: this isn't a vote for preferring getopt, it's a vote for
availability of the sequence-of-letters style.

Cheers,
-- 
Cameron Simpson  DoD#743
http://www.cskk.ezoshosting.com/cs/

The most annoying thing about being without my files after our disc crash was
discovering once again how widespread BLINK was on the web.
___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] PEP 389: argparse - new command line parsing module

2009-09-28 Thread Oleg Broytman
On Tue, Sep 29, 2009 at 07:44:50AM +1000, Cameron Simpson wrote:
> | ArgumentParser.add_getopt_arguments(options[, long_options])
> 
> Yes please!
> 
> I'm also very fond of the succinct getopt sequence-of-letters style;
> it works really well for the simple cases.

   The syntax "a:b" is also widely known; people who are often write small
shell scripts are certainly accustomed to it (I am).

> Clarification: this isn't a vote for preferring getopt, it's a vote for
> availability of the sequence-of-letters style.

   +1

Oleg.
-- 
 Oleg Broytmanhttp://phd.pp.ru/[email protected]
   Programmers don't die, they just GOSUB without RETURN.
___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] IO module precisions and exception hierarchy

2009-09-28 Thread Greg Ewing

Michael Foord wrote:

Well, the file type knows what mode it is opened in so catching these 
errors is really not difficult at all.


Yes, in this particular case it could do some checking of
its own before making the system call. But this still has
nothing to do with the exception hierarchy.

--
Greg
___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] IO module precisions and exception hierarchy

2009-09-28 Thread Michael Foord

Greg Ewing wrote:

Michael Foord wrote:

Well, the file type knows what mode it is opened in so catching these 
errors is really not difficult at all.


Yes, in this particular case it could do some checking of
its own before making the system call. But this still has
nothing to do with the exception hierarchy.

You said that having an exception hierarchy was impossible because the 
only information we have is the error number. Some errors could easily 
be caught.


Michael

--
http://www.ironpythoninaction.com/
http://www.voidspace.org.uk/blog


___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] PEP 3144 review.

2009-09-28 Thread Nick Coghlan
Peter Moody wrote:
>> Assuming the Network type loses the notion of a specific host (or host 
>> address,
>> or `ip`) attached to it, yes.
> 
> this is "less useful (strictly removing functionality)" and is an
> example of what I explicitly said I was not going to do with ipaddr.

A possible compromise then:

Just change the definition of network equality to only consider the
network address and ignore the ip attribute. Optionally provide a
separate comparison method that pays attention to the ip attribute
(keeping in mind that it isn't particularly hard for people to write out
"net1 == net2 and net1.ip == net2.ip" if they care about the extra state).

Then "IPNetwork" can be largely documented as a true IP network
definition, with the "Host with Netmask" use case handled by having an
IPNetwork object with "net.ip != net.network".

Regards,
Nick.

-- 
Nick Coghlan   |   [email protected]   |   Brisbane, Australia
---
___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] PEP 3144 review, and the inclusion process

2009-09-28 Thread Andrew McNamara
>I've never said otherwise. In fact, from an email last night, "If what
>the community requires is the library you've described, then ipaddr is
>not that library." The changes *you* require make ipaddr significantly
>less useful to me. I'm not prepared to make those changes in an
>attempt seek acceptance to the stdlib, especially if the stdlib is in
>such flux that I'll get to do this again in 18 months.

The point is that, having brought it to us, we all now have an interest
in the outcome. Whatever goes into the standard library is going to be
something that we have to live with for a long time, and now is our best
chance to shape the result.

I understand your concern over introducing more classes, however I still
feel my suggested functional decomposition is worth that cost because
I consider the behaviour of my suggested classes to be more intuitive.
I should mention that I am not a computer scientist, and none of this is
motivated by a desire for theoretical purity - just practical experience.

One of my concerns now is that if a code block receives an IPv4Network
instance, it does not know whether this represents a host address
with mask, or a network address. In some contexts, this distinction is
critical, and confounding them can result in delayed error reporting or
erroneous behaviour. Your addition of a strict flag does not completely
address this concern as it assumes the instantiation and use occur in
proximity, which is often not the case in large projects.

I suspect you are also mistaken in thinking my proposed changes make
the module less useful for you - maybe you can describe the problem as
you see it?


As a reminder to people who have come late to this thread, I proposed three
classes per protocol:

IPv?Address
A single address

IPv?AddressWithMask
A single address with implied IPv?Network

IPv?Network
A container-like network address (with strict mask parsing)

Further:

 * Comparisons between classes should be disallowed. 

 * The IPv?AddressWithMask class would have a .address and .mask attributes
   containing IPv?Addresses, and a .network attribute for the containing
   network (as specified by the mask, and lazily constructed).

 * The IPv?Network class would have similar .address and .mask attributes.

In cases where you want to allow lax specification of network addresses,
this would be spelt:

IPv?AddressWithMask(some_address).network

At first glance, this seems somewhat round-about, however it makes explicit
the potential loss of bits.

-- 
Andrew McNamara, Senior Developer, Object Craft
http://www.object-craft.com.au/
___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] PEP 3144 review.

2009-09-28 Thread R. David Murray

On Mon, 28 Sep 2009 at 13:43, Guido van Rossum wrote:

On Mon, Sep 28, 2009 at 1:36 PM, R. David Murray  wrote:
I would say that there certainly are precedents in other areas for
keeping the information about the input form around. For example,
occasionally it would be handy if parsing a hex integer returned an
object that was compatible with other integers but somehow kept a hint
that would cause printing it to use hex by default.

I see keeping around the IP address used to create a network object as
a similar edge case. I would probably define the __eq__ method to
implement equivalency (ignoring the form of the input), just as I
would in the case of the (hypothetical) hex integers. If you wanted to
do a comparison that includes the input IP address, you could use (a,
a.ip) == (b, b.ip).


Ignoring Antoine's excellent points for the moment, to my mind
one difference between your integer-with-hex-hint and ipaddr's
ip-with-netmask is that there is a one to one mapping between the
canonical hex representations and the integer.

If you want to argue that the _exact_ input string be preserved in the
integer object, then there might be more of a direct analogy.  Except that
ipaddr isn't preserving the input _string_, it's preserving a canonical
representation of that string, so even there the analogy wouldn't be
all that close.  The difference here is that ipaddr is preserving input
information that is irrelevant to the object being returned (a network).

The fractions case is much closer.

Or consider another analogy: the ipaddr case is like the mod function
returning a single object that is supposed to be the remainder,
but also has an extra field that records the original input number.
This might be a useful operator and object type in certain contexts, but
it is something that would be layered on top of the real mod function
that returns a simple integer remainder.  You would never approve this
remainder-with-saved-input as the data type returned by the mod operator.
(I hope :)

Similarly, there should be a basic ipaddr parsing function (and I don't
much care how you spell it, even though I have opinions) that returns
an ip address and a network object when given an ipaddress-plus-netmask
string.  An additional object built upon those fundamental data types that
remembers the input IP would be fine, but the data type that remembers
the IP should _not_ be the fundamental data type in the system.  That
strikes me as poor design, OO or otherwise.

In fact, your "sometimes it would be useful if" phrasing indicates that
your 'integer with hex hint' data type would also not be the fundamental
data type, but instead a subclass of int.

--David
___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] please consider changing --enable-unicode default to ucs4

2009-09-28 Thread Martin v. Löwis
James Y Knight wrote:
> On Sep 28, 2009, at 4:25 AM, M.-A. Lemburg wrote:
>> Distributions should really not be put in charge of upstream
>> coding design decisions.
> 
> I don't think you can blame distros for this one
> 
> From PEP 0261:
> It is also proposed that one day --enable-unicode will just
> default to the width of your platforms wchar_t.
> 
> On linux, wchar_t is 4 bytes.
> 
> If there's a consensus amongst python upstream that all the distros
> should be shipping Python with UCS2 unicode strings, you should reach
> out to them and say this, in a rather more clear fashion. Currently,
> most signs point towards UCS4 builds as being the better option.

There is no such consensus. Linux distributions really should build
Python in UCS-4 mode, and I would be in favor of making it the default
to match wchar_t.

Regards,
Martin
___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] PEP 3144 review.

2009-09-28 Thread Guido van Rossum
On Mon, Sep 28, 2009 at 7:17 PM, R. David Murray  wrote:
> On Mon, 28 Sep 2009 at 13:43, Guido van Rossum wrote:
>>
>> On Mon, Sep 28, 2009 at 1:36 PM, R. David Murray 
>> wrote:
>> I would say that there certainly are precedents in other areas for
>> keeping the information about the input form around. For example,
>> occasionally it would be handy if parsing a hex integer returned an
>> object that was compatible with other integers but somehow kept a hint
>> that would cause printing it to use hex by default.
>>
>> I see keeping around the IP address used to create a network object as
>> a similar edge case. I would probably define the __eq__ method to
>> implement equivalency (ignoring the form of the input), just as I
>> would in the case of the (hypothetical) hex integers. If you wanted to
>> do a comparison that includes the input IP address, you could use (a,
>> a.ip) == (b, b.ip).
>
> Ignoring Antoine's excellent points for the moment, to my mind
> one difference between your integer-with-hex-hint and ipaddr's
> ip-with-netmask is that there is a one to one mapping between the
> canonical hex representations and the integer.
>
> If you want to argue that the _exact_ input string be preserved in the
> integer object, then there might be more of a direct analogy.  Except that
> ipaddr isn't preserving the input _string_, it's preserving a canonical
> representation of that string, so even there the analogy wouldn't be
> all that close.  The difference here is that ipaddr is preserving input
> information that is irrelevant to the object being returned (a network).

I disagree that recording the exact input string would be a better
analogy; as you say the hypothetical hex integer doesn't save the
exact input string -- it remembers that the base was 16 That happens
to be 1 bit of information if you're only considering hex vs. decimal,
but one could imagine a further version that supports any base between
1 and 36 (or however far you want to go).

Whether I typed 01.01.01.01/024 or 1.1.1.1/24 is (presumably)
irrelevant for this case, since the byte values are the same; whether
I typed 1.1.1.1/24 or 1.1.1.0/24 *is* relevant (for Peter). There's
probably another form, 16843009/24, which is also equivalent.

> The fractions case is much closer.

Hardly -- I've never heard of someone who had a use case for
denormalized fractions, but I don't doubt that Peter has a use case
for denormalized IPNetwork objects. (Do you doubt that Peter has such
a use case? If so, we have a much more fundamental disagreement.)

> Or consider another analogy: the ipaddr case is like the mod function
> returning a single object that is supposed to be the remainder,
> but also has an extra field that records the original input number.
> This might be a useful operator and object type in certain contexts, but
> it is something that would be layered on top of the real mod function
> that returns a simple integer remainder.  You would never approve this
> remainder-with-saved-input as the data type returned by the mod operator.
> (I hope :)

Not a very strong argument, since that use case is purely
hypothetical. I brought up the hex integer example to show that it is
possible to conceive of use cases for objects that record some sort of
information about their creation history. Now you're bending my line
of reasoning by going from the assertion "Guido would never approve of
mod-returning-remainder-with-saved-input" (which happens to be true
until a real use case is found) to "Guido would never approve of *any*
operator that keeps some traces of its creation history" (which is
false -- dict being just one counter-example :-).

> Similarly, there should be a basic ipaddr parsing function (and I don't
> much care how you spell it, even though I have opinions) that returns
> an ip address and a network object when given an ipaddress-plus-netmask
> string. An additional object built upon those fundamental data types that
> remembers the input IP would be fine, but the data type that remembers
> the IP should _not_ be the fundamental data type in the system.  That
> strikes me as poor design, OO or otherwise.

Poor design is highly subjective, and I simply disagree that one
design is a priori better or worse than the other. This is Python,
where practicality beats purity, so things like expediency of
implementation, frequency of various uses, etc., matter.

Right now, without knowing more about Peter's use case, I'd sat that
__eq__ should ignore the .ip attribute, but that's more based on
trying to get enough people to drop their opposition than on a full
understanding of the use case. I do note that if Peter's use case is
at all common, reducing the number of classes is a worthy goal, and
Python has a bit of a history of preferring a small number of
Swiss-army-knife classes over a multitude of simple classes.

> In fact, your "sometimes it would be useful if" phrasing indicates that
> your 'integer with hex hint' data type would also not

Re: [Python-Dev] PEP 389: argparse - new command line parsing module

2009-09-28 Thread Martin v. Löwis
> Let's take ``getopt.getopt(sys.argv[1:], "a:b", ["alpha=", "beta"])``
> as an example and simply assume that 'alpha' takes a string as an
> argument and that it's required and that 'beta' is a boolean flag. To
> pull everything out you could do::
> 
>   options, args = getopt.getopt(sys.argv[1:], "a:b", ["alpha=", "beta"])
>   options_dict = dict(options)
>   alpha = options_dict.get('-a', options_dict.get('--alpha', ''))
>   beta = '-b' in options_dict or '--beta' in options_dict
> 
>   main(alpha, beta, args)
> 
> Obviously if one of the getopt supporters has a better way of doing
> this then please speak up.

As Yuvgoog Greenle says, the canonical getopt way is to write

alpha = None
beta = False
options, args = getopt.getopt(sys.argv[1:],"a:b",['alpha=','beta']):
for opt, val in options:
if arg in ('-a','--alpha'):
alpha = val
elif arg in ('-b','--beta'):
beta = True
main(alpha, beta, args)

Even though this is many more lines, I prefer it over
optparse/argparse: this code has only a single function call,
whereas the argparse version has three function calls to remember.
The actual processing uses standard Python data structures which
I don't need to look up in the documentation.

> Now, Steven, can you show how best to do this in argparse?

This demonstrates my point: you were able to use getopt right away
(even though not in the traditional way), whereas you need to ask
for help on using argparse properly.

> I am
> willing to bet that the total number of lines to do this is not that
> much more and does not require you to know to use 'or' or the dict
> constructor along with dict.get() in order to keep it compact.

See above - getopt users don't care about compactness in
the processing.

> I can
> only imagine what some newbie might try to do in order to be correct
> (if they even try).

Depends on the background of the newbie. If they come from C, they
immediately recognize the way of doing things.

Regards,
Martin
___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] IO module precisions and exception hierarchy

2009-09-28 Thread Greg Ewing

Michael Foord wrote:

You said that having an exception hierarchy was impossible because the 
only information we have is the error number.


No, I said that having an exception hierarchy wouldn't
help you to sort out the different meanings of a single
error code.

If you have some *other* way of sorting them out, then
obviously you can represent them using different
exceptions if you want.

--
Greg
___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] PEP 389: argparse - new command line parsing module

2009-09-28 Thread Steven Bethard
On Mon, Sep 28, 2009 at 8:44 PM, "Martin v. Löwis"  wrote:
>> Let's take ``getopt.getopt(sys.argv[1:], "a:b", ["alpha=", "beta"])``
>
> As Yuvgoog Greenle says, the canonical getopt way is to write
[snip getopt code]
> Even though this is many more lines, I prefer it over
> optparse/argparse: this code has only a single function call,
> whereas the argparse version has three function calls to remember.
> The actual processing uses standard Python data structures which
> I don't need to look up in the documentation.
>
>> Now, Steven, can you show how best to do this in argparse?
>
> This demonstrates my point: you were able to use getopt right away
> (even though not in the traditional way), whereas you need to ask
> for help on using argparse properly.

I don't think this is fair at all. I am totally unable to write getopt
code without checking the documentation -- I don't remember the format
string syntax, nor what the function returns. But that's just how
library modules work -- if you don't know the library, you have to
read the documentation. The only reason getopt is easier for you is
that you're already familiar with the API from C. That said, I can
certainly understand that folks who use getopt in C would have an easy
transition to getopt in Python and a harder transition to argparse.

You didn't directly answer my question of whether adding an
"add_getopt_arguments" function would meet your needs, but I infer
from your answer above that it wouldn't because you'd still need to
make multiple function calls which is your primary complaint. So at
this point, I think it's clear that there's nothing I can reasonably
add to argparse to make getopt people more comfortable that isn't just
duplicating what's already in getopt.

So let's just deprecate optparse (as in the PEP), and leave getopt
alone (other than adding a note to the documentation suggesting
argparse as an alternative).
-- 
Where did you get that preposterous hypothesis?
Did Steve tell you that?
--- The Hiphopopotamus
___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] PEP 3144 review.

2009-09-28 Thread Greg Ewing

Guido van Rossum wrote:

I've never heard of someone who had a use case for
denormalized fractions, but I don't doubt that Peter has a use case
for denormalized IPNetwork objects. (Do you doubt that Peter has such
a use case? If so, we have a much more fundamental disagreement.)


It would be interesting to know what his use case is. Maybe
it can be addressed in a different way that doesn't require
denormalised network objects.

> my "sometimes it

would be useful" was meant as a gentle nudge in the direction of
keeping the .ip attribute.


I think the point is that it would have to be useful a
*lot* of the time, not just "sometimes", to be worth
having it on every IPNetwork object.

--
Greg

___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com