[issue47257] add methods to get first and last elements of a range

2022-04-08 Thread paul rubin


paul rubin  added the comment:

Oh nice, I didn't realize you could do that.  len(range) and bool(range) (to 
test for empty) also work.  Ok I guess this enhancement is not needed.  I will 
close ticket, hope that is procedurally correct, otherwise feel free to fix.  
Thanks.

--
resolution:  -> rejected
stage:  -> resolved
status: open -> closed

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



[issue47257] add methods to get first and last elements of a range

2022-04-08 Thread paul rubin


New submission from paul rubin :

Inspired by a question on comp.lang.python about how to deal with an int set 
composed of integers and ranges.  Range objects like range(1,5,2) contain 
start, stop, and step values, but it's messy and potentially tricky to get the 
actual first and last values of the range.  Examples:

range(1,5,2) - first = 1, last = 3

range (5, 1, 2) - range is empty, first = last = None

range(5, 1, -1) - first is 5, last is 2

Note in the case where the range is not empty, you can get the "last" by a 
messy calculation but it's easier to pick the first element from the reverse 
iterator.  But then you might forget to catch the stopiteration exception in 
the case that the list is empty.  The same goes for the first element, roughly. 
 And constructing the iterators just to pick one element seems like unnecessary 
overhead.

So it is better to have actual methods for these, with type Optional[int].  
Then mypy should remind you to check for the empty case if you forget.

--
messages: 416962
nosy: phr
priority: normal
severity: normal
status: open
title: add methods to get first and last elements of a range
type: enhancement

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



[issue44571] itertools: takedowhile()

2021-10-11 Thread paul rubin


paul rubin  added the comment:

Bah, the above doesn't work in the cases where the iterator is empty or 
(different symptom) where the tail part is empty.  Rather than posting a 
corrected version (unless someone wants it) I'll just say not to use that code 
fragment, but that the intended API still looks reasonable.  I do support 
having some kind of solution but don't want to keep stretching out an already 
closed discussion unless people think there is more to say.

--

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



[issue44571] itertools: takedowhile()

2021-10-11 Thread paul rubin


paul rubin  added the comment:

Oh wow, before_and_after will go into the itertools module per that patch?  I 
found this issue while looking for a way to this, but had written the following 
implementation:

def span(pred, xs):
# split xs into two iterators a,b where a() is the prefix of xs 
# that satisfies the predicate, and b() is the rest of xs.  
# Similar to Data.List.Span in Haskell. 

ixs = iter(xs)
t = None
def a():
nonlocal t
for x in ixs:
if pred(x): yield x
else: break
t = x
def b():
return itertools.chain([t], ixs)
return a, b

def tspan():  # test
xs = [1,3,5,2,4,6,8]
def odd(x): return x%2==1
# This should print [1,3,5] then [2,4,6,8]  
for p in span(odd, xs):
print(list(p()))

--
nosy: +phr

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



[issue40734] /usr/bin surprisingly in sys.path under IDLE

2020-05-26 Thread paul rubin


paul rubin  added the comment:

Yes as mentioned I'm running Debian GNU/Linux, not Windows.  By "idle is 
installed in /usr/bin" I mean that it is an executable shell script stored at 
/usr/bin/idle .  Yes, shell prompt is the $ prompt to bash.  When I run 
"python3 -m idlelib", /usr/bin does not appear in sys.path.  "python -m 
idlelib" attempts to run python2 and I don't have python2 idle installed.  I'll 
see if I can figure out what's going on with sys.path in the user process.  The 
explanation about the two processes was helpful.  Thanks.

--

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



[issue40734] /usr/bin surprisingly in sys.path under IDLE

2020-05-25 Thread paul rubin


paul rubin  added the comment:

I'm using Debian 10 MATE live install and have been running IDLE by clicking an 
icon on the top panel, but I just tried running IDLE from the shell prompt in a 
terminal window, and also see /usr/bin in the path.  In both cases, the output 
of os.system('pwd').read() is my home directory.  IDLE itself is installed in 
/usr/bin .

--

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



[issue40734] /usr/bin surprisingly in sys.path under IDLE

2020-05-25 Thread paul rubin


paul rubin  added the comment:

Matthias, I get the same result you do when I run python from the shell command 
line.  I see /usr/bin in the path when I import sys and print sys.path from 
inside IDLE.  In other words this is an IDLE configuration oddity.  Again I 
don't know if it's a bug.  It's perplexing though.

--

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



[issue40733] Make IDLE doc more visible, mention in main python docs page

2020-05-23 Thread paul rubin


paul rubin  added the comment:

I think I used duckduckgo to find the docs.  They don't change much between 
versions and I was trying to find how to do a specific thing.  My installation 
has the docs included but it didn't explain how to do what I wanted, so I had 
hoped there was a more complete doc on docs.python.org.  Unfortunately it 
turned out to be the same doc.  The functionality I wanted (to put a startup 
script in .idlerc) seems to not exist though.  I'll research workarounds a bit 
further and possibly open an RFE if people think that sounds right.

--

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



[issue40733] mention IDLE in main python docs page

2020-05-22 Thread paul rubin


Change by paul rubin :


--
title: mention IDLE in main python ocs page -> mention IDLE in main python docs 
page

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



[issue40734] /usr/bin surprisingly in sys.path under IDLE

2020-05-22 Thread paul rubin


New submission from paul rubin :

This is in the standard python 3.7.3 install under Debian 10.  It's possible 
that this is on purpose, and it's (separately) possible that the Debian 
packagers did this for some reason.  I'm not sure it's a bug but am reporting 
it as it's an oddity that might warrant looking into.

When I look at sys.path in the IDLE shell, the path includes /usr/bin, which is 
not there under the normal python prompt.  Since /usr/bin is not a place where 
python modules usually live, it's a bit strange to find it on the path.  It 
doesn't seem healthy since it could lead to surprises.  But maybe I'm missing 
something.

Feel free to close this if the inclusion is intentional.

--
assignee: terry.reedy
components: IDLE
messages: 369643
nosy: phr, terry.reedy
priority: normal
severity: normal
status: open
title: /usr/bin surprisingly in sys.path under IDLE
type: behavior
versions: Python 3.7

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



[issue40733] mention IDLE in main python ocs page

2020-05-22 Thread paul rubin


New submission from paul rubin :

The IDLE documentation is in https://docs.python.org/3/library/idle.html which 
is not where I'd have thought to look for it, since I think of IDLE as an 
application rather than a library.  So I looked for it on the main docs page, 
docs.python.org, and didn't find it there.  I ended up finding it by web 
search.  

I guess its current location is reasonable, but maybe a link to it could be 
included in docs.python.org's main page left side navigation panel, or IDLE 
could simply be mentioned in the entry for library documentation.

--
assignee: docs@python
components: Documentation
messages: 369640
nosy: docs@python, phr
priority: normal
severity: normal
status: open
title: mention IDLE in main python ocs page
type: enhancement

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



[issue40411] frozen collection.Counter

2020-05-14 Thread paul rubin


paul rubin  added the comment:

Note: PEP 603 may essentially take care of this, if it is accepted.

--

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



[issue40028] Math module method to find prime factors for non-negative int n

2020-05-14 Thread paul rubin


paul rubin  added the comment:

I don't think the interface needs much bikeshedding, as long as the implementer 
chooses something reasonable.  E.g. factor(30) gives the list [2,3,5].  
Implementation is harder if you want to handle numbers of non-trivial size.  
Neal Koblitz's book "A Course in Number Theory and Cryptogoraphy" has good 
coverage of factoring algorithms.  To factor numbers up to 2**64, Pollard's rho 
method is simple to code and has always worked for me, but I don't know if 
there are specific numbers in that range that could give it trouble.  For 
bigger numbers you need fancier algorithms and eventually fancy hardware and 
long computing runs.  Part of a design discussion would include trying to 
decide the scope of such a module.

--

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



[issue40623] JSON streaming

2020-05-14 Thread paul rubin


paul rubin  added the comment:

Also I didn't know about ndjson (I just looked at it, ndjson.org) but its 
existence and formalization is even more evidence that this is useful.  I'll 
check what the two different python modules linked from that site do that's 
different from your example of iterating through the file by lines.

--

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



[issue40623] JSON streaming

2020-05-14 Thread paul rubin


paul rubin  added the comment:

It's coming back to me, I think I used the no-separator format because I made 
the multi-document input files by using json.dump after opening the file in 
append mode.  That seems pretty natural.  I figured the wikipedia article and 
the json.tool patch just released were evidence that there is interest in this. 
 The approach of writing newlines between the docs and iterating through lines 
is probably workable though.  I don't know why I didn't do that before.  I 
might not have been sure that json docs never contain newlines.

Really it would be nice if json.load could read in anything that json.dump 
could write out (including with the indent parameter), but that's potentially 
more complicated and might conflict with the json spec.

--

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



[issue40623] JSON streaming

2020-05-14 Thread paul rubin


paul rubin  added the comment:

Note: the function in my attached file wants no separation at all between the 
json docs (rather than a newline between them), but that was ok for the 
application I wrote it for some time back.  I forgot about that when first 
writing this rfe so thought I better clarify.

--

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



[issue40623] JSON streaming

2020-05-14 Thread paul rubin


Change by paul rubin :


Added file: https://bugs.python.org/file49154/jsonstream.py

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



[issue40623] JSON streaming

2020-05-14 Thread paul rubin


New submission from paul rubin :

This is a well-explored issue in other contexts: 
https://en.wikipedia.org/wiki/JSON_streaming

There is also a patch for it in json.tool, for release in 3.9: 
https://bugs.python.org/issue31553

Basically it's often convenient to have a file containing a list of json docs, 
one per line.  However, there is no convenient way to read them back in one by 
one, since json.load(filehandle) barfs when it sees the unexpected newline at 
the end of the first doc.

It would be great if the json module itself had a function to handle this.  I 
have an awful hack that I use myself, that is not suitable for a production 
library, but I'll attach it to show what functionality I'm suggesting.  I hope 
this is simple enough to not need a PEP.  Thanks!

--
components: Library (Lib)
files: jsonstream.py
messages: 368823
nosy: phr
priority: normal
severity: normal
status: open
title: JSON streaming
type: enhancement
Added file: https://bugs.python.org/file49153/jsonstream.py

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



[issue36027] Support negative exponents in pow() where a modulus is specified.

2020-05-14 Thread paul rubin


paul rubin  added the comment:

https://bugs.python.org/issue457066  The old is new again ;-).

--
nosy: +phr

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



[issue40028] Math module method to find prime factors for non-negative int n

2020-05-14 Thread paul rubin


paul rubin  added the comment:

I'm the one always asking for more stuff in the stdlib, but above some 
simplistic approaches this seems out of scope.  Doing it usefully above say 
2**32 requires fancy algorithms.  Better to use some external package that 
implements that stuff.

--
nosy: +phr

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



[issue40411] frozen collection.Counter

2020-04-27 Thread paul rubin


paul rubin  added the comment:

Totally tangential: Veky, your ordinal example would work ok in Haskell and 
you'd have omega work the same way as epsilon0.  Take a look at Herman Ruge 
Jervell's book "Proof Theory" for a really nice tree-based ordinal notation 
that goes much higher than epsilon0.  It would be cool if your student 
implemented it.  Raymond, I agree that ordinals are a very esoteric use of 
multisets ;).

--

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



[issue40411] frozen collection.Counter

2020-04-27 Thread paul rubin


paul rubin  added the comment:

Yeah I think the basic answer to this ticket is "Python doesn't really have 
multisets and a proposal to add them should go somewhere else".  Fair enough-- 
consider the request withdrawn from here.

Regarding minimalism vs completeness, regarding some feature X (say X is 
multisets), it's reasonable per minimalism to decide not to have X.  But if on 
weighing the use cases you decide to have X after all, I think it's best to 
implement X properly and completely with all the edge cases handled, rather 
than implement a half-baked subset.  That was something Java was historically 
very good at and Python wasn't.  I guess that is one for the theorists though.  
Thanks everyone.

--

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



[issue40411] frozen collection.Counter

2020-04-27 Thread paul rubin


paul rubin  added the comment:

Oops I meant "*without* 100s of third party modules" in the case of ruby gems 
or npm.  There are just a few pip modules that I really use all the time, most 
notably bs4.  I continue to use urllib/urllib2 instead of requests because I'm 
used to them and because they eliminate an unnecessary dependency.

--

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



[issue40411] frozen collection.Counter

2020-04-27 Thread paul rubin


paul rubin  added the comment:

Kyle, thanks, I saw your comment after posting my own, and I looked at 
Raymond's mailing list post that you linked.  I do think that "completing the 
grid" is a good thing in the cases where it's obvious how to do it (if there's 
one and one obvious way, then doing it that way should work), and having 
missing combinations in the grid is also a form of interface complexity (expect 
subset to work, find that it doesn't, and implement some hack).  Also it seems 
to me that sets, dicts, bags are basic data objects in many languages these 
days, without a lot of design space to move around in.  So we don't have to 
worry much about constraining future choices.  We could just look at Smalltalk 
or Ruby or whatever and just do what they did.  

However, that is philosophical.  I did learn from Raymond's message that 
Counter doesn't really attempt to be a multiset implementation.  In that case, 
it works for what it is made for, so it really then is a separate question of 
whether implementing multisets properly is worthwhile.  (That's as opposed to 
saying we already have a multiset implementation but some functionality is 
missing from it).

I dislike the concept of shovelling off basic functionality to 3rd party 
libraries.  The rejection of that philosophy (Python's old motto "Batteries 
included") is one of the things that attracted me to Python in the first place. 
 Though that value is mostly historical now, I'm sad about the loss.  It's 
impossible to write a large Ruby or Javascript (npm) application with 100s of 
third party modules, every one of which is an attack vector ("supply chain 
attack" is the current buzzword), and  whose implementations vary widely in 
quality and usability.  I looked at the docs for Ruby's multiset gem 
(https://maraigue.hhiro.net/multiset/) and they are partly in Japanese.  Python 
has until the past few years managed to keep away from that kind of thing.

--

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



[issue40411] frozen collection.Counter

2020-04-27 Thread paul rubin


paul rubin  added the comment:

Yes, the idea was for them to be hashable, to be used as dict keys.  E.g. if 
you use frozensets to model graphs, you'd use frozen multisets for hypergraphs. 
 My immediate use case involved word puzzles, e.g. treating words as bags of 
scrabble tiles with letters on them, and finding out what other words you could 
form from the letters.  It is not a pressing need.  

I'm trying to remember what the other missing operation I ran into was, a few 
days ago.  It may have been subset.  I found a workaround but it seemed a bit 
ugly.  It would be nice if Counters could also be thought of as multisets which 
can do the same things sets can do with unneeded head scratching.  It seems 
like counters and multisets/bags really are different things conceptually.  
Their operations and implementations overlap, but they are different.  E.g. it 
can make sense for a counter to have a negative count of something, but not for 
a bag.

--

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



[issue1726707] add itertools.ichain function and count.getvalue

2020-04-27 Thread paul rubin


paul rubin  added the comment:

Note, nowadays this is implement as itertools.chain.from_iterable .

--

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



[issue40334] PEP 617: new PEG-based parser

2020-04-27 Thread paul rubin


Change by paul rubin :


--
nosy:  -phr

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



[issue40411] frozen collection.Counter

2020-04-27 Thread paul rubin


New submission from paul rubin :

It would be nice to have frozen Counters analogous to frozensets, so they are 
usable as dictionary keys.  One can of course create frozenset(counter.items()) 
but that means the set items are tuples rather than the original set elements, 
so it's no longer quick to check membership.  I can work around this in my 
immediate application but it seems like a shortcoming.  There are some other 
set operations that aren't supported by counters either, that would be nice if 
they are conceptually multisets.

--
components: Library (Lib)
messages: 367472
nosy: phr
priority: normal
severity: normal
status: open
title: frozen collection.Counter
type: enhancement

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



[issue40334] PEP 617: new PEG-based parser

2020-04-27 Thread paul rubin


paul rubin  added the comment:

I just saw this.  Interesting.  Sometimes I use ast.literal_eval to read big, 
deeply nested data objects.  I can probably convert to JSON if necessary but 
it's another thing to watch out for.  I might try to benchmark some of these.

--
nosy: +phr

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



[issue38333] add type signatures to library function docs

2019-10-03 Thread paul rubin


paul rubin  added the comment:

I don't think we're going to accomplish anything continuing the eternal 
static-vs-dynamic debate, which in Python's case has already been resolved by 
adding optional static typing.  It's a done deal, and the issue here is just 
how to document it.  Erlang (via the Erlang Dialyzer), Clojure, and Racket have 
all been down a similar road and gained some value from it.

Haskell's Maybe type (its version of Option) works fine.  In Python the 
convention of returning None for a missing value is not great, but we are stuck 
with it and Option[whatever] is helpful.

--

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



[issue38333] add type signatures to library function docs

2019-10-03 Thread paul rubin


paul rubin  added the comment:

At first glance, having a typeclass for each protocol (at least the widely used 
ones) seems fine.  It's inherent in Haskell and a lot of libraries are 
organized around a common set of typeclasses--look up "Typeclassopedia" for 
descriptions of them.  Certainly the case of abs (which you asked about by 
name), the typeclass is already there in the typing module.

You're right about abs(complex) returning float.  Haskell's type signature for 
abs is "Num a => a -> a" which means the input type is the same as the output.  
That is a little bit peculiar since the abs of a complex number is complex, but 
we usually think of abs as a mathematical norm, which is conventionally a real.

Anyway, "abs(x: Abs[T]) -> Any"  is a better-than-nothing signature for abs, 
and the docs can comment a little further, and maybe someday it could even do a 
type-level lookup at typechecking time, i.e. have something like Haskell's 
"type families".

I like to think it's possible to supply reasonable signatures for most 
functions.  I just fixed a bug in something today because bs4 (beautiful soup 
4) has no typeshed stub so mypy uses Any for functions like soup.find, instead 
of Optional[tag].  So the program worked fine as long as find kept returning a 
tag, but then crashed because it hit a document without a tag and my code 
didn't check for None.  That's something more precise types would have caught 
at mypy time.

--

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



[issue38333] add type signatures to library function docs

2019-10-02 Thread paul rubin


paul rubin  added the comment:

abs takes any value that understands the __abs__ method and returns something 
of the same type.  In fact there is already a type protocol for it:

https://mypy.readthedocs.io/en/stable/protocols.html#supportsabs-t

So abs's signature would be (x : Abs[T]) -> T where T is a type parameter.  

I'm sure there are some examples where no good signature is possible, but lots 
of others are fine.  Someone did a Smalltalk study long ago and found that most 
functions were monomorphic in practice even though Smalltalk is dynamically 
typed like Python.  As a matter of style, Python code tends to be typed even 
when it doesn't have to be.  Not all the time of course.

I'm still getting used to types and mypy (I was a py2 holdout til quite 
recently, and mypy has been a more attractive reason to change than any of the 
other stuff) and I do keep noticing cases that don't work as I hoped, but it's 
still a good move in general.

--

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



[issue38333] add type signatures to library function docs

2019-10-02 Thread paul rubin


paul rubin  added the comment:

Yes, the suggestion was just for the docs, and since those are intended for 
human rather than machine consumption, it's fine if there are some blurry cases 
where there is no signature.  Ideally in those cases, the issue should be 
explained in the doc text.

I actually don't see what's wrong with including signatures in the source code 
as well, as long as doing so doesn't break anyone's existing code.  I agree 
with Veky that one should be very hesitant about breaking existing working 
code, even if that code relies on undocumented behavior.

--

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



[issue38333] add type signatures to library function docs

2019-09-30 Thread paul rubin


New submission from paul rubin :

It would be nice if the library reference manual had type signatures for all 
the stdlib functions at some point.  It might be possible to extract a lot of 
them automatically from typeshed and semi-automatically paste them into the doc 
files.  It might also be ok to do this gradually.  I can help with this but 
wouldn't want to take on the entire task.

--
assignee: docs@python
components: Documentation
messages: 353634
nosy: docs@python, phr
priority: normal
severity: normal
status: open
title: add type signatures to library function docs
type: enhancement
versions: Python 3.9

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



[issue24820] IDLE themes for light on dark

2015-09-30 Thread Marc Paul Rubin

Marc Paul Rubin added the comment:

Greetings from an idle-dev 'lurker.' Has anyone tested the new dark
theme with a Set Breakpoint command? The dark theme is great for me
except for this quirk: breakpoints are invisible on my test box. Under
the Classic light scheme breakpoints appear on a bright yellow 
background. 
 
Appreciate all the interest and work going into idle these days. I'll
add any needed details on request. For starters I'm just wondering
whether breakpoints have yet to be tested with this dark theme.
 
Thanks, 
jayseye (Marc Paul Rubin)

--
nosy: +jayseye

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



[issue5784] raw deflate format and zlib module

2015-04-26 Thread paul rubin

paul rubin added the comment:

Hey, thanks for updating this.  I still remember the nasty incident that got me 
filing this report in the first place.  I'll look at the patch more closely 
when I get a chance, but the immediate comment I'd make is it's worth adding a 
sentence saying explicitly to use wbits=-15 if you need to interoperate with 
some other libraries like PHP, that strip off the header.

--

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



[issue7153] add start arg to max and min functions

2009-10-17 Thread paul rubin

paul rubin p...@users.sourceforge.net added the comment:

1. Yes, the idea is to figure out the best solution and go with it (or
decide to do nothing).  That many possibilities exist just points to the
need for experience and wisdom in identifying the best choice (one and
preferably only one).  One of the attractive points about Python is it
comes with so many such decisions already wisely made.  The design
wisdom embodied in Python is almost like a useful software library in
its own right.  So the presence of multiple choices should be seen as an
invitation to resolve the issue, not a flag to keep it unresolved.

2. I agree that the multi-arg and iterator API's should have been done
as separate functions (or denoted through a keyword arg), but what we
have isn't too bad, and it's what we have.

3.  min(iterable, key=f, start=x) should obviously default to the same
thing as min([x], key=f).  min(*args, start=x) should only be allowed
when len(args)==1, since the start arg is restricted to the case of
minimum over an iterator.  min(start=x) should not be allowed.

4. I'm in general unpersuaded by the argument that a stdlib function
isn't worth having because the same thing can be done by bloating up the
user code.  Python code should be concise, which means using the stdlib
in preference to writing more user-defined functions that the next
maintainer has to figure out, and which may have their own bugs and
unhandled edge cases.  For stdlib design, it's mostly a matter of
deciding whether a construction occurs often enough to write a re-usable
function for.  In this case it wouldn't have occurred to me to write any
of those suggested versions, instead of writing reduce(max, iterator, 0)
with an explanatory comment.  But even the observation that reduce
made me bloat up the comments in the code, rather than the code itself,
was enough to get me to suggest adding the initial arg.

5. I don't think it's good to rely on bool(seq) or len(seq) to be
available if there's a simple construction (like here) that works for
arbitrary iterables.  It's better to handle the general case.  I hadn't
even realized til just now that sequence and iterable didn't mean
the same thing.

6. Yes, I know it's not common to trap ValueErrors when using max with
iterables.  I wrote code without such traps myself and then got bitten
by unhandled exceptions when some of those iterables turned out to be
empty (hence my reduce hack).  It wouldn't surprise me if lots more
such code out there is similarly buggy.  I think it's good to make
bug-avoiding mechanisms obvious and convenient.

--

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



[issue7153] add start arg to max and min functions

2009-10-16 Thread paul rubin

New submission from paul rubin p...@users.sourceforge.net:

Lots of times I want to find the largest element of a list or sequence,
defaulting to 0 if the list or sequence is empty.  max(seq) throws an
exception if seq is empty, so I end up using reduce(max, seq, 0).  That
is a standard functional programming idiom but can be a bit confusing to
imperative-style Python programmers.  

max with multiple args is already overloaded to mean the maximum of the
args, so I think it would be a good fix to add a keyword arg to accept
an optional initial value:  max(seq, start=0).  For symmetry, min should
accept the same arg.

The alternatives to using reduce aren't so attractive.  If seq happens
to be a list, there might be a temptation to conditionalize on
len(seq)==0, but that is poor style since it will break if seq later
changes to an arbitrary sequence.  And trying to test it by calling
.next() and saving the value and/or trapping StopIteration gets awfully
messy.

--
components: Library (Lib)
messages: 94145
nosy: phr
severity: normal
status: open
title: add start arg to max and min functions
versions: Python 2.5

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



[issue7153] add start arg to max and min functions

2009-10-16 Thread paul rubin

Changes by paul rubin p...@users.sourceforge.net:


--
type:  - feature request

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



[issue7153] add start arg to max and min functions

2009-10-16 Thread paul rubin

paul rubin p...@users.sourceforge.net added the comment:

David, I'm not on that mailing list so hadn't seen the earlier
discussion.  I sympathasize with Raymond's YAGNI argument because I'm
comfortable with reduce(max,seq,0); but then I remember there was once a
movement to remove the reduce function from builtins, which would have
broken that idiom.  I also understand that not everyone is comfortable
with that style.  I recently had to hand over some code to another
programmer where I had used that idiom, and in the course of adding
comments to the code in preparation for the handover, I found myself
writing quite a few words about why I'd used reduce that way, so I
figured that explicit is better than implicit suggests adding default
or initial args to the max function, just like reduce already has (I
figure that max on a sequence is a special case of reduce).

My proposed python implementation:

def mymax(*args, **kwargs):
  if len(args)  1: return max(*args)
  if len(args) == 0: raise TypeError, mymax needs at least one
positional arg
  if 'initial' in kwargs: return reduce(max,args[0],kwargs['initial'])
  return reduce(max,args[0])

--

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



[issue5784] raw deflate format and zlib module

2009-04-17 Thread paul rubin

New submission from paul rubin p...@users.sourceforge.net:

The zlib module doesn't support raw deflate format, so it doesn't
completely interoperate with php's gzdeflate function and fails to
decompress some strings that web browsers can decompress.

A workaround is to use a special zlib feature and pass the value -15 as
the wbits arg: 

plaintext = zlib.deflate(compressed_text, wbits=-15)

I don't know if it's appropriate to mess with the code, but at minimum I
urge that the workaround be mentioned in the docs.  We had a tremendous
distruption where I work because of a malicious raw-deflated PHP script
that we couldn't decompress with Python for analysis.  We had to resort
to decompressing in a PHP container that (through my slipping up) it
proceeded to escape from.  

Help us Python-Kenobi, save us from PHP ;-)

--
messages: 86094
nosy: phr
severity: normal
status: open
title: raw deflate format and zlib module

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



[issue5784] raw deflate format and zlib module

2009-04-17 Thread paul rubin

Changes by paul rubin p...@users.sourceforge.net:


--
components: +Library (Lib)
type:  - feature request
versions: +Python 2.5

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



[issue5784] raw deflate format and zlib module

2009-04-17 Thread paul rubin

paul rubin p...@users.sourceforge.net added the comment:

I should have mentioned, the docs do say When wbits is negative, the
standard gzip header is suppressed; this is an undocumented feature of
the zlib library, used for compatibility with unzip‘s compression file
format but this wasn't enough at the time to figure out the issue.  I
suggest adding something like and the 'raw deflate' format supported by
PHP and some web browsers.  

I better see if I can research the exact situation a bit further, for
the sake of documenting it accurately, if others here think it's a good
idea.

--

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



[issue1560032] confusing error msg from random.randint

2009-03-30 Thread paul rubin

paul rubin p...@users.sourceforge.net added the comment:

Daniel, thanks--I didn't mean to jump on you, so I'm sorry if it came
across that way.  Maybe I'm a little oversensitized to this issue due to
some unrelated incidents with other programs.

I'll try to write a more detailed reply and maybe include a patch later
(I can't do it right now).

Regards

Paul

--

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



[issue1560032] confusing error msg from random.randint

2009-03-29 Thread paul rubin

paul rubin p...@users.sourceforge.net added the comment:

ajaksu2, I don't understand why you want to close this bug if it isn't
fixed.  I can accept that it's not the highest priority issue in the
world, but it's something that trips up users from time to time, and it
ix obviously fixable.  Closing bugs like this is demoralizing to those
of us who take the trouble to submit them in the hope of helping improve
Python.  I've noticed that any number of times over the years, and
recently saw a post about Ubuntu bug triage that expressed the sentiment
better than I could:

http://www.chiark.greenend.org.uk/ucgi/~cjwatson/blosxom/2009/03/02

(And while trying to locate that several week old post through web
searches, I came across several more like it...).  

Anyway, the best thing to do with bugs like this is fix them.  If there
is other work with higher priority, the obvious thing is to just leave
the bug open so someone gets around to it sooner or later.  Closing the
bug without a fix comes across as destructive.

--

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



[issue4123] random.shuffle slow on deque

2008-10-16 Thread paul rubin

paul rubin [EMAIL PROTECTED] added the comment:

If it's not a bug, it is at least a surprising gotcha that should be
documented in the manual.  The collections module is described in the
library docs as high performance container datatypes but I could not
possibly consider the observed behavior to be high performance.

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue4123
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue4123] random.shuffle slow on deque

2008-10-14 Thread paul rubin

New submission from paul rubin [EMAIL PROTECTED]:

This is observed in Python 2.5.1, I haven't tried any later versions.

d = collections.deque(xrange(10))
random.shuffle(d)

is quite slow.  Increasing the size to 200k, 300k, etc. shows that the
runtime increases quadratically or worse.  It's much faster to convert
the deque to a list, shuffle the list, and make a new deque from the
shuffled list.

--
components: Library (Lib)
messages: 74773
nosy: phr
severity: normal
status: open
title: random.shuffle slow on deque
versions: Python 2.5

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue4123
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue2857] add codec for java modified utf-8

2008-05-15 Thread paul rubin

paul rubin [EMAIL PROTECTED] added the comment:

Some java applications use it externally.  The purpose seems to be to
prevent NUL bytes from appearing inside encoded strings which can
confuse C libraries that expect NUL's to terminate strings.  My
immediate application is parsing lucene indexes:

http://lucene.apache.org/java/docs/fileformats.html#Chars

__
Tracker [EMAIL PROTECTED]
http://bugs.python.org/issue2857
__
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue2857] add codec for java modified utf-8

2008-05-15 Thread paul rubin

paul rubin [EMAIL PROTECTED] added the comment:

Also, according to wikipedia, tcl also uses that encoding.

__
Tracker [EMAIL PROTECTED]
http://bugs.python.org/issue2857
__
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue2857] add codec for java modified utf-8

2008-05-15 Thread paul rubin

paul rubin [EMAIL PROTECTED] added the comment:

I'm not sure what you mean by ditto for Lucene indexes.  I wasn't
planning to use C code.  I was hoping to write Python code to parse
those indexes, then found they use this weird encoding, and Python's
codec set is fairly inclusive already, so this codec sounded like a
reasonably useful addition.  It probably shows up other places as well.
 It might even be a reasonable internal representation for Python, which
as I understand it currently can't represent codepoints outside the BMP.
 Also, it is used in Java serialization, which I think of as a somewhat
weird and whacky thing, but it's conceivable that somebody someday might
want to write a Python program that speaks the Java serialization
protocol (I don't have a good sense of whether that's feasible).

Writing an application specific codec with the C API is doable in
principle, but it seems like an awful lot of effort for just one quickie
program.  These indexes are very large and so writing the codec in
Python would probably be painfully slow.

__
Tracker [EMAIL PROTECTED]
http://bugs.python.org/issue2857
__
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue2857] add coded for java modified utf-8

2008-05-14 Thread paul rubin

New submission from paul rubin [EMAIL PROTECTED]:

For object serialization and some other purposes, Java encodes unicode
strings with a modified version of utf-8:

http://en.wikipedia.org/wiki/UTF-8#Java
http://java.sun.com/javase/6/docs/api/java/io/DataInput.html#modified-utf-8

It is used in Lucene index files among other places.

It would be useful if Python had a codec for this, maybe called UTF-8J
or something like that.

--
components: Library (Lib)
messages: 66843
nosy: phr
severity: normal
status: open
title: add coded for java modified utf-8
versions: Python 2.5

__
Tracker [EMAIL PROTECTED]
http://bugs.python.org/issue2857
__
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue2138] Add a factorial function

2008-03-17 Thread paul rubin

paul rubin [EMAIL PROTECTED] added the comment:

Rather than factorial how about a product function, so factorial(n) =
product(xrange(1,n+1)).  I do like the idea of an imath module whether
or not it has factorial, and the topic of this rfe has drifted somewhat
towards the desirability of such a module, which is a reasonable
question for discussion.  I'm more or less indifferent to whether imath
has factorial in it or not.  I do think it would be useful for it to
have functions for things like binomial coefficients that were
implemented a little more cleverly than with large factorials, but in
this case factorial should be there too.

__
Tracker [EMAIL PROTECTED]
http://bugs.python.org/issue2138
__
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue2151] no way to get http result status from urllib

2008-02-21 Thread paul rubin

New submission from paul rubin:

I don't see any way in the docs to get the status of an http request, in
particular I want to know whether it's a 404.  It does show up in the
guts of the library so maybe I can extract it somehow, but there should
be a simple documented way.

Also, the urllib doc says the info() method returns a mimetools.Message
instance, but what actually comes back is an httplib.HTTPMessage
instance.  I guess that's a subclass, but it's confusing.  The doc
should describe what actually comes back.

--
components: Library (Lib)
messages: 62613
nosy: phr
severity: normal
status: open
title: no way to get http result status from urllib
type: feature request
versions: Python 2.5

__
Tracker [EMAIL PROTECTED]
http://bugs.python.org/issue2151
__
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue2138] Factorial

2008-02-21 Thread paul rubin

paul rubin added the comment:

I like the idea of having some integer math functions like this in the
stdlib; whether in the math module or elsewhere doesn't matter much.  In
particular I remember having to implement xgcd on several separate
occasions for unrelated applications, each time requiring about the same
head scratching as before, and wishing it was in the stdlib so that
could be avoided.  This type of function is complicated enough to not
rattle immediately off the fingertips, but not complicated enough to be
worth looking up in a reference book.

http://bugs.python.org/issue457066 has some discussion of xgcd and
modular inverses.

--
nosy: +phr

__
Tracker [EMAIL PROTECTED]
http://bugs.python.org/issue2138
__
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1742669] %d format handling for long values

2008-02-21 Thread paul rubin

paul rubin added the comment:

I would prefer that %d signal an error 100% of the time if you give it a
float.  It should not accept 42.0.  It is for printing integers.

--
nosy: +phr

_
Tracker [EMAIL PROTECTED]
http://bugs.python.org/issue1742669
_
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com