[issue15034] Document best practices for exceptions

2020-11-10 Thread Vedran Čačić

Vedran Čačić  added the comment:

Terry: of course, if a method is not overridden, there's no need to call 
super()'s method, since the only thing it would do is call the same thing that 
would be called without overriding.

But of course, if Exception's __init__ does anything, then super() should be 
called from the overrridden method.

--
nosy: +veky

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



[issue35712] Make NotImplemented unusable in boolean context

2020-11-09 Thread Vedran Čačić

Vedran Čačić  added the comment:

... as it probably should: look at https://bugs.python.org/msg349303

Yes, filtering comprehensions are a frequently used niche, and too long in the 
"official" parlance. I seem to recall that 

[x in mylist if x is not None]

(instead of triple-x version) was rejected because it was too hard to parse. 
Maybe now we can really implement it?

--

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



[issue42222] Modernize integer test/conversion in randrange()

2020-10-31 Thread Vedran Čačić

Vedran Čačić  added the comment:

Yes, the ability to write randrange(1e9) is sometimes nice. And the fact that 
it might give the number outside the intended range with probability 1e-17 is 
not really an important argument (people have bad intuitions about very small 
probabilities). But if we intend to be consistent with range, then of course 
this must go.

--
nosy: +veky

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



[issue31504] Documentation for return value for string.rindex is missing when search string is empty

2020-10-31 Thread Vedran Čačić

Vedran Čačić  added the comment:

Maybe you would use 5, but I would use 7 and get the same result. If the docs 
say "X.rindex(Y) == i means i is the highest index where Y is found in X", and 
"Y is found in X at i" is interpreted as "X[i:i+len(Y)] == Y" (as Serhiy said), 
then there is no such (highest) index.

I understand what _you_'re saying, but please understand that the docs do not 
say anything like that.

--

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



[issue42210] float.hex discards sign from -nan

2020-10-31 Thread Vedran Čačić

Vedran Čačić  added the comment:

inf and -inf are really two different values (in the scope of the standard). 
Same as 5. and -5., or even 0. and -0. They behave differently in some exactly 
specified operations, and it is useful.

Are there any exactly specified operations whose specifications require the 
unequal treatment of nans with + and - signs? I don't think so, since it goes 
against the whole idea of nan as an unspecified number. (If you want to track 
its _history_, that's what payload is for.) My interpretation is that nan can 
have a sign bit only so unary minus and absolute value can be implemented 
quicker (without having to check whether the input is nan) -- not because it 
carries any useful semantics within the standard.

--
nosy: +veky

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



[issue26789] logging: Trying to log during Python finalization with NameError: name 'open' is not defined

2020-10-30 Thread Vedran Čačić

Vedran Čačić  added the comment:

> In the OP, the error is caused by `open` being unavailable, which is a 
> builtin. According to what Serhiy says, this error would be after step 6

I think you read the post above incorrectly. The phase 3 is the one where open 
is removed, since it's not a "native" builtin, but imported from io.

--
nosy: +veky

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



[issue42060] Usage of assert in http/client.py

2020-10-18 Thread Vedran Čačić

Vedran Čačić  added the comment:

If I understand correctly, those are _private methods_ (names start with 
underscore). In such cases, asserts can be completely fine, since the library 
writer controls the situations where the method is called. If it is never 
called with _UNKNOWN argument, assert is just that, assertion that it is so. 
(It would be different if it were a public method, since the library writer 
doesn't know it will never be called with _UNKNOWN.)

--
nosy: +veky

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



[issue38250] enum.Flag should be more set-like

2020-10-14 Thread Vedran Čačić

Vedran Čačić  added the comment:

Flag values are _not_ a set of enabled bits.

At least, it is a weird kind of set where a is the same as {a}. That's why I 
mentioned mereology... there is no reasonable "membership", just "inclusion". I 
understand that str is not a perfect analogy, but sets are even more wrong.

--

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



[issue38250] enum.Flag should be more set-like

2020-10-13 Thread Vedran Čačić

Vedran Čačić  added the comment:

Again, I disagree. `str` used to work like this in Py2.0 (or somewhere around 
then), only 'x' was in 'xyz', not 'xy'. Then Guido came to his senses. :-)

This is not set theory, this is mereology. You don't differentiate between a 
digit and a one-digit number, a char and a one-char string, and in the same way 
you shouldn't differentiate between a bit and a one-bit flag.

--

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



[issue38250] enum.Flag should be more set-like

2020-10-11 Thread Vedran Čačić

Vedran Čačić  added the comment:

Of course, if it returns True only on _some_ bits combinations it doesn't make 
sense. I thought every element of a Boolean span would be _in_ the Foo.

But about "zero bit", I still think it's perfectly analogous to '' in 'abc'.

--

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



[issue38250] enum.Flag should be more set-like

2020-10-11 Thread Vedran Čačić

Vedran Čačić  added the comment:

Just a comment, (1) is analogous to str. iter('abc') gives only 'a', 'b' and 
'c', while contains accepts '', 'ab', 'bc', and 'abc' too. At least in my mind, 
it's a pretty strong analogy.

--

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



[issue41877] Check against misspellings of assert etc. in mock

2020-10-08 Thread Vedran Čačić

Vedran Čačić  added the comment:

Of course, that's why I wrote "my" in quotes above. It's not my solution, it's 
the idea that many people independently had. Because it is _the_ solution, of 
course. :-]

I'd just like to point out in the above thread (first link you provided), how 
_many_ people operate under the assumption that "misspelling problems are now 
solved". I'm sure many of their opinions would be different if they knew we'd 
be having this discussion now.

Let's not make the same mistake again. I assure you that in few more years 
we'll find some other creative ways to misspell arrest_* methods. ;-)

--

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



[issue41877] Check against misspellings of assert etc. in mock

2020-10-08 Thread Vedran Čačić

Vedran Čačić  added the comment:

Sorry, but 

1) Stability policy is great when we hold on to it. If we add new spellings of 
assert every few years, what kind of stability it is? "My" solution is of the 
same type: just add one more thing to the API. But that solution is better, 
because a) it doesn't clash, and b) it must be done only once.

2) Soundex has nothing to do with it. It was invented to mitigate errors when 
transferring _sounds_ (phonemes) over the telephone wire. It would surprise me 
very much if those were in any useful sense correlated with errors encountered 
typing graphemes on the mechanical keyboard.

--

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



[issue40066] Enum._convert should change __repr__ and/or __str__ to use module name instead of class name

2020-10-08 Thread Vedran Čačić

Vedran Čačić  added the comment:

> - do you think the change has merit?

Absolutely.

> - why /shouldn't/ we make the change?

Well, standard backward compatibility stuff. :-)

--

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



[issue41877] Check against misspellings of assert etc. in mock

2020-09-28 Thread Vedran Čačić

Vedran Čačić  added the comment:

It would be a valid argument if the API _worked_. Obviously, it doesn't. Every 
few years, the same story repeats. "We've found even more missspellings of 
assert, we need to add them too. They cause real bugs in our tests." I have a 
strong feeling it will never end.

--

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



[issue41877] Check against misspellings of assert etc. in mock

2020-09-28 Thread Vedran Čačić

Vedran Čačić  added the comment:

How about we actually _solve_ the problem, instead of masking it with layer 
upon layer of obfuscation?

Python has standalone functions. assert_called (and company) should just be 
functions, they shouldn't be methods, and the problem is solved elegantly. The 
whole reason the problem exists in the first place is that Java, where Python 
copied the API from, has no standalone functions. In Pythonic design, the 
problem shouldn't exist at all.

--
nosy: +veky

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



[issue35765] Document references object x but doesn't show it in the example

2020-09-26 Thread Vedran Čačić

Vedran Čačić  added the comment:

I think it would be simpler to just remove the empty name `x`.

"If you have an object, you can ...".

--
nosy: +veky

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



[issue40066] Enum._convert should change __repr__ and/or __str__ to use module name instead of class name

2020-09-14 Thread Vedran Čačić

Vedran Čačić  added the comment:

Noone said it is a requirement, I just said it would be nice to have it 
factored out as a decorator or something instead of having to write __repr__ 
over and over again.

--

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



[issue40066] Enum._convert should change __repr__ and/or __str__ to use module name instead of class name

2020-09-14 Thread Vedran Čačić

Vedran Čačić  added the comment:

If it's considered to be not too backwards-incompatible, I think it would be 
nice to have str different from repr. That way we can finetune what exactly we 
need. But we can already do almost exactly that with *int* instead of *str*, so 
it's not too compelling.

Much more important thing is the "repr as inverse of eval". Is there any way we 
can have that for our own enums (as a mixin or a decorator)?

@module_global(re)
class RegexFlag(Enum):
...

It would be fantastic. :-)

--

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



[issue41740] Improve error message for string concatenation via `sum`

2020-09-07 Thread Vedran Čačić

Vedran Čačić  added the comment:

The fact that you've forgotten about it is exactly why sum tries to educate you 
(despite Python being "the language of consenting adults" in most other 
aspects). The problem (why it doesn't do a good job in that aspect) is that 
people usually expect sum to act like a 2-arg form of functools.reduce, while 
in fact it acts like a 3-arg form, with 0 as the initializer.

I doubt that Python will change regarding that, but you can sharpen your 
intuition by asking yourself: what do you expect sum([]) to be? If 0, then 
you're inconsistent. :-)

--
nosy: +veky

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



[issue41598] Adding support for rounding modes to builtin round

2020-08-26 Thread Vedran Čačić

Vedran Čačić  added the comment:

Well, of course, but that's possible even now, and people still reach for 
`round`. I guess the problem is that it's too easily accessible. :-)

--

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



[issue41598] Adding support for rounding modes to builtin round

2020-08-26 Thread Vedran Čačić

Vedran Čačić  added the comment:

> Personally, I think I'd rather have easier ways to create Decimal objects

Wouldn't everybody? :-P But that's been proposed at least 4 times already and 
never got anywhere. My proposal is at least original, has a precedent at the 
above link (strings as surogate literals, preserving value across semantic 
boundaries), _and_ comes with a natural scope limitation guarantee: noone can 
argue for '2.1' + '3.5' to be '5.6' (because it is already '2.13.5';), it works 
only in the first argument of round.

Also, the string at that time is not so pointless: many people use round for 
printing, at that point you are going to convert to str anyway. And 
round(str(result), digits) gives a nice way to use python's builtin repr 
capability of "picking the shortest representation" for DWIMming: it's the best 
of both worlds, your implementation DWIMs, but you're not responsible for 
corner cases. ;-=

But no, I'm not going to Python-ideas, for the same reason I'm not going back 
to high school: too many bullies, too hard to get your voice heard, mostly 
because everyone assumes you wouldn't be there if you had anything smart to 
say. :-/

--

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



[issue41598] Adding support for rounding modes to builtin round

2020-08-25 Thread Vedran Čačić

Vedran Čačić  added the comment:

> I'd rather add whatever bells and whistles we need (if any) to make it easier 
> for users who care about this to use Decimal.

This made me think. (I have tons of these ideas, but usually am afraid of 
voicing them unless encouraged by comments such as this one.;) How about this 
whistle: we allow round to accept str as the first argument?

In a very unrelated context 
(https://www.python.org/dev/peps/pep-0484/#forward-references) Guido has said 
something like "when literals aren't what they seem, strings are a good enough 
substitute". Maybe here too?

--

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



[issue41598] rnd() + rndup() in math

2020-08-22 Thread Vedran Čačić

Vedran Čačić  added the comment:

> use more digits to manage rounding in decimal base, not only one but more (i 
> should think better and experiment on how many)

You don't have to. It's infinitely many. :-P Think, how many decimal digits 
would you need to accurately round numbers to a closest third (one trinary 
digit)? Here are some decimal digits: 2.1. If the next digit is 5, then 
it rounds to 2.0. If it is 7, it rounds to 2.1 (base 3). If it is 6, you still 
don't know anything. It can go arbitrarily far. Of course, the probability is 
lower with every digit, and at some point it becomes acceptable (you said for 
yourself it's acceptable even with one extra digit), but it's not 
mathematically correct.

And that one bit was just an illustration. In real life, 64-bit machines 
usually use at least 80-bit precision, so 16 extra bits. But it doesn't help 
your case, for the above reasons: this is simply not decimal rounding.

--

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



[issue41598] rnd() + rndup() in math

2020-08-22 Thread Vedran Čačić

Vedran Čačić  added the comment:

I think you don't know what paraphrasing means. Or maybe I don't know it, but 
in any case, I'm well aware what Von Neumann said, and how it is usually 
misunderstood in today's society. "Living in the state of sin" is simply an 
emotionally powerful metaphor, and it pertains to the philosophical 
impossibility of something, whether or not there are strong reasons to "do it 
anyway" and even good methods of faking/approximating it. Same as "detecting 
infinite loops programmatically", "passing objects by value", or "having side 
effects in a referentially transparent language". :-)

I agree that Python is a language where practicality beats purity, and as I 
said, there is a sensible interface for the implementation about which we agree 
(except for a detail: I'd actually _force_ people to import the rounding modes 
from decimal module, to at least hint to them what exactly they are doing and 
what the preferred approach is). But I still think that arguments for that are 
very weak.

First, yes, there is a very small probability of calculations _randomly_ ending 
with abc.de5...0 (in the Platonic sense) [so it actually manifests as a 
problem], but there is much greater probability (though still small) that 
calculations _theoretically_ ending with abc.de5 actually end with 
abc.de4...7 [and thus are rounded down anyway, despite your insistence on 
modes]. People _will_ think "hey, I did the right thing by specifying the 
mode--why does it still acts funny?"

"there are reasonable use-cases for different rounding modes even when using 
floats.": absolutely. But they are _binary_ rounding modes! I think you should 
read the standard. It is actually two standards, one for binary and one for 
decimal arithmetic. (The second one is implemented fairly faithfully in the 
decimal module; the first one is, through libc, the one that Python floats are 
based upon).

The [binary] standard says, more or less, that the result should be as if the 
value was calculated with the infinite number or extra [binary] digits (of 
course, in practice it should just be some extra precision, but again, of 
_binary_ digits), and then, when fitting that value into a smaller [binary] 
register with smaller available number of [binary] digis, all extra [binary] 
digits are discarded (not stored) and some ending [binary] digits retained are 
modified according to the value of some of the discarded [binary] digits and 
the rounding mode. For example:

"""
The 24-bit significand will stop at position 23, shown as the underlined bit 0 
above. The next bit, at position 24, is called the round bit or rounding bit. 
It is used to round the 33-bit approximation to the nearest 24-bit number 
(there are specific rules for halfway values, which is not the case here). This 
bit, which is 1 in this example, is added to the integer formed by the leftmost 
24 bits.
"""

You see it speaks about _bits_, not decimal digits. In the same way, _decimal_ 
rounding would take a value calculated with some extra precision of _decimal_ 
digits, and when storing them with the smaller number of _decimal_ digits, 
discard extra... blah blah as above. But you cannot round binary numbers to 
decimal digits. It's as if you tried to round 0.45 to one trinary digit after 
the integer point. The answer is 0.1 in base 3, but it isn't expressible in 
decimals. And it doesn't work:

>>> Decimal('0.45').quantize(Decimal(1/3))
decimal.InvalidOperation: []

because the authors of quantize have thought about that. The documentation says 
"""Unlike other operations, if the length of the coefficient after the quantize 
operation would be greater than precision, then an InvalidOperation is 
signaled.""" In effect, rounding cannot increase the number of significant 
digits. And it would do that if you're rounding to an incompatible base, 
whether 2 to 10 or 10 to 3.

--

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



[issue41607] pdb - Clickable path to breakpoints

2020-08-21 Thread Vedran Čačić

Vedran Čačić  added the comment:

IDLE has Go to File/Line menu too. I think it would also help there. (Terry, 
can you confirm?) Not to mention that it would be one thing less to explain to 
beginners when using pdb.

--
nosy: +veky

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



[issue41598] rnd() + rndup() in math

2020-08-21 Thread Vedran Čačić

Vedran Čačić  added the comment:

Yes, and these functions are completely fine for your personal library, if you 
need such things. But they really have no place in math module, since (1) they 
aren't always correct, (2) it's incredibly difficult to characterize exactly 
when they are, and (3) even when they are correct, they just give people wrong 
impression about floats somehow being decimal numbers.

If you need to use floats, reconcile yourself with the idea that they don't 
represent all decimal numbers, not even the ones with just one decimal place, 
and any algorithm dealing with decimal digits will be just an approximation.

If you want the best approximation the humanity can muster, backed with 
empirical data and theoretical considerations, use the round() builtin. 

If you want to just have something that works according to your preconceived 
notions in some cases, while failing mysteriously in others, use your 
quick-and-dirty implementations.

If you want exact decimal results, use the decimal module, and specify the 
rounding mode as you wish.

--

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



[issue41598] rnd() + rndup() in math

2020-08-20 Thread Vedran Čačić

Vedran Čačić  added the comment:

Yes, we can do better than ms (whatever that means). And we do exactly that in 
the `decimal` module. Floats are not the right target for your algorithms, 
because they don't have decimal digits. It's as if you're trying to round words 
in English language. :-D (In fact, with words you'd probably have better luck, 
since they _can_ represent decimal numbers exactly.)

--

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



[issue41591] Comprehensions documentation

2020-08-20 Thread Vedran Čačić

Vedran Čačić  added the comment:

On the contrary, I think it would be much more clearer if it focused on the one 
that was evaluated in the context. So, _inner_ listcomp is... (instead of 
"nested listcomp is..."). "Main part of outer" is just beating around the bush. 
But in fact I'm not motivated enough (nor powerful enough) to actually change 
this on my own.

--

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



[issue41598] rnd() + rndup() in math

2020-08-20 Thread Vedran Čačić

Vedran Čačić  added the comment:

ROUND_HALF_UP is not chosen because it's popular, but because it's the best way 
to compensate for errors in representing decimal numbers by binary numbers.

Thinking that floats are decimal numbers is going to bite you anyway sooner or 
later. For example, would you expect (with your implementation) rnd(2.8-1.3) == 
rnd(1.8-1.3) ?

--

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



[issue41591] Comprehensions documentation

2020-08-20 Thread Vedran Čačić

Vedran Čačić  added the comment:

It refers to the sentence

"""The result will be a new list resulting from evaluating the expression in 
the context of the for and if clauses which follow it. """

The expression at the start of listcomp is the one that's evaluated in the 
context of clauses following it, no matter what kind of expression it is. If it 
is another listcomp, then you have a nested listcomp, but that's just a 
nonspecial case.

--

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



[issue41591] Comprehensions documentation

2020-08-20 Thread Vedran Čačić

Vedran Čačić  added the comment:

This is not nested listcomp. Nested listcomp is a listcomp inside a listcomp. 
What you wrote is one listcomp, with two for-clauses. It does "desugar" into a 
nested loop, but that doesn't make it a nested listcomp.

--
nosy: +veky

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



[issue41598] rnd() + rndup() in math

2020-08-20 Thread Vedran Čačić

Vedran Čačić  added the comment:

If we want to proceed with this, much better way would be to add a rounding 
mode optional argument to `round` builtin.

But really, anyone trying to precisely round a decimal representation of a 
binary floating point number is, to paraphrase von Neumann, living in the state 
of sin. See https://stackoverflow.com/a/51146310/1875565.

--
nosy: +veky

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



[issue41590] "zip()" very slowly for this

2020-08-19 Thread Vedran Čačić

Vedran Čačić  added the comment:

Third, where did you get the idea that transposing a "matrix" consisting of 
lists of varying length is a sensible operation? Your reference (Wikipedia) 
tells nothing about that case. I've never seen [[],[1]] called "a matrix".

--

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



[issue41590] "zip()" very slowly for this

2020-08-19 Thread Vedran Čačić

Vedran Čačić  added the comment:

First, what you wrote with if...else is _not_ "if clause". It's a conditional 
expression. You'll recognize them easily if you remember that "if clause" in 
comprehensions never has an "else", while conditional expression always does.

Second, speed is just one of many, many criteria by which we evaluate programs. 
If only speed matters to you, you probably shouldn't be writing in Python at 
all. There are much faster languages.

--
nosy: +veky

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



[issue41584] Clarify documentation for binary arithmetic operation subclass __r*__ precedence

2020-08-19 Thread Vedran Čačić

Vedran Čačić  added the comment:

Sorry, of course I meant C()-A(). The point is that the class A _doesn't_ have 
to implement __rsub__.

--

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



[issue41584] Clarify documentation for binary arithmetic operation subclass __r*__ precedence

2020-08-19 Thread Vedran Čačić

Vedran Čačić  added the comment:

Yes, there is a corner case here. If A derives from B and B derives from C, A 
doesn't implement __rsub__ and B does, A()-C() will call B's __rsub__.

--
nosy: +veky

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



[issue41546] pprint() gives exception when ran from pythonw

2020-08-17 Thread Vedran Čačić

Vedran Čačić  added the comment:

The big part of the justification for making print a function in Py3 is that it 
can be painlessly replaced with other functions, such as (example given by 
BDFL) pprint.pprint. I think we should do what we can to make the replacement 
as painless as possible.

--
nosy: +veky

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



[issue41552] uuid.uuid1() on certain Macs does not generate unique IDs

2020-08-15 Thread Vedran Čačić

Vedran Čačić  added the comment:

Yes, you're right. Xoring can be replaced by any key-derivation function, 
though of course that's probably overkill.

--

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



[issue41552] uuid.uuid1() on certain Macs does not generate unique IDs

2020-08-14 Thread Vedran Čačić

Vedran Čačić  added the comment:

+1 on xoring all MAC addresses to get NodeID. Since it is only done once at 
import time, it shouldn't be too expensive (many other things including OS 
calls are done at initialization). But yes, if the problem goes away with new 
version of _uuid, then the fix isn't needed.

--

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



[issue41552] uuid.uuid1() on certain Macs does not generate unique IDs

2020-08-14 Thread Vedran Čačić

Vedran Čačić  added the comment:

I'd like to point out that _even_ if you do reuse MAC address:

1. node IDs don't have to be derived from MAC addresses only (though in 
practice they usually are - I'm just saying the RFC gives you permission to 
include other information in it).

2. The time resolution is 100ns. As long as your UUID generations are more than 
0.2μs apart, you're safe from collisions.

3. There is still a clock sequence, which for these purposes can be viewed as 
random. Even if you _do_ generate UUIDs on different machines with same MAC and 
naive nodeID-deriving algorithm, two or more of them within the same 
100ns-interval, there is still only a probability of 1/16384 (62ppm) of 
collision.

In short, it's probably not a problem, though if there is an easy fix, of 
course it should be applied. Currently, there are two ways to indicate "this is 
not a real unique MAC address" that UUID recognizes: 

# Virtual interfaces, such as those provided by
# VPNs, do not have a colon-delimited MAC address
# as expected, but a 16-byte HWAddr separated by
# dashes. These should be ignored in favor of a
# real MAC address

and the 41st bit test /More details at #32107/. Maybe there is a third way, but 
if the above address doesn't play by these rules, maybe hardcoding it isn't so 
bad an idea.

--
nosy: +veky

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



[issue41528] Use math module in turtle

2020-08-12 Thread Vedran Čačić

Vedran Čačić  added the comment:

Well, if you want to exploit Python features in full, I'd suggest cmath as even 
better library. Turtle position is just a complex numbers, and cmath has direct 
conversion from and to polar coordinates, which is all that's needed for basic 
commands. :-)

--
nosy: +veky

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



[issue41458] Avoid overflow/underflow in math.prod()

2020-08-06 Thread Vedran Čačić

Vedran Čačić  added the comment:

> s.append(x) if side == s_side else t.append(x)

To me, (s if side == s_side else t).append(x) seems much better. Not only more 
is factored, but .append is viewed as a procedure (returning None, changing its 
object), and if-expression is really used for its value, not the side-effect.

--

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



[issue41480] python won't save

2020-08-04 Thread Vedran Čačić

Vedran Čačić  added the comment:

Thanks for a very precise report. Have you tried to manually save your file 
(File > Save As)? Also, how did the file get that name (PPTests0.1.py)?

--

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



[issue41480] python won't save

2020-08-04 Thread Vedran Čačić

Vedran Čačić  added the comment:

What exactly do you type/click and where?

--
nosy: +veky

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



[issue41458] Avoid overflow/underflow in math.prod()

2020-08-03 Thread Vedran Čačić

Vedran Čačić  added the comment:

Yes, fprod would be nice [though if you just want to avoid over/underflows, 
much easier solution is to first determine the sign, then sum the logarithms of 
absolute values, and exponentiate that]. But I agree with Tim that it should be 
a separate function. For the same reason that sum is not fsum. (The reason prod 
is in math is bureaucratic, not ontologic.)

--
nosy: +veky

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



[issue41272] New clause in FOR and WHILE instead of ELSE

2020-07-18 Thread Vedran Čačić

Vedran Čačić  added the comment:

I completely agree that we should reject this, but you commit a very frequent 
mistake in programming try-expressions. The problem is, if the first option 
contains a NameError, second option will be executed.

It should be:

try: i001
except NameError: 
else: 

And similarly for break001. You see, dependent `else` is needed sometimes. But 
of course Guido already covered this. :-)

--
nosy: +veky

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



[issue26205] Better specify number of nested scopes

2020-07-05 Thread Vedran Čačić

Vedran Čačić  added the comment:

Well, then "what name is in which namespace" is relative to which function 
we're considering. In my example above, imagine aa has x declared, bb has y, 
and cc has z. Then y and z are in the same namespace when we look from the 
perspective of aa, but they are not in the same namespace from the perspective 
of bb. Even worse, cc sees z but doesn't see y. How can they be in the same 
namespace then?

I always thought about namespaces as mappings from names to objects, 
independent of perspective. Whether two names are in the same namespace, should 
be a question with an objective answer.

--

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



[issue26205] Inconsistency concerning nested scopes

2020-07-05 Thread Vedran Čačić

Vedran Čačić  added the comment:

How is that different from saying that "At any one time, the language and 
interpreter sees all the scopes as one scope for the purpose of accessing and 
rebinding."? Any ChainMap presents itself as a dictionary to the outside. That 
doesn't mean it doesn't have an internal structure.

Yes, nonlocal picks the innermost one because of its semantics, but it still 
needs to search through the scopes in order to know which one to pick, right?

--

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



[issue26205] Inconsistency concerning nested scopes

2020-07-05 Thread Vedran Čačić

Vedran Čačić  added the comment:

Just to point out: it can be more than four, right? If you have a function aa 
within a function bb within a function cc, then bb's and cc's scope are 
different, even though functionally equivalent from the perspective of aa.

--
nosy: +veky

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



[issue29882] Add an efficient popcount method for integers

2020-06-28 Thread Vedran Čačić

Vedran Čačić  added the comment:

Well, bit_sum is what it really is. But I agree it's a terrible name. :-)

--
nosy: +veky

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



[issue41087] Argparse int / float default

2020-06-25 Thread Vedran Čačić

Vedran Čačić  added the comment:

Python _is_ strongly typed. As soon as you try to use that 0.005 as an index 
into a list or something else that requires an int, you'll get a TypeError. 
Strong typing is not the same as static typing. It is a common misconception.

And common sense is always common to something. For humans it is common sense 
that we have two eyes, but it's not common to spiders. As I said, what is 
common sense in statically typed languages is not necessarily common to Python.

--

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



[issue41087] Argparse int / float default

2020-06-23 Thread Vedran Čačić

Vedran Čačić  added the comment:

Yes, it is common sense in statically typed languages. Python is not statically 
typed. Many other things are also "common sense" in various paradigms, which 
doesn't mean they should also be in Python.

--
nosy: +veky

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



[issue40755] Add missing multiset predicates to collections.Counter

2020-05-30 Thread Vedran Čačić

Vedran Čačić  added the comment:

I'm very glad for that. :-)

For the other part of my message, I never intended to remove the support for 
non-natural counts. I just wanted to add some more methods to the natural part 
of Counter's API. It already has some methods which assume natural counts: 
.elements(), for example.

--

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



[issue40755] Add missing multiset predicates to collections.Counter

2020-05-25 Thread Vedran Čačić

Vedran Čačić  added the comment:

isequal is really strange considering we're talking about Python here. Do any 
of other stdlib types have that method instead of just using == (which works 
fine even now)? I'd even spell the second and third as <= and >=, same as set 
does.

But if we're finally going to accept that Counters are just bags (CS term for 
multisets), then surely .add and .remove (and maybe .discard, setting the count 
to 0) would be more natural additions. I can't count (pun intended) all the 
times I had to write that '] += 1' just to count some element.

--
nosy: +veky

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



[issue40605] «python»: Aucun fichier ou dossier de ce type

2020-05-12 Thread Vedran Čačić

Vedran Čačić  added the comment:

You surely can, but I don't know much about OS X. You can probably set some 
kind of alias (https://www.peachpit.com/articles/article.aspx?p=31442=5).

--

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



[issue40605] «python»: Aucun fichier ou dossier de ce type

2020-05-12 Thread Vedran Čačić

Vedran Čačić  added the comment:

Of course the _env_ is in /usr/bin. It's _python_ that's not found.

What program are you trying to run? And does it maybe start with

 #!/usr/bin/env python

? If yes, you should change it to python3.

--

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



[issue40605] «python»: Aucun fichier ou dossier de ce type

2020-05-12 Thread Vedran Čačić

Vedran Čačić  added the comment:

What do you mean by 

> when I want to use a programm with Python

? Do you write something like

~$ python3 myscript.py

? If so, maybe it's myscript.py that's missing, not Python itself.

--

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



[issue40605] «python»: Aucun fichier ou dossier de ce type

2020-05-12 Thread Vedran Čačić

Vedran Čačić  added the comment:

How do you know which version of Python you have if you can't run it? :-)

--
nosy: +veky

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



[issue40257] Improve the use of __doc__ in pydoc

2020-05-10 Thread Vedran Čačić

Vedran Čačić  added the comment:

Of course, I thought that

2. inspect.getdoc() returns the object's own docstring.

means it returns the object's own docstring _if it has one_. If it doesn't, 
then it should still return the docstring of its class, of course!

I have no problem with the fact that help(1) gives the same help as help(int). 
Of course, same as with the above (subclasses), we might want to emphasize the 
fact that the help is for the class and not for the object itself, but just 
returning nothing is in no way an improvement.

Guido, load is probably from Pandas, df is a relatively standard abbreviation 
for "dataframe" (an instance of a class DataFrame, with many various methods), 
and obj?? in Jupyter opens the help for obj in a subwindow, enabling you to 
browse it and close when you're done with it.

--

___
Python tracker 
<https://bugs.python.org/issue40257>
___
___
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 Vedran Čačić

Vedran Čačić  added the comment:

Just another usecase: one of my students is writing an implementation of 
ordinal arithmetic in Python as a graduate thesis. FrozenCounters whose keys 
are FrozenCounters and whose values are natural numbers are _exactly_ 
isomorphic (via Cantor's normal form) to countable ordinals below epsilon_0 
(and if a Counter can have itself as a key, we can go above epsilon_0 too).

Examples: zero = f{}
  one = f{zero: 1}
  seven = f{zero: 7}
  omega = f{one: 1}
  w^7*3+5 = f{seven: 3, zero: 5}
  w^w^w = f{f{omega: 1}: 1}
  epsilon0 = f{epsilon0: 1}
  and so on

I realize this is not something everybody does, but just to show that the need 
exists. We started with https://github.com/tamuhey/python-frozen-counter, 
afterwards we rolled our own implementation. But if it were in the stdlib, it 
would have saved us a lot of work.

--
nosy: +veky

___
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



[issue40342] Programming FAQ about "How do I apply a method to a sequence of objects?" should include the option of an explicit for-loop

2020-04-22 Thread Vedran Čačić

Vedran Čačić  added the comment:

Mapping lambdas is always inferior to comprehensions, in fact the main reason 
comprehensions were introduced was that mapping lambdas was cumbersome. (It 
didn't work so well for filtering by lambdas, but that's another story.)

As I said, Py3K was beneficial since raw maps weren't eager anymore, but it 
also gave us a print_function, enabling the new antipattern

[print(obj) for obj in mylist]

which wasn't possible before.

It's too late for Python, but a lesson for some future programming language: 
procedures and functions are not the same. Function call is an expression 
having a value, procedure call is a statement having an effect. Both are 
useful, but conflating them is not.

--

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



[issue40342] Programming FAQ about "How do I apply a method to a sequence of objects?" should include the option of an explicit for-loop

2020-04-20 Thread Vedran Čačić

Vedran Čačić  added the comment:

I must say I agree with Dominik here. Too many times my students write list 
comprehensions when they mean a for loop. It's not just a "has result vs 
updates inplace" dichotomy: often it produces some output like a drawing or 
just a print() call [one of rare things that was better when print was a 
command is that it was impossible to do this:]. Yes, I know print call is not a 
method, but e.g. .plot() on DataFrame is. I'd sleep easier if I knew the 
Programming FAQ didn't encourage this style.

It would be enough to add a sentence of a sort
"If you don't care about the return value of the method, use a for loop.
for obj in mylist: obj.method()
"

--
nosy: +veky

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



[issue40286] Add getrandbytes() method to random.Random

2020-04-15 Thread Vedran Čačić

Vedran Čačić  added the comment:

I think that the "module owner";-P must decide whether the `random` module 
should follow the C-namespacing or not. Of course, I'm in the "not" camp, so I 
believe those two "rand..." functions (randrange is completely redundant with 
random.choice(range)) should be supplemented with random.int and random.float. 
And then random.bytes will be completely natural. And people might be gently 
nudged into the right direction when using Python module namespaces.

--

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



[issue40284] Add mapping methods to types.SimpleNamespace

2020-04-15 Thread Vedran Čačić

Vedran Čačić  added the comment:

I think there is a teaching moment here. I think it's important that no object 
in Python standard library conflates "item namespace" with "attr namespace". 
(Maybe that isn't true because of some specialized objects, but surely general 
ones such as SimpleNamespace shouldn't commit that mistake.)

On the other hand, we do have json in standard library, and JSON is primarily 
based on JavaScript Object Notation (yes, I know it's been extended to fit more 
languages, but still, its primal DNA shows). And the conflating of attributes 
and items is so natural in JS (a['b']===a.b) that it took them more than a 
decate to realize that separating Map from Object might be a good idea. :-)

So, maybe we should also have something like JSNamespace in stdlib (presumably 
in json module). But SimpleNamespace shouldn't be it. As Guido once said, a 
bucket has a handle, and it contains sand, but it doesn't contain a handle.

--
nosy: +veky

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



[issue40286] Add getrandbytes() method to random.Random

2020-04-15 Thread Vedran Čačić

Vedran Čačić  added the comment:

> I suggest just random.bytes(n), the same as numpy.

The problem with this is that people who `from random import *` (some schools 
insist on this, probably because most functions they need already start with 
`rand`) will shadow builtin `bytes`. Not that those schools do anything with 
`bytes`, but still, it might be inconvenient.

(The metaproblem is of course that some functions already do the "poor man's 
namespacing" in C-style by starting with `rand`, and some don't. I'm always for 
user control of namespacing, but I'm just saying that it doesn't correspond to 
how many beginners use `random` module.)

--
nosy: +veky

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



[issue40257] Improve the use of __doc__ in pydoc

2020-04-14 Thread Vedran Čačić

Vedran Čačić  added the comment:

Then I'm fine with it. Thanks.

--

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



[issue40257] Improve the use of __doc__ in pydoc

2020-04-14 Thread Vedran Čačić

Vedran Čačić  added the comment:

Ok, I get what you're saying. But if someone writes

class B(A):
  # no docstring at all
  ...

help(B)

they'll still get other elements of current help? Particularly, "Methods 
inherited from A" (with their docstrings)?

--

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



[issue40257] Improve the use of __doc__ in pydoc

2020-04-11 Thread Vedran Čačić

Vedran Čačić  added the comment:

I don't agree with 1. I use that feature a lot, I write a base class which my 
students must subclass to their liking, but they still expect that 
help(TheirClass) will give them the documentation they need.

I agree that in _some_ cases it is not helpful (but even when the base is 
abstract, it might be helpful). How about: we keep the current behavior, but 
make it clear that the docstring applies to a superclass? It might be subtle, 
as just changing the first line of help() output (currently it says "Help on 
class Derived in module ...", change it to "Help on class Base in module ..."), 
or write a longer message such as "Documentation for Derived not found, showing 
the documentation for Base". But just removing it in all cases is really a 
wrong thing to do.

--
nosy: +veky

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



[issue40066] Enum._convert should change __repr__ and/or __str__ to use module name instead of class name

2020-04-10 Thread Vedran Čačić

Vedran Čačić  added the comment:

> _in some cases when enum instances are exposed as module globals_

Yes. And repr should be inverse of eval, but it's probably too late for that. 
:-/

--
nosy: +veky

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



[issue40250] unable to comment out r'\u' string with triple quote marks

2020-04-10 Thread Vedran Čačić

Vedran Čačić  added the comment:

This "bug" is reported at least once a year, by different people. Maybe we 
should put something in the documentation, to the effect that

a) as Eric said, triple-quoted strings are not (meant to be used as) comments

b) if you nonetheless really want to use them that way, in most cases you _can_ 
get away with using r'''...'''.

--
nosy: +veky

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



[issue40202] Misleading grammatically of ValueError Message?

2020-04-09 Thread Vedran Čačić

Vedran Čačić  added the comment:

> It says **too many** but I assign a few than the size of the list. am I the 
> one who wrong here?

Yes. The same as here:

> Should said something else because it received less values and expected 
> should say 3 and not 2, correct?

You probably don't understand _values_. a,b and x,y on the left side are not 
values. They are names. The 1,2,3 on the right side are values. Those are 
counted.

--
nosy: +veky

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



[issue40153] json dump with repeated key

2020-04-07 Thread Vedran Čačić

Vedran Čačić  added the comment:

JSON is JavaScript Object Notation, that is, a notation for JS Objects. Python 
dicts are much more general than that (not only in keys, but in values too: 
JSON keys must be strings, and values must be Strings, Numbers, Booleans, 
Arrays, (JS) Objects, or nulls -- both are restricted compared to Python 
dicts). There is really no reason to expect full embedding.

--
nosy: +veky

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



[issue40098] dir() does not return the list of valid attributes for the object

2020-03-31 Thread Vedran Čačić

Vedran Čačić  added the comment:

Guido:

First, wow!

Second, now it's even more glaring that list[str] has repr 'list[str]', while 
list doesn't have a repr 'list'. :-( Is it possible that the time for _that_ 
change will also come some day? :-)

Third, my problem with dir is not dunders, but dunders that really shouldn't be 
there. For example, __le__ when type doesn't support ordering. I understand how 
that happens, but it doesn't mean it isn't a bug.

--

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



[issue40098] dir() does not return the list of valid attributes for the object

2020-03-31 Thread Vedran Čačić

Vedran Čačić  added the comment:

Guido wrote:

>>> t = list[int]

A few years ago, I tried to explain to you that it's much more intuitive to use 
builtin types instead of their alter egos from typing (List etc.) for [] 
operator, you said it's not important. It's funny that you've implicitly 
acknowledged what I said through this typo. ;-)

--
nosy: +veky

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



[issue38250] enum.Flag should be more set-like

2020-03-25 Thread Vedran Čačić

Vedran Čačić  added the comment:

1. +0 _if_ the implementation is easy to explain. If backward compatibility is 
an issue, we can always add a property: 
for flag in flags.set:
(though set might imply unorderedness:)
2. -1. Guido said long ago that all lens should be O(1).
(Of course, if you do make it O(1), I have no objection.)
3. +1, absolutely.

--
nosy: +veky

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



[issue34822] Simplify AST for slices

2020-03-07 Thread Vedran Čačić

Vedran Čačić  added the comment:

Agree with the idea, but think the name is too narrow. How about 
`parethesized`? There are many contexts where parentheses look weird and can be 
omitted (e.g. after return statement), although subscripts are currently the 
only place where they are an outright error.

--

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



[issue39717] Fix exception causes in tarfile module

2020-02-24 Thread Vedran Čačić

Vedran Čačić  added the comment:

I guess https://bugs.python.org/issue39728 is a perfect example of "previous 
exception not adding any value". :-) And I think it isn't a coincidence that it 
happens in "your" module.

The morale: we think about exceptions in different ways, and it's hard to say 
what's the right way. Maybe we should just change the wording to imply that 
__context__ exception didn't spontaneously "occur", but was explicitly "raised" 
by a handler.

--

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



[issue39717] Fix exception causes in tarfile module

2020-02-23 Thread Vedran Čačić

Vedran Čačić  added the comment:

Oh yes, this has bugged me often. Please fix it somehow.

Yes, using "from None" is probably the wrong way to go. Often we need more info 
in tracebacks, not less. But the "During handling" message is very misleading. 
Same as Ethan, many times I interpreted it as "something went wrong in the 
handler" when in fact the handler was doing exactly what it was supposed to do.

except WhateverException as e:
raise CustomException from e

might be too much to write every time, and while I understand that we cannot 
simply redefine `raise` under `except` to do that implicitly, maybe there is 
some middle solution. On Python-ideas, recently I saw an idea

except WhateverException:
raise as CustomException

which I like a lot, but I don't know how hard it is to implement.

---

If everything above seems like too much, at least we should consider changing 
the wording of the message. If it said

+"In the handler of the above exception, another exception was raised:"
-"During handling of the above exception, another exception occurred:"

I'd be much happier. And it would more often suggest the right thing.

--
nosy: +veky

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



[issue39576] Surprising MemoryError in `decimal` with MAX_PREC

2020-02-21 Thread Vedran Čačić

Vedran Čačić  added the comment:

Well, it all depends on how do you intend to read it. To me, the closing quote 
and "So non-integer powers are left out" after it suggested that the 
non-integer powers being left out is somehow a consequence of the above 
paragraph. When in fact instead of "so" I think "except" or "alas":-) should 
have been.

--

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



[issue39576] Surprising MemoryError in `decimal` with MAX_PREC

2020-02-20 Thread Vedran Čačić

Vedran Čačić  added the comment:

Hm... is "exact result" a technical term that's defined somewhere? Because to 
me it seems that this

> "If there exists an exact result at a lower precision, this
result should also be returned at MAX_PREC (without MemoryError)".

is a mathematical statement, and surely for Decimal('0.07776') ** 
Decimal('0.2') _there exists_ an exact result at a lower precision. Maybe this 
should be reworded as "If there exists ... _and an implementation knows about 
it_, it should also be returned ..."

--

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



[issue34822] Simplify AST for slices

2020-02-18 Thread Vedran Čačić

Vedran Čačić  added the comment:

I wrote some AST analyzers, and this would have simplified my code. So I 
welcome it. :-)

However, it means people might be tempted to write 

a[b:c, d]asa[(b:c, d)]

(or at least expect it to work -- same as `a[b, c]` can now be written as 
`a[(b, c)]`). We aren't going to allow this?

--
nosy: +veky

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



[issue39090] Document various options for getting the absolute path from pathlib.Path objects

2020-02-15 Thread Vedran Čačić

Vedran Čačić  added the comment:

If we want something mnemonic, I'm sure nothing beats __abs__. (Hey, we have 
__truediv__ already!;)

--
nosy: +veky

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



[issue39601] brace escapes are not working in formatted string literal format specifications

2020-02-12 Thread Vedran Čačić

Vedran Čačić  added the comment:

I can't help with the issue itself (though I must say that I philosophically 
don't believe in "sailed off ships" -- in the limit, Python must be the best it 
can be, though it can take decades to get there), but I can help you with the 
error message. It simply tries to take {{x}} as your v (expression to be 
formatted). That is, a set containing a set containing x. But since sets 
themselves are not hashable (being mutable), they cannot be contained in sets 
(that's why frozensets were invented).

>>> {{4}}
Traceback (most recent call last):
  File "", line 1, in 
TypeError: unhashable type: 'set'

--
nosy: +veky

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



[issue39576] Surprising MemoryError in `decimal` with MAX_PREC

2020-02-07 Thread Vedran Čačić

Vedran Čačić  added the comment:

Yeah, I should have said "represent" instead of "write". :-)

--

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



[issue39576] Surprising MemoryError in `decimal` with MAX_PREC

2020-02-06 Thread Vedran Čačić

Vedran Čačić  added the comment:

> Of course the result is exactly 2.  Which I have enough RAM to hold ;-)

You might think so, but if you write it as 2.00...0 with 

>>> decimal.MAX_PREC
99

zeros, I think you're overestimating your RAM capacity. :-P

Now, what is the exact significance of MAX_PREC, I don't know. But I guess some 
hard limits were needed for standards compliance, and Python didn't want to 
limit you there. Of course, same as with recursionlimit, it might be better to 
actually have some reasonable _lower_ limit that we know is actually safe.

--
nosy: +veky

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



[issue39479] [RFE] Add math.lcm() function: Least Common Multiple

2020-02-01 Thread Vedran Čačić

Vedran Čačić  added the comment:

Tim: Considering that congruence is _defined_ as x=y(mod m) :<=> m|y-x, it's 
really not so surprising. :-)

Steven: It seems that we completely agree about inclusion of 
is_probabilistic_prime in stdlib. And we agree that it should be called isprime 
(or is_prime if Raymond names it;). About the bikeshedding, see Tim's comment. 
:-P

About absolutely correct algorithms: first, what exactly is your claim? If it's 
"I can write an algorithm in pure Python that can for every number of 397 
digits mathematically exactly determine whether it is prime in under 6 
seconds", I'd very much like to see that algorithm. (I guess it must be 
publicly available, since we're speaking about inclusion in Python stdlib.) I 
really don't have much expertise in number theory that I can be convinced it 
doesn't exist, but I very much doubt it.

--

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



[issue39496] Inelegant loops in Modules/_sqlite/cursor.c

2020-01-31 Thread Vedran Čačić

Vedran Čačić  added the comment:

It seems you haven't read carefully what I've written. This way some compilers 
might emit warnings. Please read 
https://stackoverflow.com/questions/5476759/compiler-warning-suggest-parentheses-around-assignment-used-as-truth-value

--

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



[issue39496] Inelegant loops in Modules/_sqlite/cursor.c

2020-01-31 Thread Vedran Čačić

Vedran Čačić  added the comment:

You mean, something like

while ((row = pysqlite_cursor_iternext(self))) {
PyList_Append(list, row);
Py_DECREF(row);
}

? It's interesting that now we have walrus in Python, we see the opportunities 
for it in other languages. (In C, it's spelled (=).:)

--
nosy: +veky

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



[issue39479] [RFE] Add math.lcm() function: Least Common Multiple

2020-01-31 Thread Vedran Čačić

Vedran Čačić  added the comment:

And yeah, I managed to leave out 2. Speaking about "often implemented wrong"... 
:-))

--

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



[issue39479] [RFE] Add math.lcm() function: Least Common Multiple

2020-01-31 Thread Vedran Čačić

Vedran Čačić  added the comment:

is_prime that's always correct is probably not the right thing to go into math. 
Besides, now we have isqrt, it's just

n>1 and n&1 and all(n%d for d in range(3,isqrt(n)+1,2))

-- yes, it's damn slow, but so is everything else you want to be absolutely 
correct. :-]

is_probable_prime is another matter, but there is an enormous amount of 
bikeshedding about the API of that one.

--

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



[issue39479] [RFE] Add math.lcm() function: Least Common Multiple

2020-01-28 Thread Vedran Čačić

Vedran Čačić  added the comment:

I agree with Raymond that it's really seldom needed. However, I'd like to point 
out that the "trivial" implementation might not be so trivial after all: as 
Steven said, it mishandles (0,0) case. And even Tim fell into that trap, so it 
can't be said it's easily avoided. I agree that this case doesn't really appear 
in "real world" tasks, but that's not really an excuse: imagine a factorial 
that didn't work for 0.

Also, a bit more often used case: seeing the code for lcm of 2 arguments, 
people might (and do; I've seen it) generalize to 3 or more arguments in a way 
that seems logical and is often correct, but not always (a*b*c//gcd(a,b,c)).

And one more tidbit: the usual formula for lcm doesn't really work for the case 
of fraction inputs. I know that currently math.gcd doesn't handle fractions, 
but it could. It's imaginable that that feature will some day be added (just 
like pow recently started supporting modular inverses), and then suddenly lcd 
implementations will silently give the wrong result for fractions.

A smart man;-) once said that the main criteria for inclusion in stdlib is that 
the function is often needed by users, _and_ it's often implemented wrong. I 
think lcm doesn't really satisfy the first criterion, but it does satisfy the 
second.

--

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



[issue39479] [RFE] Add math.lcm() function: Least Common Multiple

2020-01-28 Thread Vedran Čačić

Vedran Čačić  added the comment:

I must say that the problem (with two classes divided into teams) seems to me 
to be exactly one that can be solved with gcd, and lcm itself is mostly useless 
for it.

--
nosy: +veky

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



[issue39374] Key in sort -> Callable Object instead of function

2020-01-17 Thread Vedran Čačić

Vedran Čačić  added the comment:

I think that "HOW TO"s are fundamentally different from the "regular" 
documentation, in that they focus on explaining only the usual use cases and 
valuing simple explanations over the correct ones. Of course this _can_ be 
fixed, but I don't think that it must be done.

--
nosy: +veky

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



[issue38924] pathlib paths .normalize()

2019-11-28 Thread Vedran Čačić

Vedran Čačić  added the comment:

I think the real issue here

> mypath = PurePosixPath(normpath(mypath))

is the PurePosixPath wrapper. It is nice that normpath _accepts_ pathlike 
objects, but it should then not return a generic str. It should try to return 
an object of the same type.

Of course it's harder to do, especially in presence of pathlike objects of 
unknown classes, but with some reasonable assumptions on the constructors, it 
can be done---and it's much more useful. The similar debate, with similar 
conclusions, has already happened with datetime-like objects.

--
nosy: +veky

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



[issue38933] unusual behaviour on list of dependable lambdas

2019-11-28 Thread Vedran Čačić

Vedran Čačić  added the comment:

Yes, I never really understood what problem people have with it. If I manually 
say

i = 0
f = lambda a: a[i]
i = 1
g = lambda a: a[i]

why does anyone expect functions f and g to be different? They have the same 
argument, and do the same thing with it. The bytecode is completely the same. 
How can they do different things?

--

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



[issue38933] unusual behaviour on list of dependable lambdas

2019-11-27 Thread Vedran Čačić

Vedran Čačić  added the comment:

Why exactly is [2,3] expected? In the first example, the inner list has two 
functions that are _exactly the same_. Each of them takes a, grabs i from outer 
scope, and returns a[i]. (And of course, at the moment of evaluation of these 
functions, i is 1.) 

Do you really expect i to be "spliced" into the lambda as a value at the moment 
of constructing the function? Would you also expect

lambda x: x + input('y? ')

to ask you for input?

--
nosy: +veky

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



[issue38758] @dataclass defaults

2019-11-13 Thread Vedran Čačić

Vedran Čačić  added the comment:

It seems to me that what you're missing is that "class declarations" are still 
perfectly normal executable statements (in most other superficially similar 
programming languages, they are not). So, when you say

class A:
b = []

it is actually executed, a new empty list is made, and named A.b. If you then 
construct a = A(), then a.b is that same object. It must be, you never made any 
other list in the process. So if you really want a.b to be a _different_ empty 
list, you have to make it at some point. The most obvious way to do it is just 
to copy the A.b --- that's why people usually talk about copying.

Your approach is different: it seems to me that you say, if A.b is a list, then 
make a new empty list, if it is a set, then make a new empty set, and if it is 
a dict, then make a new empty dict. Not to mention that it feels very weird 
when having e.g.

class A:
b = [4]

(-:, it doesn't take into account any other types. Which leads to another your 
problem, the one of perspective. Lists, sets and dicts are not that "common 
case" as you seem to think. Yes, they are in the beginners' code -- and that's 
why current dataclass implementation flags them as errors, since it's quite 
possible that people who write such things don't actually understand how Python 
is executed. But specialcasing them to actually do something useful would be 
the wrong thing to do, since it would incentivize people who should know 
better, back into using those simple types. I think it is shown in the 
discussion mentioned.

--

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



[issue38758] @dataclass defaults

2019-11-13 Thread Vedran Čačić

Vedran Čačić  added the comment:

Have you read https://github.com/ericvsmith/dataclasses/issues/3?

--
nosy: +veky

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



[issue34716] MagicMock.__divmod__ should return a pair

2019-11-13 Thread Vedran Čačić

Vedran Čačić  added the comment:

Yes, this is impossible using only "universal Python" (independent of 
implementation). Though, of course, it's possible in CPython if you analyze the 
source code (or AST) and count the targets on the left side.

--
nosy: +veky

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



  1   2   3   >