exercism / v3

The work-in-progress project for developing v3 tracks
https://v3.exercism.io
Other
170 stars 163 forks source link

[Python] string formatting concept exercise #3034

Closed valentin-p closed 3 years ago

valentin-p commented 3 years ago

Closes #1647

ErikSchierboom commented 3 years ago

This Friday (Jan 29th 2021), we're going to explode this repo back into the individual track repositories and archive this repo.

As such, this PR needs to be merged by Friday 9am UTC, or it will need to be manually reopened against the track repo.

BethanyG commented 3 years ago

Hey Val, Taking a second quick look this morning, and I have some additional points:

  1. We really should warn people that they cannot use f-strings when they are wrapping text for translation. They have to use str.format(). See this SO post for some details. TL;DR: the way the f-string variables are evaluated short-circuits the process that looks up the string translation, so translating doesn't happen.

  2. Because our error messages for tests show up in the UI, but the test file does not -- we need to make sure that we have friendly error messages. Here is a snip from the basics excercise tests:

image

which will display in the UI as:

image

They'll also get the individual test case code, but the message is a little more friendly and helps with debugging.

  1. I think we should also mention that while f-strings can use any sort of expression inside the curly braces, it is best to keep those simple, and to never, ever use inputs that aren't sanitized. Using an expression inside those {} is like using eval() or exec()...so they aren't "safe", which is why there are still the template strings option and .format().
BethanyG commented 3 years ago

Apologies - one last thing: could you please add @J08K as a contributor? I know this was a re-write, but he put considerable work into the original to get started and we should acknowledge that work. Thanks!