You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/python/editing-python-code-in-visual-studio.md
+13-8Lines changed: 13 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -78,36 +78,41 @@ Typing @ starts a decorator and shows potential decorators. Many of these items
78
78
79
79
*Visual Studio 2017 version 15.7 and later.*
80
80
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.
82
82
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:
84
84
85
85

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

90
90
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**:
92
92
93
93

94
94
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.
96
96
97
97
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:
98
98
99
99
```python
100
-
defcommasToColons(input: str):
100
+
defcommas_to_colons(input: str):
101
101
items =input.split(',')
102
102
items = [x.strip() for x in items]
103
103
return':'.join(items)
104
104
105
-
commasToColons(1)
105
+
commas_to_colons(1)
106
106
```
107
107
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:
109
109
110
-

110
+

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.
Copy file name to clipboardExpand all lines: docs/python/managing-python-environments-in-visual-studio.md
+18-2Lines changed: 18 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -46,7 +46,23 @@ In Visual Studio, you can create a virtual environment for a specific project, w
46
46
47
47
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).)
48
48
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.
50
66
51
67
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).
52
68
@@ -123,7 +139,7 @@ Use the following steps to identify an environment that's installed in a non-sta
123
139
124
140
*Visual Studio 2017 version 15.7 and later.*
125
141
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:
127
143
128
144

0 commit comments