Live data from Hacker News

5% of 666 Python repos had comma typo bugs (inc V8, TensorFlow and PyTorch)

codereviewdoctor.medium.com

301–310 of 339 posts

Re: 5% of 666 Python repos had comma typo bugs (inc V8, TensorFlow and PyTorch)

#301

A lot of people are criticising dynamic typing for this. It doesn't seem to have anything to do with typing discipline. words = ( 'yes', 'correct', 'affirmative' 'agreed', ) Would be a tuple (immutable list) of strings, while words = ( 'yes', 'correct', 'affirmative', 'agreed', ) would also be a tuple of strings. If haskell had for some reason decided to have the same syntax sugar, it also would have caused an issue.

You got me for a second there.

Re: 5% of 666 Python repos had comma typo bugs (inc V8, TensorFlow and PyTorch)

#302
The first one, the implicit concatenation, I can see. But the rest of the things seem like most of the time they're intentional.

    {
        'key': (
            'long string long string long string'
        )
    }
Using parentheses like this to put long strings on their own line is standard practice.

    title = 'Hello world',
I, for one, have often used this deliberately.

Re: 5% of 666 Python repos had comma typo bugs (inc V8, TensorFlow and PyTorch)

#303
post #225

Earlier quoted context omitted.

I know that. I meant that “abc” + “def” is most likely illegal (although “abc” + ‘d’ is not).

You started talking about "adding strings" in a thread about adjacent literals, without mentioning any + operator.. String catenation ("adding") by adjacency (no visible operator) is a thing; "add" doesn't imply that we are talking about a + operator: $ awk 'BEGIN { x = "abc-" 2 + 2 "-def"; print x}' abc-4-def

Because the parent compared Python's behavior to that of C. The difference of course is that adding strings doesn't make sense in C, so there's no danger of misinterpreting "abc" "def" in C, as there is in Python.

Re: 5% of 666 Python repos had comma typo bugs (inc V8, TensorFlow and PyTorch)

#304
post #298
post #201

Earlier quoted context omitted.

> The most common way to split a string in lines is using this concatenation formula. Is it really? I tend to avoid it in favour of ””” or ‘\n’.join( ), because it looks like a mistake. Triple quotes are kind of annoying if the string is indented, but you can just not indent the string to avoid the whitespace.

Both of your solutions are great but don't fully cover the use case. They are useful for multiline strings, but implicit concatenation is also often used to break long strings that may not have newlines.

In y opinion that would be better served with ‘’.join( ‘hello’, ‘world’)

No footgun potential, and as others have mentioned the “good usage” would often be bad simply because it ends up looking like a mistake even if it’s intentional.

Re: 5% of 666 Python repos had comma typo bugs (inc V8, TensorFlow and PyTorch)

#305
post #198

Earlier quoted context omitted.

Presumably because parantheses don't really have anything to do with tuples, it's commas that do. Parantheses are there to help the parser group things in case of ambiguity, and to support expressions spanning multiple lines.

Since you typed it twice, I don't think it's a typo. It's parentheses not parantheses.

Thank you! I guess spelling from my native language is creeping over to English on occasion :)

Re: 5% of 666 Python repos had comma typo bugs (inc V8, TensorFlow and PyTorch)

#306
post #179

Earlier quoted context omitted.

If you use mypy (as anyone should for any non-hobby Python usage) then Python has one of the strongest type systems available. Optional types, generics, "Any" escape hatches, everything you could want.

Would mypy have caught any of the issues highlighted in the article?

No. Mypy only cares about types, it would only have been caught if something was expecting tuple of certain length, otherwise not.

The problem in the article is more related to syntax, not types, with the problem that both forms are valid syntax with different but still very similar outcome.

Pylint on the other hand can find it with implicit-str-concat check enabled.

Re: 5% of 666 Python repos had comma typo bugs (inc V8, TensorFlow and PyTorch)

#307

Earlier quoted context omitted.

https://github.com/tensorflow/tensorflow/tree/0d8705c82c64df... STOP! This folder contains the legacy Keras code which is stale and about to be deleted. The current Keras code lives in github/keras-team/keras. Please do not use the code from this folder. Yeah, not the most obvious notice. The fact they didn't find the same mistake(s) in keras-team/keras (I assume they scanned, it's one of the most popular Python repo…

once tensorflow pointed to keras-team this happened https://github.com/keras-team/keras/issues/15854 resulting in https://github.com/keras-team/keras/pull/15876

The automatic bug report generation tool produces the following:

"Absent comma results in unwatned string concatenation on line 330"

Bug-ception!

Re: 5% of 666 Python repos had comma typo bugs (inc V8, TensorFlow and PyTorch)

#308

Earlier quoted context omitted.

If a person decides to add parentheses to some booleans or arithmetic, (4 + 5) * (8 + 2) (this and that) or (theother) These elements should not become 1-tuples after the interior contents are evaluated. I sometimes add parentheses even around single variables just for visual clarity. Also, this allows you to do dot-access on int / float literals, if you want to # doesn't work 4.to_bytes(8, 'little') # works (4).to_b…

In principle, a 1-tuple shouldn't even be a thing - any single value is a 1-tuple by itself already. However, in a dynamically typed language, this approach complicates things elsewhere - e.g. if you have a value / 1-tuple that is a list, you'd expect iteration over it to give you list elements, not the single element that is a list. But if you have a value that is a tuple of unknown size, you don't want to special-c…

It depends what you mean by tuple. In Python, tuples are basically just immutable lists. Just as lists with 1 element are useful, so are tuples with 1 element. You might be dealing with a tuple of unknown length, where the length could be 1. In other contexts, the word "tuple" often carries the connotation of "having a known fixed length", in which case the notion of a 1-tuple as distinct from the value itself is less useful.

Re: 5% of 666 Python repos had comma typo bugs (inc V8, TensorFlow and PyTorch)

#309

I can see the value of a lint (if there's a newline without a comma, warn), but concatenating strings by multiplication is the correct thing to do (since it's also used this way in mathematics of parsers). Using the plus operator to concatenate strings is just weird. Think of the usual algebraic properties these operators are supposed to have. "+" always is supposed to be commutative--so "a"+"b" = "b"+"a", if those m…

Juxtaposition is not multiplication in this context - you can't write (2 3), for example, it has to be (2 * 3). Furthermore, Python already uses * for strings to indicate repetition: ("foo" * 2 == "foofoo"). String concatenation really just needs its own separate operator. & is an obvious candidate, if only it wasn't so commonly appropriated for bitwise AND - which is a very poor use of a single-char operator as it's…

& is also used for set intersection in Python. I think + for string concatenation isn't too bad, really. It fits in with the fact that length(s + t) = length(s) + length(t), the same way we write A × B for Cartesian product (since |A × B| = |A| × |B|, even though this operation is neither commutative nor associative) or B^A for a function space (since |B^A| = |B|^|A|).

Re: 5% of 666 Python repos had comma typo bugs (inc V8, TensorFlow and PyTorch)

#310

Earlier quoted context omitted.

Keywords like namespace , no; but functions and classes and modules provide for a lot of scoping opportunities.

The problem is `fop` should be `foo`: foo = 5 fop = 6 Keywords like `let` solve this problem: let foo = 5 fop = 6 # error

A good IDE has many other safety nets for that error.

Auto completion, highlight matching variable, gray out unread variables and warning of unused assignment.

I’ve written lots of python and can’t recall ever having this issue. More likely is a logic typo of two similar variables like length_x vs length_y, where a “let” wouldn’t have saved you anyway if both are already defined.

JavaScript, pre strict TS, on the other hand, where missing var implied global was a real motherload of bugs. Or kotlins “val” vs “var” changing semantics completely…wow. But those are different concepts from basic definition I know.

Post reply on HN