Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7247da5

Browse files
authored
Fix decimal default parameters (#1773)
* Drop outdated work around to fix decimal default parameters* Add test for Decimal default parameter* Update changelog
1 parent090ff9f commit7247da5

File tree

5 files changed

+14
-5
lines changed

5 files changed

+14
-5
lines changed

‎CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ Instead, `PyIterable` does that.
113113
- Unicode strings with surrogates were truncated when converting from Python
114114
-`Reload` mode now supports generic methods (previously Python would stop seeing them after reload)
115115
- Temporarily fixed issue resolving method overload when method signature has`out` parameters ([#1672](i1672))
116+
- Decimal default parameters are now correctly taken into account
116117

117118
###Removed
118119

‎src/runtime/MethodBinder.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1072,11 +1072,7 @@ static internal class ParameterInfoExtensions
10721072
{
10731073
publicstaticobject?GetDefaultValue(thisParameterInfoparameterInfo)
10741074
{
1075-
// parameterInfo.HasDefaultValue is preferable but doesn't exist in .NET 4.0
1076-
boolhasDefaultValue=(parameterInfo.Attributes&ParameterAttributes.HasDefault)==
1077-
ParameterAttributes.HasDefault;
1078-
1079-
if(hasDefaultValue)
1075+
if(parameterInfo.HasDefaultValue)
10801076
{
10811077
returnparameterInfo.DefaultValue;
10821078
}

‎src/testing/Python.Test.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
66
<AssemblyOriginatorKeyFile>..\pythonnet.snk</AssemblyOriginatorKeyFile>
77
<SignAssembly>true</SignAssembly>
8+
<NoWarn>IDE0051;IDE0060</NoWarn>
89
</PropertyGroup>
910
<ItemGroup>
1011
<ProjectReferenceInclude="..\runtime\Python.Runtime.csproj" />

‎src/testing/methodtest.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,11 @@ public static int TestSingleDefaultParam(int i = 5)
258258
returni;
259259
}
260260

261+
publicstaticdecimalTestDecimalDefaultParam(decimaln=1m)
262+
{
263+
returnn;
264+
}
265+
261266
publicstaticintTestTwoDefaultParam(inti=5,intj=6)
262267
{
263268
returni+j;

‎tests/test_method.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,12 @@ def test_single_default_param():
441441
assertresult==5
442442

443443

444+
deftest_decimal_default_param():
445+
"""Test that decimal default parameters work."""
446+
result=MethodTest.TestDecimalDefaultParam()
447+
assertresult==System.Decimal(1)
448+
449+
444450
deftest_one_arg_and_two_default_param():
445451
"""Test void method with single ref-parameter."""
446452
result=MethodTest.TestOneArgAndTwoDefaultParam(11)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp