Skip to content

Commit 1a28b24

Browse files
author
Kraig Brockschmidt
committed
Edits from review
1 parent 217fdf0 commit 1a28b24

5 files changed

+31
-10
lines changed

docs/python/editing-python-code-in-visual-studio.md

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,36 +78,41 @@ Typing @ starts a decorator and shows potential decorators. Many of these items
7878

7979
*Visual Studio 2017 version 15.7 and later.*
8080

81-
"Type hints" in Python ([PEP 484](https://www.python.org/dev/peps/pep-0484/) (python.org) is a annotation syntax for functions and classes that allow you to indicate the types of arguments, return values, and class attributes. IntelliSense displays type hints when you hover over functions calls, arguments, and variables that have those annotations.
81+
"Type hints" in Python 3.5+ ([PEP 484](https://www.python.org/dev/peps/pep-0484/) (python.org) is an annotation syntax for functions and classes that indicate the types of arguments, return values, and class attributes. IntelliSense displays type hints when you hover over functions calls, arguments, and variables that have those annotations.
8282

83-
In the example below, the `Vector` class is declared as `List[float]`, and the `scale` function contains type hints for both its arguments and return value. Hovering over a call to that function shows the tyep hints:
83+
In the example below, the `Vector` class is declared as `List[float]`, and the `scale` function contains type hints for both its arguments and return value. Hovering over a call to that function shows the type hints:
8484

8585
![Hovering over a function call to reveal type hints](media/code-editing-type-hints1.png)
8686

8787
In the following example, you can see how the annotated attributes of the `Employee` class appear in the IntelliSense completion popup for an attribute:
8888

8989
![IntelliSense completion showing type hints](media/code-editing-type-hints2.png)
9090

91-
It's also helpful to validate type hints throughout your project, because errors won't normally appear until run time. For this purpose, Visual Studio integrates the industry standard MyPy tool through the context menu command **Python > Run MyPy** in **Solution Explorer**:
91+
It's also helpful to validate type hints throughout your project, because errors won't normally appear until run time. For this purpose, Visual Studio integrates the industry standard MyPy tool through the context menu command **Python > Run Mypy** in **Solution Explorer**:
9292

9393
![Run MyPy context menu command in Solution Explorer](media/code-editing-type-hints-run-mypy.png)
9494

95-
Running the command prompts you to install MyPy, if needed, the validates type hints in every Python file in the project. Errors appear in the Visual Studio **Error List** window. Selecting an item in the window navigates to the appropriate line in your code.
95+
Running the command prompts you to install the mypy package, if needed. Visual Studio then runs mypy to validate type hints in every Python file in the project. Errors appear in the Visual Studio **Error List** window. Selecting an item in the window navigates to the appropriate line in your code.
9696

9797
As a simple example, the following function definition contains a type hint to indicate that the `input` argument is type `str`, whereas the call to that function attempts to pass an integer:
9898

9999
```python
100-
def commasToColons(input: str):
100+
def commas_to_colons(input: str):
101101
items = input.split(',')
102102
items = [x.strip() for x in items]
103103
return ':'.join(items)
104104

105-
commasToColons(1)
105+
commas_to_colons(1)
106106
```
107107

108-
Using the **Run MyPy** command on this code generates the following error:
108+
Using the **Run Mypy** command on this code generates the following error:
109109

110-
![Example result of MyPy validating type hints](media/code-editing-type-hints-validation-error.png)
110+
![Example result of mypy validating type hints](media/code-editing-type-hints-validation-error.png)
111+
112+
> [!Tip]
113+
> For versions of Python before 3.5, Visual Studio also displays type hints that you supply through *stub files* (`.pyi`). You can use stub files whenever you don't want to include type hints directly in your code, or when you want to create type hints for a library that doesn't use them directly. For more information, see [Create Stubs for Python Modules](https://github.com/python/mypy/wiki/Creating-Stubs-For-Python-Modules) in the mypy project wiki.
114+
>
115+
> At present, Visual Studio doesn't support type hints in comments.
111116
112117
### Signature help
113118

docs/python/managing-python-environments-in-visual-studio.md

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,23 @@ In Visual Studio, you can create a virtual environment for a specific project, w
4646

4747
A conda environment is one created using the `conda` tool, or with integrated conda management in Visual Studio 2017 version 15.7 and higher. (Requires Anaconda or Miniconda; Anaconda is available through the Visual Studio installer, see [Installation - Visual Studio 2017](installing-python-support-in-visual-studio.md#visual-studio-2017).)
4848

49-
Conda environments are typically stored in the `envs` folder within an Anaconda installation, and therefore act similarly to global environments. For example, installing a new package into a conda environment makes that package available to all projects using that environment.
49+
> [!Note]
50+
> For best results with conda environments, use conda 4.4.8 or later (conda versions are different from Anaconda versions). Installing Anaconda 5.1 from the Visual Studio 2017 installer
51+
52+
To see the conda version, where conda environments are stored, and other information, run `conda info` at an Anaconda command prompt (that is, a command prompt where Anaconda is in the path):
53+
54+
```bash
55+
conda info
56+
```
57+
You conda environment folders appear as follows:
58+
59+
```output
60+
envs directories : c:\anaconda3\envs
61+
C:\Users\user\AppData\Local\conda\conda\envs
62+
C:\Users\user\.conda\envs
63+
```
64+
65+
Because conda environments are not stored with a project, they act similarly to global environments. For example, installing a new package into a conda environment makes that package available to all projects using that environment.
5066

5167
For Visual Studio 2017 version 15.6 and earlier, you can use conda environments by pointing to them manually as described under [Manually identify an existing environment](#manually-identify-an-existing-environment).
5268

@@ -123,7 +139,7 @@ Use the following steps to identify an environment that's installed in a non-sta
123139

124140
*Visual Studio 2017 version 15.7 and later.*
125141

126-
1. Select **+ Create conda environment** in the **Python Environments** window, which opens the **Configure** tab:
142+
1. Select **+ Create conda environment** in the **Python Environments** window, which opens a **Create new conda environment** tab:
127143

128144
![Create tab for a new conda environment](media/environments-conda-1.png)
129145

Loading
-145 Bytes
Loading
-2.93 KB
Loading

0 commit comments

Comments
 (0)