question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Optional Parameters from IronPython

See original GitHub issue

Any idea as to why when I call a RestEase generated method from IronPython it doesn’t respect my optional query parameters?

        Task<MyThing> MyMethod(
            [Query] bool? param1 = null,
            [Query] string param2 = null,
            [Query] string param3 = null,
            [Query] string param4 = null
            );

It works fine from a standard C# client, but from my embedded IronPython client it tells me MyMethod() takes exactly 4 arguments (0 given)

IronPython generally respects optional parameters and if I pass null values in it works fine.

Is there some ‘magic’ happening in the code generation that means the parameters are not actually optional in the resulting method?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:10 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
canton7commented, Jun 29, 2018
1reaction
canton7commented, Jun 28, 2018

Ah, right. I might be able to do something about that: I’ll have a look.

On 28 June 2018 15:02:08 BST, Adrian Cockburn notifications@github.com wrote:

That’ll explain it… Python doesn’t care about types or interfaces, as it’s fully dynamic or ‘duck typed’:

If it walks like a duck and it quacks like a duck, then it must be a duck

   public interface IMyThing
   {
       string DoStuffWithOrWithoutAParam(string param = null);
   }

   public class MyThing : IMyThing
   {
       public string DoStuffWithOrWithoutAParam(string param = null)
       {
return string.Format("Hello {0}", string.IsNullOrWhiteSpace(param) ?
"World" : param);
       }
   }

   public class MyBrokenThing : IMyThing
   {
       public string DoStuffWithOrWithoutAParam(string param)
       {
return string.Format("Hello {0}", string.IsNullOrWhiteSpace(param) ?
"World" : param);
       }
   }

So, the first implementation works from IronPython but the second one doesn’t. Strangely, I’ve been working with IronPyhton for about 6 years now and have never come across this before now.

– You are receiving this because you commented. Reply to this email directly or view it on GitHub: https://github.com/canton7/RestEase/issues/98#issuecomment-401045543

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can I use Named and Optional Arguments in ironpython
As this SO question says, the new named arguments of .NET are not supported in IronPython (which uses named arguments to constructors it...
Read more >
2. Built-in Functions — IronPython 2.7.2b1 documentation
The arguments are a file name and two optional dictionaries. The file is parsed and evaluated as a sequence of Python statements (similarly...
Read more >
Using Python Optional Arguments When Defining Functions
In this tutorial, you'll learn about Python optional arguments and how to define functions with default values. You'll also learn how to create...
Read more >
IronPython .NET Integration
IronPython supports two ways of passing ref or out arguments to a method, an implicit way and an explicit way. In the implicit...
Read more >
[Ironpython-users] Binding problem with default parameters in ...
The problem is that the method has optional parameters, but those are only declared at the interface. Now, when the class changes from...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found