Skip to content

Commit ff8b954

Browse files
committed
Merge branch 'master' into 3.6
2 parents 81e4430 + 0573b67 commit ff8b954

36 files changed

+1025
-484
lines changed

.editorconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ dotnet_diagnostic.CA1845.severity = none # CA1845: Use span-based 'string
8181
dotnet_diagnostic.CA1846.severity = none # CA1846: Prefer 'AsSpan' over 'Substring'
8282
dotnet_diagnostic.CA1847.severity = none # CA1847: Use char literal for a single character lookup
8383
dotnet_diagnostic.CA1852.severity = suggestion # CA1852: Seal internal types
84+
dotnet_diagnostic.CA1859.severity = suggestion # CA1859: Use concrete types when possible for improved performance
8485
dotnet_diagnostic.CA2101.severity = suggestion # CA2101: Specify marshaling for P/Invoke string arguments
8586
dotnet_diagnostic.CA2201.severity = none # CA2201: Do not raise reserved exception types
8687
dotnet_diagnostic.CA2208.severity = suggestion # CA2208: Instantiate argument exceptions correctly

Build/net462.props

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,13 @@
1010
<Features>$(Features);FEATURE_ASSEMBLY_RESOLVE</Features>
1111
<Features>$(Features);FEATURE_ASSEMBLYBUILDER_DEFINEDYNAMICASSEMBLY</Features>
1212
<Features>$(Features);FEATURE_ASSEMBLYBUILDER_SAVE</Features>
13-
<Features>$(Features);FEATURE_BASIC_CONSOLE</Features>
1413
<Features>$(Features);FEATURE_CODEDOM</Features>
1514
<Features>$(Features);FEATURE_COM</Features>
1615
<Features>$(Features);FEATURE_CONFIGURATION</Features>
1716
<Features>$(Features);FEATURE_CTYPES</Features>
1817
<Features>$(Features);FEATURE_CUSTOM_TYPE_DESCRIPTOR</Features>
1918
<Features>$(Features);FEATURE_EXCEPTION_STATE</Features>
2019
<Features>$(Features);FEATURE_FILESYSTEM</Features>
21-
<Features>$(Features);FEATURE_FULL_CONSOLE</Features>
2220
<Features>$(Features);FEATURE_FULL_CRYPTO</Features>
2321
<Features>$(Features);FEATURE_FULL_NET</Features>
2422
<Features>$(Features);FEATURE_LAMBDAEXPRESSION_COMPILETOMETHOD</Features>

Build/net6.0.props

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,13 @@
99
<Features>$(Features);FEATURE_ASSEMBLY_GETFORWARDEDTYPES</Features>
1010
<Features>$(Features);FEATURE_ASSEMBLY_RESOLVE</Features>
1111
<Features>$(Features);FEATURE_ASSEMBLYBUILDER_DEFINEDYNAMICASSEMBLY</Features>
12-
<Features>$(Features);FEATURE_BASIC_CONSOLE</Features>
1312
<Features>$(Features);FEATURE_CODEDOM</Features>
1413
<Features>$(Features);FEATURE_COM</Features>
1514
<Features>$(Features);FEATURE_CONFIGURATION</Features>
1615
<Features>$(Features);FEATURE_CTYPES</Features>
1716
<Features>$(Features);FEATURE_CUSTOM_TYPE_DESCRIPTOR</Features>
1817
<Features>$(Features);FEATURE_EXCEPTION_STATE</Features>
1918
<Features>$(Features);FEATURE_FILESYSTEM</Features>
20-
<Features>$(Features);FEATURE_FULL_CONSOLE</Features>
2119
<Features>$(Features);FEATURE_FULL_CRYPTO</Features>
2220
<Features>$(Features);FEATURE_FULL_NET</Features>
2321
<Features>$(Features);FEATURE_LCG</Features>

Build/netcoreapp2.1.props

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,12 @@
99
<Features>$(Features);FEATURE_ASSEMBLY_GETFORWARDEDTYPES</Features>
1010
<Features>$(Features);FEATURE_ASSEMBLY_RESOLVE</Features>
1111
<Features>$(Features);FEATURE_ASSEMBLYBUILDER_DEFINEDYNAMICASSEMBLY</Features>
12-
<Features>$(Features);FEATURE_BASIC_CONSOLE</Features>
1312
<Features>$(Features);FEATURE_CODEDOM</Features>
1413
<Features>$(Features);FEATURE_CONFIGURATION</Features>
1514
<Features>$(Features);FEATURE_CTYPES</Features>
1615
<Features>$(Features);FEATURE_CUSTOM_TYPE_DESCRIPTOR</Features>
1716
<Features>$(Features);FEATURE_EXCEPTION_STATE</Features>
1817
<Features>$(Features);FEATURE_FILESYSTEM</Features>
19-
<Features>$(Features);FEATURE_FULL_CONSOLE</Features>
2018
<Features>$(Features);FEATURE_FULL_CRYPTO</Features>
2119
<Features>$(Features);FEATURE_FULL_NET</Features>
2220
<Features>$(Features);FEATURE_LCG</Features>

Build/netcoreapp3.1.props

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,13 @@
99
<Features>$(Features);FEATURE_ASSEMBLY_GETFORWARDEDTYPES</Features>
1010
<Features>$(Features);FEATURE_ASSEMBLY_RESOLVE</Features>
1111
<Features>$(Features);FEATURE_ASSEMBLYBUILDER_DEFINEDYNAMICASSEMBLY</Features>
12-
<Features>$(Features);FEATURE_BASIC_CONSOLE</Features>
1312
<Features>$(Features);FEATURE_CODEDOM</Features>
1413
<Features>$(Features);FEATURE_COM</Features>
1514
<Features>$(Features);FEATURE_CONFIGURATION</Features>
1615
<Features>$(Features);FEATURE_CTYPES</Features>
1716
<Features>$(Features);FEATURE_CUSTOM_TYPE_DESCRIPTOR</Features>
1817
<Features>$(Features);FEATURE_EXCEPTION_STATE</Features>
1918
<Features>$(Features);FEATURE_FILESYSTEM</Features>
20-
<Features>$(Features);FEATURE_FULL_CONSOLE</Features>
2119
<Features>$(Features);FEATURE_FULL_CRYPTO</Features>
2220
<Features>$(Features);FEATURE_FULL_NET</Features>
2321
<Features>$(Features);FEATURE_LCG</Features>

Build/netstandard2.0.props

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,12 @@
88
<Features>$(Features);FEATURE_APARTMENTSTATE</Features>
99
<Features>$(Features);FEATURE_ASSEMBLY_RESOLVE</Features>
1010
<Features>$(Features);FEATURE_ASSEMBLYBUILDER_DEFINEDYNAMICASSEMBLY</Features>
11-
<Features>$(Features);FEATURE_BASIC_CONSOLE</Features>
1211
<Features>$(Features);FEATURE_CODEDOM</Features>
1312
<Features>$(Features);FEATURE_CONFIGURATION</Features>
1413
<Features>$(Features);FEATURE_CTYPES</Features>
1514
<Features>$(Features);FEATURE_CUSTOM_TYPE_DESCRIPTOR</Features>
1615
<Features>$(Features);FEATURE_EXCEPTION_STATE</Features>
1716
<Features>$(Features);FEATURE_FILESYSTEM</Features>
18-
<Features>$(Features);FEATURE_FULL_CONSOLE</Features>
1917
<Features>$(Features);FEATURE_FULL_CRYPTO</Features>
2018
<Features>$(Features);FEATURE_FULL_NET</Features>
2119
<Features>$(Features);FEATURE_LCG</Features>

Documentation/feature-symbols.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@ System.Reflection.Emit.AssemblyBuilder.DefineDynamicAssembly
2020
### FEATURE_ASSEMBLYBUILDER_SAVE
2121
System.Reflection.Emit.AssemblyBuilder.Save
2222

23-
### FEATURE_BASIC_CONSOLE
24-
Basic Console features like Console.WriteLine, Console.ReadLine.
25-
2623
### FEATURE_CODEDOM
2724
System.CodeDom
2825

@@ -42,9 +39,6 @@ System.Threading.ThreadAbortException.ExceptionState
4239
### FEATURE_FILESYSTEM
4340
Full file system (Directory, File, Path, FileStream, etc.)
4441

45-
### FEATURE_FULL_CONSOLE
46-
Full Console APIs including stdin, stdout, stderr streams, colors, etc.
47-
4842
### FEATURE_FULL_CRYPTO
4943

5044
### FEATURE_FULL_NET

Documentation/upgrading-from-ipy2.md

Lines changed: 49 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,55 @@ System.StringSplitOptions["None"]
3131

3232
Similarly, `True` and `False` are also keywords in Python 3.
3333

34+
## Redirecting output
35+
36+
With IronPython 2, standard output was written to the runtime's `SharedIO.OutputWriter` (which was `Console.Out` by default). This is no longer the case with IronPython 3 where the standard output is a binary stream. The output is now written to runtime's `SharedIO.OutputStream`. Similarly, standard input and error are now using `SharedIO.InputStream` and `SharedIO.ErrorStream` respectively.
37+
38+
Because of this, using a `TextWriter` to capture output will no longer work. As a workaround, in order to use a `TextWriter` as the main method of redirection, one could wrap the writer inside a stream (for example, see [`TextStream`][TextStream]).
39+
40+
```c#
41+
// IronPython 2
42+
var engine = Python.CreateEngine();
43+
var textWriter = new MyTextWriter();
44+
// no longer works in IronPython 3!
45+
engine.Runtime.IO.RedirectToConsole();
46+
Console.SetOut(textWriter);
47+
```
48+
49+
```c#
50+
// IronPython 3
51+
var engine = Python.CreateEngine();
52+
var textWriter = new MyTextWriter();
53+
engine.Runtime.IO.SetOutput(new TextStream(textWriter), textWriter);
54+
```
55+
56+
Another way of achieving the redirection behavior similar to IronPython 2 is to set engine option `ConsoleSupportLevel` to `SupportLevel.Basic`. IronPython 3 still uses binary streams for standard input and output but **all three** standard streams are set to use `TextStream`, forwarding to the corresponding writers/reader.
57+
58+
```c#
59+
// IronPython 3
60+
var engine = Python.CreateEngine(new Dictionary<string, object> {
61+
{ "ConsoleSupportLevel", Microsoft.Scripting.Runtime.SharedIO.SupportLevel.Basic },
62+
});
63+
var textWriter = new MyTextWriter();
64+
// works again!
65+
engine.Runtime.IO.RedirectToConsole();
66+
Console.SetOut(textWriter);
67+
```
68+
69+
This method is particularly useful when embedding the IronPython 3 engine in a host that sets console's writers/reader before the engine is created and the host's code is not accessible to the user (for instance, scripting in [LINQPad]).
70+
71+
```c#
72+
// IronPython 3 in LINQPad
73+
var engine = Python.CreateEngine(new Dictionary<string, object> {
74+
{ "ConsoleSupportLevel", Microsoft.Scripting.Runtime.SharedIO.SupportLevel.Basic },
75+
});
76+
engine.Execute("print('abc')"); // shows output in the "Results" pane
77+
dynamic ans = engine.Execute("input()"); // pauses the script and asks for input at the bottom of the "Results" pane; terminate your input with Ctrl+Z, Enter
78+
```
79+
80+
[TextStream]: https://github.com/IronLanguages/dlr/blob/master/Src/Microsoft.Scripting/Utils/TextStream.cs
81+
[LINQPad]: https://www.linqpad.net/
82+
3483
## `int` Type
3584

3685
One of the major backward incompatible changes in Python 3 is [PEP 237 – Unifying Long Integers and Integers][PEP 0237]: Essentially, `long` renamed to `int`. That is, there is only one built-in integral type, named `int`; but it behaves mostly like the old `long` type. From the pure Python perspective this means that `int` should be used wherever previously `long` was used. More consideration has to be applied in interop cases with .NET.
@@ -206,27 +255,3 @@ IronPython's `range` is a generator that produces a sequence of `int` values. Th
206255

207256
[PEP 0237]: https://python.org/dev/peps/pep-0237
208257

209-
210-
## Redirecting output
211-
212-
With IronPython 2, standard output was written to the runtime's `SharedIO.OutputWriter` (which was `Console.Out` by default). This is no longer the case with IronPython 3 where the standard output is a binary stream. The output is now written to runtime's `SharedIO.OutputStream`. Similarly, standard input and error are now using `SharedIO.InputStream` and `SharedIO.ErrorStream` respectively.
213-
214-
Because of this, using a `TextWriter` to capture output will no longer work. As a workaround, in order to use a `TextWriter` as the main method of redirection, one could wrap the writer inside a stream (for example, see [TextStream][TextStream]).
215-
216-
IronPython 2
217-
```c#
218-
var engine = Python.CreateEngine();
219-
var textWriter = new MyTextWriter();
220-
// no longer works!
221-
engine.Runtime.IO.RedirectToConsole();
222-
Console.SetOut(textWriter);
223-
```
224-
225-
IronPython 3
226-
```c#
227-
var engine = Python.CreateEngine();
228-
var textWriter = new MyTextWriter();
229-
engine.Runtime.IO.SetOutput(new TextStream(textWriter), textWriter);
230-
```
231-
232-
[TextStream]: https://github.com/IronLanguages/main/blob/master/Runtime/Microsoft.Dynamic/Utils/TextStream.cs

Package/nuget/IronPython.nuspec

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,23 @@ This package contains the IronPython interpreter engine.</description>
1919
<tags>ironpython python dynamic dlr</tags>
2020
<dependencies>
2121
<group targetFramework="net462">
22-
<dependency id="DynamicLanguageRuntime" version="1.3.3" />
22+
<dependency id="DynamicLanguageRuntime" version="1.3.4" />
2323
<dependency id="System.Memory" version="4.5.5" />
2424
</group>
2525
<group targetFramework="netstandard2.0">
26-
<dependency id="DynamicLanguageRuntime" version="1.3.3" />
26+
<dependency id="DynamicLanguageRuntime" version="1.3.4" />
2727
<dependency id="System.Memory" version="4.5.5" />
2828
<dependency id="System.Text.Encoding.CodePages" version="4.6.0" />
2929
<dependency id="Microsoft.Win32.Registry" version="4.5.0" />
3030
<dependency id="Mono.Unix" version="7.1.0-final.1.21458.1" />
3131
</group>
3232
<group targetFramework="netcoreapp3.1">
33-
<dependency id="DynamicLanguageRuntime" version="1.3.3" />
33+
<dependency id="DynamicLanguageRuntime" version="1.3.4" />
3434
<dependency id="Microsoft.Win32.Registry" version="4.7.0" />
3535
<dependency id="Mono.Unix" version="7.1.0-final.1.21458.1" />
3636
</group>
3737
<group targetFramework="net6.0">
38-
<dependency id="DynamicLanguageRuntime" version="1.3.3" />
38+
<dependency id="DynamicLanguageRuntime" version="1.3.4" />
3939
<dependency id="Mono.Unix" version="7.1.0-final.1.21458.1" />
4040
</group>
4141
</dependencies>

0 commit comments

Comments
 (0)