pythonnet
pythonnet copied to clipboard
match python type T to Nullable<T> in C#
When a method parameter in C# is defined as Nullable
like int?
and you call it in python by like a literal int number, it does not match with int?
and could not bind the method, at least in .NETStandard2.0. So this update is telling the MethodBinder
class that a primitive value (with the type of T
) in python can be matched with the corresponding primitive type (T
) in C# or the Nullable<T>
type too.
What does this implement/fix? Explain your changes.
...
Does this close any currently open issues?
...
Any other comments?
...
Checklist
Check all those that are applicable and complete.
- [ ] Make sure to include one or more tests for your change
- [ ] If an enhancement PR, please create docs and at best an example
- [ ] Add yourself to
AUTHORS
- [ ] Updated the
CHANGELOG
Codecov Report
Merging #1191 into master will not change coverage. The diff coverage is
n/a
.
@@ Coverage Diff @@
## master #1191 +/- ##
=======================================
Coverage 86.25% 86.25%
=======================================
Files 1 1
Lines 291 291
=======================================
Hits 251 251
Misses 40 40
Flag | Coverage Δ | |
---|---|---|
#setup_linux | 64.94% <ø> (ø) |
|
#setup_windows | 72.50% <ø> (ø) |
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
Legend - Click here to learn more
Δ = absolute <relative> (impact)
,ø = not affected
,? = missing data
Powered by Codecov. Last update 7a9dcfa...9135b94. Read the comment docs.
Honestly, I am not even sure we need TryComputeArgumentType
. The only thing it provides right now is resolving between Foo(int)
and Foo(double)
, which should be handled in a different way altogether: the current version looks like it won't let you call Foo(double, string)
by doing Foo(1, "42")
in Python.
Anyway I couldn't call a C# class constructor say Foo(int, int, double?)
by calling Foo(2, 5, 0.25)
in Python. So with this minor change in the code, it just works.
For now, I think TryComputeArgumentType
do an important job in the library and it needs some improvements. If the logic needs refactoring, still this minor change need to be considered...
@hatami57 can you try passing a Nullable(0.25)
or Nullable[Double](0.25)
as a workaround?
@hatami57 can you try passing a
Nullable(0.25)
orNullable[Double](0.25)
as a workaround?
As far as I remember, I did try it but it didn't work...
Codecov Report
Merging #1191 (9135b94) into master (f8c27a1) will increase coverage by
12.20%
. The diff coverage isn/a
.
@@ Coverage Diff @@
## master #1191 +/- ##
===========================================
+ Coverage 74.04% 86.25% +12.20%
===========================================
Files 1 1
Lines 289 291 +2
===========================================
+ Hits 214 251 +37
+ Misses 75 40 -35
Flag | Coverage Δ | |
---|---|---|
setup_linux | 64.94% <ø> (?) |
|
setup_windows | 72.50% <ø> (-1.54%) |
:arrow_down: |
Flags with carried forward coverage won't be shown. Click here to find out more.
Impacted Files | Coverage Δ | |
---|---|---|
setup.py | 86.25% <0.00%> (+12.20%) |
:arrow_up: |
Continue to review full report at Codecov.
Legend - Click here to learn more
Δ = absolute <relative> (impact)
,ø = not affected
,? = missing data
Powered by Codecov. Last update 4133927...e3bf747. Read the comment docs.
@hatami57 Did you try what lostmsu suggested again on 3.0?