Live data from Hacker News

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

codereviewdoctor.medium.com

171–180 of 339 posts

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

#171

Earlier quoted context omitted.

No, it doesn't: mylongstring = ("hello" + "world") or, without `+` mylongstring = ("hello" "world")

Use \ mylongstring = "hello " \ "world " \ "my " \ "name " \ "is"*

The use of \ is discouraged in Python. From PEP8:

> The preferred way of wrapping long lines is by using Python's implied line continuation inside parentheses, brackets and braces. Long lines can be broken over multiple lines by wrapping expressions in parentheses. These should be used in preference to using a backslash for line continuation.

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

#172
post #12

I am a bit in shock. Accidental string concatenation. Python just lost a lot of reputation in my brain.

I was going to comment something like "who would even use this?" and then I remembered that I have in fact used that feature :) It's a somewhat "nice" way to write long strings and keep the code from getting too wide. I never did it inside an array, but I found breaking up a long string into smaller ones and wrapping them in parens without a comma was convenient, for things like error messages. But that's just what c…

Heh. I use it all the time the way you do and didn't realize this is alien to many developers (no one in my team every complained about it).

It's common in some languages and used the way you use it. I looked in PEP8 and it seems they don't discuss this.

I think it's a perfectly valid use case, but clearly there are two camps to this. If this is so contentious, I would recommend PEP8 be revised to either explicitly endorse it as a way to split long lines or to explicitly discourage it and recommend the + operator instead.

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

#173

Earlier quoted context omitted.

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

Not entirely: let foo = a(); let foo = b(foo); let fop = c(foo); let foo = d(foo); (Which is valid, e.g., in Rust.)

You do get a warning, though. And most Rust projects I've seen usually adhere to 0 warnings.

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

#174
post #93

Earlier quoted context omitted.

Hmmm, it sounds like you're expecting "two" and "three" to be separate list elements because of some sort of implicit behavior due to being written in a list context. This is the opposite of what "Explicit is better than implicit" means. This is a list and you must explicitly place a comma when you want to start a new element in the list. Is there ever a time a new element follows a previous one and is NOT separated…

> it sounds like you're expecting "two" and "three" to be separate list elements I'd expect that to be an error.

Funny enough, in dynamic languages i expect it to do something unexpected and unwanted.

This is why i like Go/Rust. I detest the implicit warts of these languages.

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

#175
post #93

Earlier quoted context omitted.

Hmmm, it sounds like you're expecting "two" and "three" to be separate list elements because of some sort of implicit behavior due to being written in a list context. This is the opposite of what "Explicit is better than implicit" means. This is a list and you must explicitly place a comma when you want to start a new element in the list. Is there ever a time a new element follows a previous one and is NOT separated…

I'm not a python programmer, but the implicit string concatenation seems surprising to me.

I'm not a python programmer either, but I would be seriously annoyed at implicit anything instead of syntax error

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

#176
post #41

Earlier quoted context omitted.

This change would break a lot of legacy code for no good reason The most common way to split a string in lines is using this concatenation formula.

But wasn't this proposal part of the move to python 3? strings where broken left and right anyway.

Right, there was lots of deliberate breakage, _and_ this is purely syntaxual hence the sort of thing 2to3 could trivially deal with.

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

#177

Earlier quoted context omitted.

> Another one is having to import everything you use. The alternative is what exactly? Have the entire standard library exposed at once? Make all modules create non-conflicting names for exported objects, so that the json parse function has to be called json_parse and the csv parse function has to be called csv_parse? Seems less than ideal to me.

That's one way. If these things are classes in a plain old single-dispatch oop system, you can havec a json-parser and csv-parser which have parse methods. There could be packages/namespaces. So csv:parse and json:parse. These packages are standard and so they just exist; nothing to import. In Python, you cannot use anything without an import! The top-level modules (which serve as de facto namespaces) themselves are…

> This jaw-droppingly moronic.

It can be slightly inconvenient but doesn’t feel moronic to me. It means that except for the built-in functions, everything can be traced to either a definition or an import. Makes tracking code much easier.

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

#178
post #93

Earlier quoted context omitted.

Hmmm, it sounds like you're expecting "two" and "three" to be separate list elements because of some sort of implicit behavior due to being written in a list context. This is the opposite of what "Explicit is better than implicit" means. This is a list and you must explicitly place a comma when you want to start a new element in the list. Is there ever a time a new element follows a previous one and is NOT separated…

I'm not a python programmer, but the implicit string concatenation seems surprising to me.

It's idiomatic in C.

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

#179
post #99

Earlier quoted context omitted.

The lack of a static type-system is IMO what makes these one-character mistakes very annoying. The compiler can't tell you something is wrong, so you're just left to figure out why things are broken, just to realize it was the smallest of typos.

I love how simple and forgiving Python is for small projects. The "trailing comma creates a tuple" situation comes out of, as far as I can tell, a desire to create maximally convenient syntax in the scenarios where tuples are intended. I think that's great for small code! I just wish that the core team would take that same zeal for a "pythonic" experience with small code and use it to develop more scaled-up systems f…

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.

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

#180

Earlier quoted context omitted.

Did you figure out what the context is, and if you did, would you mind spelling it out for me? I still haven't figured out what correction to make to that sentence to get it to make sense.

in a blog post about the evils of typos there was a typo! classic https://en.wikipedia.org/wiki/Muphry%27s_law ;)

Also this classic:

> Apple I was the first product ever announced by the company in 1976. The computer was put on sale for $666.66 at the time.

https://9to5mac.com/2021/11/25/steve-woz-signs-rare-1976-app...

Post reply on HN