News for hackers. Stuff that matters.
Re:We fixed f-string typos in popular Python repos by readthenotes1 on Friday April 29, 2022 @02:40PM (#31209082)
I find it ironic that the article points out that relying on error from humans to find errors is something of a hit or miss proposition and suggests that automating error finding is an appropriate course instead of making it less likely to make the error in the first place.

For example, I wonder how many errors would have been found if the definition of a format string was the default? That is, how many times would people have written something like "hello {previously-defined-variable}" and not meant to substitute the value of that previously defined variable at runtime?

Re:We fixed f-string typos in popular Python repos by MauranKilom on Friday April 29, 2022 @03:04PM (#31209359)
I don't think this makes sense. Plain strings and format strings are not interchangeable, and using one where the other was meant is probably a bug.

Would you expect that a user input like "{secret} please" is interpolated? If so, we hopefully agree that this would blow major security holes into any python script processing untrusted user input. And if not... Why not?

Re:We fixed f-string typos in popular Python repos by kgeist on Friday April 29, 2022 @03:39PM (#31209751)
>Would you expect that a user input like "{secret} please" is interpolated?

That's basically what the recent log4j security vulnerability was all about. "Helpfully" interpolating logs by default.

Re:We fixed f-string typos in popular Python repos by boxed on Friday April 29, 2022 @04:17PM (#31210134)
Look up how this works in Swift. They only have one string. No raw strings or f strings. Yet they have all the power of all three python string types and less syntax. It's very nice.
Re:We fixed f-string typos in popular Python repos by minitech on Friday April 29, 2022 @10:18PM (#31212780)
Swift does have raw strings (the #"extended delimiter"# syntax).
Re:We fixed f-string typos in popular Python repos by boxed on Thursday May 12, 2022 @01:55PM (#31357670)
No. Those ALSO have string interpolation!

#"\#(expression)"#

That is exactly the point.

Re:We fixed f-string typos in popular Python repos by minitech on Friday May 13, 2022 @10:45PM (#31374657)
But they’re a distinct string syntax. Your point seemed to be that there was only one. rf"{expression}" works in Python too, note, so either way you want to interpret it, raw strings aren’t a difference.
Re:We fixed f-string typos in popular Python repos by boxed on Saturday May 21, 2022 @02:20PM (#31460410)
No, they aren't. You can have any number of #. Including zero. It's ONE syntax.
Re:We fixed f-string typos in popular Python repos by asvitkine on Friday April 29, 2022 @03:18PM (#31209535)
If you only make it work with string literals (e.g. generate the underlying formatting logic at parse time), it wouldn't allow arbitrary inputs to be treated as f strings.
Re:We fixed f-string typos in popular Python repos by noobermin on Friday April 29, 2022 @03:16PM (#31209515)
The assumption I'm thinking they mean is to make formatting default and unformatted not default, for example, how "raw" strings were treated, escaped characters are replaced with the ascii code by default unless the string is raw, signified by an 'r' prefixed in front.
Re:We fixed f-string typos in popular Python repos by Sohcahtoa82 on Friday April 29, 2022 @03:42PM (#31209781)
Adding that behavior would break existing code that uses str.format, and Python tries to avoid breaking code between minor releases.
Re:We fixed f-string typos in popular Python repos by HL33tibCe7 on Friday April 29, 2022 @02:47PM (#31209165)
That’s not really a feasible solution in Python because that change would break a load of existing code.
Re:We fixed f-string typos in popular Python repos by mschuster91 on Friday April 29, 2022 @02:57PM (#31209280)
So what? Raise a deprecation notice, treat it as a fatal error in two or three years and that's it. PHP has been doing this for years now.
Re:We fixed f-string typos in popular Python repos by swatcoder on Friday April 29, 2022 @03:08PM (#31209419)
As someone who would like to be working on new, interesting things in 2-3 years rather than bringing old code into conformance with breaking changes, this attitude captures a worrisome trend in development.

On the one hand, it's great that we have platforms that innovate and improve and harden over time, but we're also facing a development culture where more and more time is spent servicing package/platform/language/OS changes that have no material impact on our own otherwise-mature projects.

It's worth being judicious about where breaking changes are applied, right?

Re:We fixed f-string typos in popular Python repos by mulmen on Friday April 29, 2022 @03:54PM (#31209902)
One person’s “new interesting thing” is another person’s “breaking change”.
Re:We fixed f-string typos in popular Python repos by HL33tibCe7 on Friday April 29, 2022 @03:06PM (#31209395)
We’re not talking about deprecating a feature here, we’re talking about the addition of behaviour that will break existing code, potentially in non-trivial and hard to debug ways, and in ways that could easily introduce security vulnerabilities.
Re:We fixed f-string typos in popular Python repos by capitalsigma on Friday April 29, 2022 @03:06PM (#31209405)
Just bump the major version number from 3 to 4, right? How long could that migration take?
Re:We fixed f-string typos in popular Python repos by noobermin on Friday April 29, 2022 @03:17PM (#31209530)
We've done this too many times and we've had enough pain, let's please proceed at a pace where we can worry about delivering our product and not updating formatted strings, thank you.
Re:We fixed f-string typos in popular Python repos by krisoft on Friday April 29, 2022 @03:13PM (#31209482)
> treat it as a fatal error

Did you think this through? What would you treat as a fatal error? How would the compiler know if a particular string is old style code wanting to print some characters between curly braces or new style code wanting to string interpolate a variable?

Re:We fixed f-string typos in popular Python repos by bornfreddy on Friday April 29, 2022 @03:05PM (#31209376)
Also see: Python 2 => 3 hell. Nobody wants to repeat that.
Re:We fixed f-string typos in popular Python repos by fphhotchips on Friday April 29, 2022 @10:58PM (#31212965)
Right?! Imagine: "We're announcing Python 4. Python 3 was because we handled unicode in a way that turned out to make nearly 0 sense. Python 4 is because you lot can't put your f's in the right place."
Re:We fixed f-string typos in popular Python repos by Too on Saturday April 30, 2022 @12:28AM (#31213342)
Changing something as deeply rooted as the string type?

Python already went through exactly that disaster once before, when they changed the default string type from b””-strings to u””-strings. It took about 20 years for this transition to finally complete.

Re:We fixed f-string typos in popular Python repos by rglullis on Friday April 29, 2022 @09:14PM (#31212457)
PHP has also been responsible for the majority of exploited servers and misconfigured applications. Whatever they are doing it, I take it as a strong negative signal.
Re:We fixed f-string typos in popular Python repos by SquareWheel on Friday April 29, 2022 @09:54PM (#31212665)
That's not unreasonable considering that PHP is by far the most popular server-side language. It's not like we have many hackers targeting Erlang instead.
Re:We fixed f-string typos in popular Python repos by rglullis on Friday April 29, 2022 @10:03PM (#31212713)
It's out of proportion. Take as many Django/Rails/ASP.Net exploited sites that you find and it won't hold a candle to PHP.

Also, want to talk Java? Let's not forget that log4j was exploited precisely because of implicit string conversions.

Implicit f-strings are a really bad idea.

Re:We fixed f-string typos in popular Python repos by dekhn on Friday April 29, 2022 @03:07PM (#31209412)
Python does not do this. A change like that would require a major version number increment and the community would revolt.

Too bad we can't go back in time to 1996 or so.

Re:We fixed f-string typos in popular Python repos by swatcoder on Friday April 29, 2022 @02:55PM (#31209253)
To be fair, your suggestion might make for a more resilient default, but it's also a great way to leak data and add overhead for the default case. There are tradeoffs.
Re:We fixed f-string typos in popular Python repos by Someone on Friday April 29, 2022 @03:49PM (#31209854)
Not much overhead, I would think. We’re talking about literal strings in source code, not strings in general. It’s not much work to check those.

One thing that it would break is that strings read from files would be treated differently from those in source code, even those read from files that logically “belong” to the application (say config file)

I don’t think that’s an issue, though.

Also, in Swift "\(foo)" does string interpolation. I haven’t seen people complain it leaks data or makes Swift slow (but then, it’s not fast at compiling at all because of its rather complicated type inference)

Re:We fixed f-string typos in popular Python repos by JadeNB on Friday April 29, 2022 @06:09PM (#31211152)
> Also, in Swift "\(foo)" does string interpolation. I haven’t seen people complain it leaks data or makes Swift slow (but then, it’s not fast at compiling at all because of its rather complicated type inference)

I think that the claim is not that this leaks data in an absolute sense, but rather that changing the behaviour after people have come to rely on it will leak data from currently well behaving applications.

Re:We fixed f-string typos in popular Python repos by macspoofing on Friday April 29, 2022 @02:51PM (#31209211)
>...and suggests that automating error finding is an appropriate course instead of making it less likely to make the error in the first place.

You can't fix the syntax and standard lib of the language. It is what it is. Similarly, how many bugs would you prevent if Python had compiler support to catch those types of syntax (and type) errors.

Re:We fixed f-string typos in popular Python repos by Too on Saturday April 30, 2022 @12:38AM (#31213385)
This is how bash works. Any string with a $ in it will be interpolated unless you double escape it. Also depending on if you use double or single quoted strings.

Spaces as list separator could also fall into this philosophical question of what makes most sense as string separators. Some times it is super convenient, until you have actual spaces in your string and it becomes a pita.

See also the yaml Norway problem for what happens when implicit goes over explicit.

It generates about the same amount of bugs, if not more, and would also end up with a code-review-doctor suggesting you to use /$ over $. In the end, regardless of syntax, a human always have to make the final call on whether interpolation is wanted or not.

Re:We fixed f-string typos in popular Python repos by boxed on Friday April 29, 2022 @04:16PM (#31210126)
This is how strings work in swift. It's a much superior system imo.
Re:We fixed f-string typos in popular Python repos by rikatee on Friday April 29, 2022 @04:33PM (#31210268)
what's also ironic is I left an easter egg in the code sample for how we downloaded the list of repositories and no one has noticed it yet.