From 8329cdbe396d6cfa0061cedac2e6fa65744cd8c1 Mon Sep 17 00:00:00 2001 From: Benedikt Reinartz Date: Tue, 26 Apr 2022 08:17:00 +0200 Subject: [PATCH 1/3] Add test for Decimal default parameter --- src/testing/Python.Test.csproj | 1 + src/testing/methodtest.cs | 5 +++++ tests/test_method.py | 6 ++++++ 3 files changed, 12 insertions(+) diff --git a/src/testing/Python.Test.csproj b/src/testing/Python.Test.csproj index 1f40f4518..3adc5c0c6 100644 --- a/src/testing/Python.Test.csproj +++ b/src/testing/Python.Test.csproj @@ -5,6 +5,7 @@ true ..\pythonnet.snk true + IDE0051;IDE0060 diff --git a/src/testing/methodtest.cs b/src/testing/methodtest.cs index fe49de88d..ec05fef72 100644 --- a/src/testing/methodtest.cs +++ b/src/testing/methodtest.cs @@ -258,6 +258,11 @@ public static int TestSingleDefaultParam(int i = 5) return i; } + public static decimal TestDecimalDefaultParam(decimal n = 1m) + { + return n; + } + public static int TestTwoDefaultParam(int i = 5, int j = 6) { return i + j; diff --git a/tests/test_method.py b/tests/test_method.py index e2d8d5b06..b24b525aa 100644 --- a/tests/test_method.py +++ b/tests/test_method.py @@ -441,6 +441,12 @@ def test_single_default_param(): assert result == 5 +def test_decimal_default_param(): + """Test that decimal default parameters work.""" + result = MethodTest.TestDecimalDefaultParam() + assert result == System.Decimal(1) + + def test_one_arg_and_two_default_param(): """Test void method with single ref-parameter.""" result = MethodTest.TestOneArgAndTwoDefaultParam(11) From 6c21a6e174208b7a295439b1bd5e3e1bebb3ecf3 Mon Sep 17 00:00:00 2001 From: Benedikt Reinartz Date: Tue, 26 Apr 2022 08:19:49 +0200 Subject: [PATCH 2/3] Drop outdated work around to fix decimal default parameters --- src/runtime/MethodBinder.cs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/runtime/MethodBinder.cs b/src/runtime/MethodBinder.cs index 8b9ee9c00..be4e8d0e5 100644 --- a/src/runtime/MethodBinder.cs +++ b/src/runtime/MethodBinder.cs @@ -1072,11 +1072,7 @@ static internal class ParameterInfoExtensions { public static object? GetDefaultValue(this ParameterInfo parameterInfo) { - // parameterInfo.HasDefaultValue is preferable but doesn't exist in .NET 4.0 - bool hasDefaultValue = (parameterInfo.Attributes & ParameterAttributes.HasDefault) == - ParameterAttributes.HasDefault; - - if (hasDefaultValue) + if (parameterInfo.HasDefaultValue) { return parameterInfo.DefaultValue; } From 53c5542d49d0f196c5b1eab78f39623bea57d41f Mon Sep 17 00:00:00 2001 From: Benedikt Reinartz Date: Tue, 26 Apr 2022 08:24:10 +0200 Subject: [PATCH 3/3] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1e706b866..766258c5d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -113,6 +113,7 @@ Instead, `PyIterable` does that. - Unicode strings with surrogates were truncated when converting from Python - `Reload` mode now supports generic methods (previously Python would stop seeing them after reload) - Temporarily fixed issue resolving method overload when method signature has `out` parameters ([#1672](i1672)) +- Decimal default parameters are now correctly taken into account ### Removed pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy