Skip to content

Commit c2ce5c1

Browse files
committed
Update Copilot instructions to include type hints for Python and TypeScript, and clarify usage guidelines
1 parent 3222771 commit c2ce5c1

File tree

1 file changed

+33
-12
lines changed

1 file changed

+33
-12
lines changed

content/1-hour/3-copilot-instructions.md

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,22 @@ Here are some guidelines to consider when creating a Copilot instructions file:
2121
- languages, frameworks and libraries in use.
2222
- required assets to be generated (such as unit tests) and where they should be placed.
2323
- any language specific rules such as:
24-
- Python code should always follow PEP8 rules.
25-
- use arrow functions rather than the `function` keyword.
24+
- utilize [type hints](https://mypy.readthedocs.io/en/stable/cheat_sheet_py3.html) in Python.
25+
- use [arrow functions](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions) rather than the `function` keyword in TypeScript.
2626
- If you notice GitHub Copilot consistently provides an unexpected suggestion (e.g. using class components for React), add those notes to the instructions file.
2727

28-
Let's create a Copilot instructions file. Just as before, because we want you to explore and experiment, we won't provide exact directions on what to type, but will give enough context to create one on your own.
28+
Let's create a Copilot instructions file. We'll start by asking Copilot to generate a block of code, then add the instructions file, then ask the same question again to see the changes.
2929

3030
1. Return to your IDE with your project open.
31-
2. Create a new file in the **.github** folder called **copilot-instructions.md**.
32-
3. Add the markdown to the file necessary which provides information about the project structure and requirements:
31+
2. Open Copilot Chat and send the following prompt:
32+
33+
```
34+
Create a Python function to validate dog age. Ensure age is between 0 and 20. Throw an error if it is outside this range.
35+
```
36+
37+
3. Note the function signature is similar to `def validate_age(age)` without type hints.
38+
4. Create a new file in the **.github** folder called **copilot-instructions.md**.
39+
5. Add the markdown to the file necessary which provides information about the project structure and requirements:
3340
3441
```markdown
3542
# Dog shelter
@@ -39,27 +46,41 @@ Let's create a Copilot instructions file. Just as before, because we want you to
3946
## Backend
4047
4148
- Built using Flask and SQLAlchemy
42-
- All routes require unit tests, which are created in *test_file.py* in the same folder as the file
43-
- When creating tests, always mock database calls
49+
- Use type hints
4450
4551
## Frontend
4652
4753
- Built using Astro and Svelte
54+
- TypeScript should use arrow functions rather than the function keyword
4855
- Pages should be in dark mode with a modern look and feel
4956
```
5057
51-
4. Save the file!
58+
6. **Save** the file.
5259
5360
## Watch the instructions file in action
5461
55-
Whenever you make a call to Copilot chat, the references dialog indicates all files used to generate the response. Once you create a Copilot instructions file, you will see it's always included in the references section.
62+
Whenever you make a call to Copilot chat, the references dialog indicates all files used to generate the response. Once you create a Copilot instructions file, you will see it's always included in the references section. Since you included directions to use type hints, you'll notice the code suggestions will follow this guidance.
5663
57-
1. Close all files currently open in VS Code or your Codespace.
64+
1. Close all files currently open in VS Code or your Codespace. (This will ensure we are working with an empty context.)
5865
2. Select the `+` icon in GitHub Copilot chat to start a new chat.
59-
3. Ask Copilot chat **What are the guidelines for the flask app?**
66+
3. Send Copilot chat the same prompt you used previously:
67+
68+
```
69+
Create a Python function to validate dog age. Ensure age is between 0 and 20. Throw an error if it is outside this range.
70+
```
71+
6072
4. Note the references now includes the instructions file and provides information gathered from it.
6173
62-
![Screenshot of the chat window with the references section expanded displaying Copilot instructions in the list](./images/copilot-chat-references.png)
74+
![Screenshot of the chat window with the references section expanded displaying Copilot instructions in the list](./images/copilot-chat-references.png)
75+
76+
5. Note the resulting Python now utilizes type hints, and the function signature will resemble the following:
77+
78+
```python
79+
def validate_age(age: Union[int, float, str]) -> float:
80+
```
81+
82+
> [!NOTE]
83+
> The exact code generated will vary, but the resulting Python suggestion should now utilize type hints.
6384
6485
## Summary and next steps
6586

0 commit comments

Comments
 (0)