Skip to content

Commit fe8521a

Browse files
committed
Fix indentation & numbering
1 parent 8465f60 commit fe8521a

File tree

3 files changed

+25
-25
lines changed

3 files changed

+25
-25
lines changed

docs/python/debugging.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ To generate a `launch.json` file with Python configurations, do the following st
4848

4949
1. A configuration menu will open from the Command Palette allowing you to choose the type of debug configuration you want to use for our Python project file. If you want to debug a single Python script, select **Python File** in the **Select a debug configuration** menu that appears.
5050

51-
![List of Python debugger configuration options](images/shared/debug-configurations.png)
51+
![List of Python debugger configuration options](images/shared/debug-configurations.png)
5252

53-
> **Note**: Starting a debugging session through the Debug Panel, `kbstyle(F5)` or **Run > Start Debugging** when no configuration exists will also bring up the debug configuration menu, but will not create a launch.json file.
53+
> **Note**: Starting a debugging session through the Debug Panel, `kbstyle(F5)`, or **Run > Start Debugging** when no configuration exists will also bring up the debug configuration menu, but will not create a `launch.json` file.
5454
5555
1. The Python Debugger extension then creates and opens a `launch.json` file that contains a pre-defined configuration based on what you previously selected, in this case, **Python File**. You can modify configurations (to add arguments, for example), and also add custom configurations.
5656

docs/python/python-tutorial.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,9 @@ There are three other ways you can run Python code within VS Code:
158158

159159
2. Select one or more lines, then press `kbstyle(Shift+Enter)` or right-click and select **Run Python > Run Selection/Line in Python Terminal**. Alternatively, you can activate Smart Send using `kbstyle(Shift+Enter)` without a selection and the Python extension will send the smallest runnable block of code near where your cursor is placed to the terminal. This command is convenient for testing just a part of a file.
160160

161-
> **Note**: If you prefer to send code at the particular line your cursor is placed, you can turn off Smart Send by setting `python.REPL.enableREPLSmartSend : "false"` in your **User** settings.
161+
> **Note**: If you prefer to send code at the particular line your cursor is placed, you can turn off Smart Send by setting `python.REPL.enableREPLSmartSend : "false"` in your **User** settings.
162162
163-
1. From the Command Palette (`kb(workbench.action.showCommands)`), select the **Python: Start Terminal REPL** command to open a REPL terminal (notated by `>>>`) for the currently selected Python interpreter. In the REPL, you can then enter and run lines of code one at a time.
163+
3. From the Command Palette (`kb(workbench.action.showCommands)`), select the **Python: Start Terminal REPL** command to open a REPL terminal (notated by `>>>`) for the currently selected Python interpreter. In the REPL, you can then enter and run lines of code one at a time.
164164

165165
Congrats, you just ran your first Python code in Visual Studio Code!
166166

docs/python/tutorial-fastapi.md

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,9 @@ Now we need a place to store the grocery list items. For simplicity, let's start
185185
186186
This creates a new empty dictionary that receives keys of type `int` (as item IDs) and values of the `ItemPayload` type.
187187
188-
We'll now define routes in our FastAPI application. In the context of web applications, routes are like pathways that map specific URLs to the code that handles them. These routes serve as the entry points for the different functionality within our application. When a client, such as a web browser or another program, sends a request to our application with a particular URL, FastAPI routes that request to the appropriate function (also known as route handler or view function) based on the URL, and that function processes the request and generates a response.
188+
We'll now define routes in our FastAPI application. In the context of web applications, routes are like pathways that map specific URLs to the code that handles them. These routes serve as the entry points for the different functionality within our application. When a client, such as a web browser or another program, sends a request to our application with a particular URL, FastAPI routes that request to the appropriate function (also known as route handler or view function) based on the URL, and that function processes the request and generates a response.
189189
190-
Let's proceed with defining routes to add and retrieve individual items, as well as return all items in the grocery list.
190+
Let's proceed with defining routes to add and retrieve individual items, as well as return all items in the grocery list.
191191
192192
3. Add the following route at the end of the `main.py` file:
193193
@@ -219,7 +219,7 @@ Let's proceed with defining routes to add and retrieve individual items, as well
219219
220220
![Inlay function return and variable type hints being displayed by Pylance throughout the sample code](images/fastapi-tutorial/pylance_inlay_hints.png)
221221
222-
Now let's check if this route is working as expected. The fastest way to do so is to use both VS Code's debugger as well as FastAPI's `/docs` endpoint, which provides information about all the available API routes and lets you interact with the API to explore their parameters and responses. This documentation is generated dynamically based on the metadata and type hints defined in the FastAPI application.
222+
Now let's check if this route is working as expected. The fastest way to do so is to use both VS Code's debugger as well as FastAPI's `/docs` endpoint, which provides information about all the available API routes and lets you interact with the API to explore their parameters and responses. This documentation is generated dynamically based on the metadata and type hints defined in the FastAPI application.
223223
224224
4. Add a breakpoint next to the `if quantity <= 0` statement, by clicking on the left margin of the line number (or `kb(editor.debug.action.toggleBreakpoint)`). The debugger will stop prior to the execution of that line, so you can inspect the code line by line.
225225
@@ -249,19 +249,19 @@ Now let's check if this route is working as expected. The fastest way to do so i
249249
250250
![Variables window displayed in the Run and Debug view, with the item and grocery_list variables highlighted](images/fastapi-tutorial/fastapi_debugger_variables.png)
251251
252-
Now let's use VS Code's Debug Console to do some exploration.
252+
Now let's use VS Code's Debug Console to do some exploration.
253253
254254
10. Select the `quantity <= 0` statement, right-click on the editor and select **Evaluate in Debug Console**:
255255
256256
![Evaluate in Debug Console option displayed in the context menu when right-clicking on a line of code](images/fastapi-tutorial/fastapi_evaluate_debug_console.png)
257257
258258
This opens the Debug Console and runs the selected expression. As expected in our example, the expression evaluates to `False`.
259259
260-
The Debug Console can be a powerful tool to quickly test expressions and better understand the state of your code at the time of a breakpoint. You can also use it to run arbitrary code, such as calling functions or printing variables. You can learn more about Python debugging in VS Code in the [Python tutorial](/docs/python/python-tutorial.md#configure-and-run-the-debugger).
260+
The Debug Console can be a powerful tool to quickly test expressions and better understand the state of your code at the time of a breakpoint. You can also use it to run arbitrary code, such as calling functions or printing variables. You can learn more about Python debugging in VS Code in the [Python tutorial](/docs/python/python-tutorial.md#configure-and-run-the-debugger).
261261
262-
You can now continue the execution of the code by selecting **Continue** in the Debug view tool bar, or by pressing `kb(workbench.action.debug.continue)`.
262+
You can now continue the execution of the code by selecting **Continue** in the Debug view tool bar, or by pressing `kb(workbench.action.debug.continue)`.
263263
264-
Finally, let's add the remaining routes for the application so we can list all items or specific items, as well as remove them from our grocery list. You can leave the debugger running as it will automatically reload the application when you save the changes you make in the next step.
264+
Finally, let's add the remaining routes for the application so we can list all items or specific items, as well as remove them from our grocery list. You can leave the debugger running as it will automatically reload the application when you save the changes you make in the next step.
265265
266266
11. Replace the content in `main.py` with the code below:
267267
@@ -379,19 +379,19 @@ For the steps below, make sure you have the following requirements installed on
379379
380380
3. Select the default version.
381381
382-
We can optionally install [Features](https://github.com/devcontainers/features) to be included in the container. For this tutorial, we will install [Redis Server](https://github.com/itsmechlark/features/tree/main/src/redis-server), a community contributed Feature that installs and adds the proper dev container setup for Redis.
383-
384382
4. Select **Redis Server** as an additional feature to be installed, press **OK**, and then select **Keep Defaults**.
385383
384+
We can optionally install [Features](https://github.com/devcontainers/features) to be included in the container. For this tutorial, we will install [Redis Server](https://github.com/itsmechlark/features/tree/main/src/redis-server), a community contributed Feature that installs and adds the proper dev container setup for Redis.
385+
386386
![Redis Server option selected in the Dev Containers configuration files list](images/fastapi-tutorial/devcontainers_redis_server_feature.png)
387387
388-
This creates a `.devcontainer` folder in your workspace, with a `devcontainer.json` file. Let's make some edits to this file so the container setup includes steps such as installing the VS Code extensions we need as well as the project dependencies.
388+
This creates a `.devcontainer` folder in your workspace, with a `devcontainer.json` file. Let's make some edits to this file so the container setup includes steps such as installing the VS Code extensions we need as well as the project dependencies.
389389
390390
5. Open the `devcontainer.json` file.
391391
392392
6. Add a "," after the `"features" : { ... }` entry, so we can add more settings to the file.
393393
394-
Next, we will add the necessary dependency installation commands to the `postCreateCommand` property in the `devcontainer.json` file, so our application is ready to run once the container is set up.
394+
Next, we will add the necessary dependency installation commands to the `postCreateCommand` property in the `devcontainer.json` file, so our application is ready to run once the container is set up.
395395
396396
7. Locate the content below and remove the comment (`//`) from that line, so the dependencies can be installed once the container is created:
397397
@@ -458,19 +458,19 @@ First, let's start by replacing the dictionary with a Redis client object that c
458458
redis_client = redis.StrictRedis(host='0.0.0.0', port=6379, db=0, decode_responses=True)
459459
```
460460
461-
Pylance will display an error message because Redis hasn't been imported yet.
461+
Pylance will display an error message because Redis hasn't been imported yet.
462462
463463
2. Put the cursor on "redis" in the editor, and click on the displayed light bulb (or `kb(editor.action.quickFix)`). Then select **Add 'import redis'**.
464464
465465
![Light bulb displayed next to the Redis variable, with the option to add the import statement](images/fastapi-tutorial/fastapi_add_redis_quickfix.png)
466466
467467
>**Tip**: You can set up Pylance to automatically add imports by looking for the **Auto Import Completions** setting in the Settings editor (`kb(workbench.action.openSettings)`) and enabling it.
468468
469-
We now have a Redis client object that connects to a Redis server running on the local host (`host="0.0.0.0"`) and listening on port 6379 (`port=6379`). The `db` parameter specifies the Redis database to use. Redis supports multiple databases, and in this code we're going to use database 0, which is the default database. We're also passing `decode_responses=True` for the responses to be decoded as strings (instead of bytes).
469+
We now have a Redis client object that connects to a Redis server running on the local host (`host="0.0.0.0"`) and listening on port 6379 (`port=6379`). The `db` parameter specifies the Redis database to use. Redis supports multiple databases, and in this code we're going to use database 0, which is the default database. We're also passing `decode_responses=True` for the responses to be decoded as strings (instead of bytes).
470470
471-
Let's do some more replacements in the first route `add_item`. Instead of looking at all the keys from the dictionary to find the item name that has been provided, we can fetch that information directly from a Redis hash.
471+
Let's do some more replacements in the first route `add_item`. Instead of looking at all the keys from the dictionary to find the item name that has been provided, we can fetch that information directly from a Redis hash.
472472
473-
We'll assume that the `item_name_to_id` hash already exists, mapping item names to their IDs (don't worry, we'll add this code shortly!). We can then get the ID of the item name we're receiving in the request by invoking the `hget` method from Redis, which will return the item ID if the requested name already exists in the hash, or `None` if it doesn't.
473+
We'll assume that the `item_name_to_id` hash already exists, mapping item names to their IDs (don't worry, we'll add this code shortly!). We can then get the ID of the item name we're receiving in the request by invoking the `hget` method from Redis, which will return the item ID if the requested name already exists in the hash, or `None` if it doesn't.
474474
475475
3. Delete the line with the content below:
476476
@@ -484,7 +484,7 @@ We'll assume that the `item_name_to_id` hash already exists, mapping item names
484484
item_id = redis_client.hget("item_name_to_id", item_name)
485485
```
486486
487-
Notice that Pylance raises a problem with this change. This is because the `hget` method returns either `str`, or `None` (if the item doesn't exist). However, the lines below the code that we haven't replaced yet expect `item_id` to be of type `int`. Let's address this warning by renaming the `item_id` symbol.
487+
Notice that Pylance raises a problem with this change. This is because the `hget` method returns either `str`, or `None` (if the item doesn't exist). However, the lines below the code that we haven't replaced yet expect `item_id` to be of type `int`. Let's address this warning by renaming the `item_id` symbol.
488488
489489
4. Rename `item_id` to `item_id_str`.
490490
@@ -504,7 +504,7 @@ Notice that Pylance raises a problem with this change. This is because the `hget
504504
if item_id_str is not None:
505505
```
506506
507-
Now that we have the item ID as a string, we need to convert it to an `int` and update the quantity for the item. Currently, our Redis hash only maps item names to their IDs. To also map item IDs to their names and quantities, we will create a separate Redis hash for each item, using `"item_id:{item_id}"` as our hash name to make retrieval by ID easier. We'll also add `item_name` and `quantity` fields for each of these hashes.
507+
Now that we have the item ID as a string, we need to convert it to an `int` and update the quantity for the item. Currently, our Redis hash only maps item names to their IDs. To also map item IDs to their names and quantities, we will create a separate Redis hash for each item, using `"item_id:{item_id}"` as our hash name to make retrieval by ID easier. We'll also add `item_name` and `quantity` fields for each of these hashes.
508508
509509
7. Delete the code within the `if` block:
510510
@@ -520,9 +520,9 @@ Now that we have the item ID as a string, we need to convert it to an `int` and
520520
redis_client.hincrby(f"item_id:{item_id}", "quantity", quantity)
521521
```
522522
523-
We now only need to replace the code for when the item does not exist, when `item_id_str` is `None`. In this case, we generate a new `item_id`, create a new Redis hash for the item, and then add the provided item name and quantity.
523+
We now only need to replace the code for when the item does not exist, when `item_id_str` is `None`. In this case, we generate a new `item_id`, create a new Redis hash for the item, and then add the provided item name and quantity.
524524
525-
To generate a new `item_id`, let's use the `incr` method from Redis, passing a new hash called `"item_ids"`. This hash is used to store the last generated ID, so we can increment it each time we create a new item, ensuring that they all have a unique ID.
525+
To generate a new `item_id`, let's use the `incr` method from Redis, passing a new hash called `"item_ids"`. This hash is used to store the last generated ID, so we can increment it each time we create a new item, ensuring that they all have a unique ID.
526526
527527
8. Delete the line with the following content:
528528
@@ -538,7 +538,7 @@ To generate a new `item_id`, let's use the `incr` method from Redis, passing a n
538538
539539
When this `incr` call is run for the first time with the `item_ids` key, Redis creates the key and maps it to the value `1`. Then, each subsequent time it's run, it increments the stored value by 1.
540540
541-
Now we will add the item to the Redis hash, using the `hset` method and by providing a mapping for the fields (`item_id`, `item_name`, and `quantity`), and the values (the item's newly created ID, and its provided name and quantity).
541+
Now we will add the item to the Redis hash, using the `hset` method and by providing a mapping for the fields (`item_id`, `item_name`, and `quantity`), and the values (the item's newly created ID, and its provided name and quantity).
542542
543543
9. Delete the line with the following content:
544544
@@ -560,7 +560,7 @@ Now we will add the item to the Redis hash, using the `hset` method and by provi
560560
})
561561
```
562562
563-
Now we only need to map the newly created ID to the item name by setting the hash we referenced in the beginning, `item_name_to_id`.
563+
Now we only need to map the newly created ID to the item name by setting the hash we referenced in the beginning, `item_name_to_id`.
564564
565565
10. Add this line to the end of the route, inside the `else` block:
566566

0 commit comments

Comments
 (0)