Discussion:
[Python.NET] Passing in null as the value for a nullable type.
John Gill
2014-02-05 16:46:59 UTC
Permalink
I am sure there is a really simple answer to this one... but so far it is eluding me.

I have a class something like this:

public class Foo
{
...
public int process_date(DateTime? mydate)
{
...
}
}


I want to call this from python using pythondotnet.


Calling it like this works fine:

mydate = DateTime(0)
Foo().process_date(mydate)

But if I try to pass in a null as the date as follows:

Foo().process_date(None)

I get:

TypeError: No method matches given arguments

Hoping there is something really obvious I am missing here.

John

This communication and any attachments contain information which is confidential and may also be legally privileged. It is for the exclusive use of the intended recipient(s). If you are not the intended recipient(s) please note that any form of disclosure, distribution, copying, printing or use of this communication or the information in it or in any attachments is strictly prohibited and may be unlawful. If you have received this communication in error, please return it with the title "received in error" to ***@tokiomillennium.com and then permanently delete the email and any attachments from your system.

E-mail communications cannot be guaranteed to be secure or error free, as information could be intercepted, corrupted, amended, lost, destroyed, arrive late or incomplete, or contain viruses. It is the recipient's responsibility to ensure that e-mail transmissions and any attachments are virus free. We do not accept liability for any damages or other consequences caused by information that is intercepted, corrupted, amended, lost, destroyed, arrives late or incomplete or contains viruses.
******************************************
Tribble, Brett
2014-02-05 17:44:44 UTC
Permalink
I believe you want to import System and pass System.Null. I can't remember if I've done this, but I think so.

From: PythonDotNet [mailto:pythondotnet-bounces+btribble=ea.com-+ZN9ApsXKcFQFI55V6+***@public.gmane.orgg] On Behalf Of John Gill
Sent: Wednesday, February 05, 2014 8:47 AM
To: pythondotnet-+ZN9ApsXKcEdnm+***@public.gmane.org
Subject: [Python.NET] Passing in null as the value for a nullable type.

I am sure there is a really simple answer to this one... but so far it is eluding me.

I have a class something like this:

public class Foo
{
...
public int process_date(DateTime? mydate)
{
...
}
}


I want to call this from python using pythondotnet.


Calling it like this works fine:

mydate = DateTime(0)
Foo().process_date(mydate)

But if I try to pass in a null as the date as follows:

Foo().process_date(None)

I get:

TypeError: No method matches given arguments

Hoping there is something really obvious I am missing here.

John
This communication and any attachments contain information which is confidential and may also be legally privileged. It is for the exclusive use of the intended recipient(s). If you are not the intended recipient(s) please note that any form of disclosure, distribution, copying, printing or use of this communication or the information in it or in any attachments is strictly prohibited and may be unlawful. If you have received this communication in error, please return it with the title "received in error" to ***@tokiomillennium.com<mailto:postmaster-U6M1/***@public.gmane.org> and then permanently delete the email and any attachments from your system.


E-mail communications cannot be guaranteed to be secure or error free, as information could be intercepted, corrupted, amended, lost, destroyed, arrive late or incomplete, or contain viruses. It is the recipient's responsibility to ensure that e-mail transmissions and any attachments are virus free. We do not accept liability for any damages or other consequences caused by information that is intercepted, corrupted, amended, lost, destroyed, arrives late or incomplete or contains viruses.
******************************************
John Gill
2014-02-05 18:25:17 UTC
Permalink
Thanks. At least on my system there is no such thing as System.Null

In c# at least, null is just a keyword in the language.


From: PythonDotNet [mailto:pythondotnet-bounces+jgill=***@python.org] On Behalf Of Tribble, Brett
Sent: Wednesday, February 05, 2014 1:45 PM
To: A list for users and developers of Python for .NET
Subject: Re: [Python.NET] Passing in null as the value for a nullable type.

I believe you want to import System and pass System.Null. I can't remember if I've done this, but I think so.

From: PythonDotNet [mailto:pythondotnet-bounces+btribble=ea.com-+ZN9ApsXKcFQFI55V6+***@public.gmane.orgg] On Behalf Of John Gill
Sent: Wednesday, February 05, 2014 8:47 AM
To: pythondotnet-+ZN9ApsXKcEdnm+***@public.gmane.org
Subject: [Python.NET] Passing in null as the value for a nullable type.

I am sure there is a really simple answer to this one... but so far it is eluding me.

I have a class something like this:

public class Foo
{
...
public int process_date(DateTime? mydate)
{
...
}
}


I want to call this from python using pythondotnet.


Calling it like this works fine:

mydate = DateTime(0)
Foo().process_date(mydate)

But if I try to pass in a null as the date as follows:

Foo().process_date(None)

I get:

TypeError: No method matches given arguments

Hoping there is something really obvious I am missing here.

John
This communication and any attachments contain information which is confidential and may also be legally privileged. It is for the exclusive use of the intended recipient(s). If you are not the intended recipient(s) please note that any form of disclosure, distribution, copying, printing or use of this communication or the information in it or in any attachments is strictly prohibited and may be unlawful. If you have received this communication in error, please return it with the title "received in error" to ***@tokiomillennium.com<mailto:postmaster-U6M1/***@public.gmane.org> and then permanently delete the email and any attachments from your system.


E-mail communications cannot be guaranteed to be secure or error free, as information could be intercepted, corrupted, amended, lost, destroyed, arrive late or incomplete, or contain viruses. It is the recipient's responsibility to ensure that e-mail transmissions and any attachments are virus free. We do not accept liability for any damages or other consequences caused by information that is intercepted, corrupted, amended, lost, destroyed, arrives late or incomplete or contains viruses.
******************************************

This communication and any attachments contain information which is confidential and may also be legally privileged. It is for the exclusive use of the intended recipient(s). If you are not the intended recipient(s) please note that any form of disclosure, distribution, copying, printing or use of this communication or the information in it or in any attachments is strictly prohibited and may be unlawful. If you have received this communication in error, please return it with the title "received in error" to ***@tokiomillennium.com and then permanently delete the email and any attachments from your system.

E-mail communications cannot be guaranteed to be secure or error free, as information could be intercepted, corrupted, amended, lost, destroyed, arrive late or incomplete, or contain viruses. It is the recipient's responsibility to ensure that e-mail transmissions and any attachments are virus free. We do not accept liability for any damages or other consequences caused by information that is intercepted, corrupted, amended, lost, destroyed, arrives late or incomplete or contains viruses.
******************************************
Zane D. Purvis
2014-02-05 19:35:44 UTC
Permalink
Try System.Nullable[System.DateTime]()

I haven't tested that, but I think that's what you need.
Post by John Gill
Thanks. At least on my system there is no such thing as System.Null
In c# at least, null is just a keyword in the language.
*From:* PythonDotNet [mailto:pythondotnet-bounces+jgill=
*Sent:* Wednesday, February 05, 2014 1:45 PM
*To:* A list for users and developers of Python for .NET
*Subject:* Re: [Python.NET] Passing in null as the value for a nullable
type.
I believe you want to import System and pass System.Null. I can't remember
if I've done this, but I think so.
*From:* PythonDotNet [mailto:pythondotnet-bounces+btribble=
*Sent:* Wednesday, February 05, 2014 8:47 AM
*Subject:* [Python.NET] Passing in null as the value for a nullable type.
I am sure there is a really simple answer to this one... but so far it is eluding me.
public class Foo
{
...
public int process_date(DateTime? mydate)
{
...
}
}
I want to call this from python using pythondotnet.
mydate = DateTime(0)
Foo().process_date(mydate)
Foo().process_date(None)
TypeError: No method matches given arguments
Hoping there is something really obvious I am missing here.
John
This communication and any attachments contain information which is
confidential and may also be legally privileged. It is for the exclusive
use of the intended recipient(s). If you are not the intended recipient(s)
please note that any form of disclosure, distribution, copying, printing or
use of this communication or the information in it or in any attachments is
strictly prohibited and may be unlawful. If you have received this
communication in error, please return it with the title "received in error"
and any attachments from your system.
E-mail communications cannot be guaranteed to be secure or error free, as
information could be intercepted, corrupted, amended, lost, destroyed,
arrive late or incomplete, or contain viruses. It is the recipient's
responsibility to ensure that e-mail transmissions and any attachments are
virus free. We do not accept liability for any damages or other
consequences caused by information that is intercepted, corrupted, amended,
lost, destroyed, arrives late or incomplete or contains viruses.
******************************************
This communication and any attachments contain information which is
confidential and may also be legally privileged. It is for the exclusive
use of the intended recipient(s). If you are not the intended recipient(s)
please note that any form of disclosure, distribution, copying, printing or
use of this communication or the information in it or in any attachments is
strictly prohibited and may be unlawful. If you have received this
communication in error, please return it with the title "received in error"
and any attachments from your system.
E-mail communications cannot be guaranteed to be secure or error free, as
information could be intercepted, corrupted, amended, lost, destroyed,
arrive late or incomplete, or contain viruses. It is the recipient's
responsibility to ensure that e-mail transmissions and any attachments are
virus free. We do not accept liability for any damages or other
consequences caused by information that is intercepted, corrupted, amended,
lost, destroyed, arrives late or incomplete or contains viruses.
******************************************
_________________________________________________
https://mail.python.org/mailman/listinfo/pythondotnet
John Gill
2014-02-05 20:13:30 UTC
Permalink
That's what I thought too... but..

In [82]: System.Nullable[System.DateTime]()
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-82-97bddf8dec27> in <module>()
----> 1 System.Nullable[System.DateTime]()

TypeError: no constructor matches given arguments

In any case that would give me an actual DateTime, not a Nullable<DateTime> with HasValue = false

If only you HasValue wasn't read only ;)

Anyway, now I understand what is going on I think this is enough of an edge case not to worry about - unless someone out there has a simple fix to pythondotnet to support it.

John

From: PythonDotNet [mailto:pythondotnet-bounces+jgill=***@python.org] On Behalf Of Zane D. Purvis
Sent: Wednesday, February 05, 2014 3:36 PM
To: A list for users and developers of Python for .NET
Subject: Re: [Python.NET] Passing in null as the value for a nullable type.

Try System.Nullable[System.DateTime]()
I haven't tested that, but I think that's what you need.

On Wed, Feb 5, 2014 at 1:25 PM, John Gill <jgill-U6M1/***@public.gmane.org<mailto:jgill-U6M1/***@public.gmane.org>> wrote:
Thanks. At least on my system there is no such thing as System.Null

In c# at least, null is just a keyword in the language.


From: PythonDotNet [mailto:pythondotnet-bounces+jgill<mailto:pythondotnet-bounces%2Bjgill>=tokiomillennium.com-+ZN9ApsXKcEdnm+***@public.gmane.org<mailto:***@python.org>] On Behalf Of Tribble, Brett
Sent: Wednesday, February 05, 2014 1:45 PM
To: A list for users and developers of Python for .NET
Subject: Re: [Python.NET] Passing in null as the value for a nullable type.

I believe you want to import System and pass System.Null. I can't remember if I've done this, but I think so.

From: PythonDotNet [mailto:pythondotnet-bounces+btribble<mailto:pythondotnet-bounces%2Bbtribble>=ea.com-+ZN9ApsXKcEdnm+***@public.gmane.org<mailto:ea.com-+ZN9ApsXKcEdnm+***@public.gmane.org>] On Behalf Of John Gill
Sent: Wednesday, February 05, 2014 8:47 AM
To: pythondotnet-+ZN9ApsXKcEdnm+***@public.gmane.org<mailto:pythondotnet-+ZN9ApsXKcEdnm+***@public.gmane.org>
Subject: [Python.NET] Passing in null as the value for a nullable type.

I am sure there is a really simple answer to this one... but so far it is eluding me.

I have a class something like this:

public class Foo
{
...
public int process_date(DateTime? mydate)
{
...
}
}


I want to call this from python using pythondotnet.


Calling it like this works fine:

mydate = DateTime(0)
Foo().process_date(mydate)

But if I try to pass in a null as the date as follows:

Foo().process_date(None)

I get:

TypeError: No method matches given arguments

Hoping there is something really obvious I am missing here.

John
This communication and any attachments contain information which is confidential and may also be legally privileged. It is for the exclusive use of the intended recipient(s). If you are not the intended recipient(s) please note that any form of disclosure, distribution, copying, printing or use of this communication or the information in it or in any attachments is strictly prohibited and may be unlawful. If you have received this communication in error, please return it with the title "received in error" to ***@tokiomillennium.com<mailto:postmaster-U6M1/***@public.gmane.org> and then permanently delete the email and any attachments from your system.


E-mail communications cannot be guaranteed to be secure or error free, as information could be intercepted, corrupted, amended, lost, destroyed, arrive late or incomplete, or contain viruses. It is the recipient's responsibility to ensure that e-mail transmissions and any attachments are virus free. We do not accept liability for any damages or other consequences caused by information that is intercepted, corrupted, amended, lost, destroyed, arrives late or incomplete or contains viruses.
******************************************
This communication and any attachments contain information which is confidential and may also be legally privileged. It is for the exclusive use of the intended recipient(s). If you are not the intended recipient(s) please note that any form of disclosure, distribution, copying, printing or use of this communication or the information in it or in any attachments is strictly prohibited and may be unlawful. If you have received this communication in error, please return it with the title "received in error" to ***@tokiomillennium.com<mailto:postmaster-U6M1/***@public.gmane.org> and then permanently delete the email and any attachments from your system.


E-mail communications cannot be guaranteed to be secure or error free, as information could be intercepted, corrupted, amended, lost, destroyed, arrive late or incomplete, or contain viruses. It is the recipient's responsibility to ensure that e-mail transmissions and any attachments are virus free. We do not accept liability for any damages or other consequences caused by information that is intercepted, corrupted, amended, lost, destroyed, arrives late or incomplete or contains viruses.
******************************************

_________________________________________________
Python.NET mailing list - PythonDotNet-+ZN9ApsXKcEdnm+***@public.gmane.org<mailto:***@python.org>
https://mail.python.org/mailman/listinfo/pythondotnet


This communication and any attachments contain information which is confidential and may also be legally privileged. It is for the exclusive use of the intended recipient(s). If you are not the intended recipient(s) please note that any form of disclosure, distribution, copying, printing or use of this communication or the information in it or in any attachments is strictly prohibited and may be unlawful. If you have received this communication in error, please return it with the title "received in error" to ***@tokiomillennium.com and then permanently delete the email and any attachments from your system.

E-mail communications cannot be guaranteed to be secure or error free, as information could be intercepted, corrupted, amended, lost, destroyed, arrive late or incomplete, or contain viruses. It is the recipient's responsibility to ensure that e-mail transmissions and any attachments are virus free. We do not accept liability for any damages or other consequences caused by information that is intercepted, corrupted, amended, lost, destroyed, arrives late or incomplete or contains viruses.
******************************************

Brad Friedman
2014-02-05 18:43:27 UTC
Permalink
DateTime is a struct. You have to pass a value. It should not take null. If you tried to do that in c# it would not allow it either.
I am sure there is a really simple answer to this one
 but so far it is eluding me.
public class Foo
{


public int process_date(DateTime? mydate)
{


}
}
I want to call this from python using pythondotnet.
mydate = DateTime(0)
Foo().process_date(mydate)
Foo().process_date(None)
TypeError: No method matches given arguments
Hoping there is something really obvious I am missing here.
John
E-mail communications cannot be guaranteed to be secure or error free, as information could be intercepted, corrupted, amended, lost, destroyed, arrive late or incomplete, or contain viruses. It is the recipient's responsibility to ensure that e-mail transmissions and any attachments are virus free. We do not accept liability for any damages or other consequences caused by information that is intercepted, corrupted, amended, lost, destroyed, arrives late or incomplete or contains viruses.
******************************************
_________________________________________________
https://mail.python.org/mailman/listinfo/pythondotnet
John Gill
2014-02-05 19:59:45 UTC
Permalink
Thanks Brad.

I think I understand what is happening now. Note that the C# code I posted works fine, you can pass in Null as mydate.

DateTime? mydate

Gets translated by the C# compiler to System.Nullable<DateTime> mydate.

When you pass in null to the method C# sets up a Nullable<DateTime> with the HasValue set to False.

As far as I can tell there is no way to create such a thing in pythondotnet. Not sure whether this is a bug or a feature, but certainly explains why it is dazed and confused when I try to pass in None, it isn’t prepared to match the DateTime?.

In this case, I have control of the C# code so I can just overload the method and work around this.

Thanks for helping me understand what is going on.

John

From: PythonDotNet [mailto:pythondotnet-bounces+jgill=***@python.org] On Behalf Of Brad Friedman
Sent: Wednesday, February 05, 2014 2:43 PM
To: A list for users and developers of Python for .NET
Cc: ***@python.org
Subject: Re: [Python.NET] Passing in null as the value for a nullable type.

DateTime is a struct. You have to pass a value. It should not take null. If you tried to do that in c# it would not allow it either.

On Feb 5, 2014, at 11:46 AM, John Gill <***@tokiomillennium.com<mailto:***@tokiomillennium.com>> wrote:
I am sure there is a really simple answer to this one
 but so far it is eluding me.

I have a class something like this:

public class Foo
{


public int process_date(DateTime? mydate)
{


}
}


I want to call this from python using pythondotnet.


Calling it like this works fine:

mydate = DateTime(0)
Foo().process_date(mydate)

But if I try to pass in a null as the date as follows:

Foo().process_date(None)

I get:

TypeError: No method matches given arguments

Hoping there is something really obvious I am missing here.

John
This communication and any attachments contain information which is confidential and may also be legally privileged. It is for the exclusive use of the intended recipient(s). If you are not the intended recipient(s) please note that any form of disclosure, distribution, copying, printing or use of this communication or the information in it or in any attachments is strictly prohibited and may be unlawful. If you have received this communication in error, please return it with the title "received in error" to ***@tokiomillennium.com<mailto:***@tokiomillennium.com> and then permanently delete the email and any attachments from your system.


E-mail communications cannot be guaranteed to be secure or error free, as information could be intercepted, corrupted, amended, lost, destroyed, arrive late or incomplete, or contain viruses. It is the recipient's responsibility to ensure that e-mail transmissions and any attachments are virus free. We do not accept liability for any damages or other consequences caused by information that is intercepted, corrupted, amended, lost, destroyed, arrives late or incomplete or contains viruses.
******************************************
_________________________________________________
Python.NET<http://Python.NET> mailing list - ***@python.org<mailto:***@python.org>
https://mail.python.org/mailman/listinfo/pythondotnet

This communication and any attachments contain information which is confidential and may also be legally privileged. It is for the exclusive use of the intended recipient(s). If you are not the intended recipient(s) please note that any form of disclosure, distribution, copying, printing or use of this communication or the information in it or in any attachments is strictly prohibited and may be unlawful. If you have received this communication in error, please return it with the title "received in error" to ***@tokiomillennium.com and then permanently delete the email and any attachments from your system.

E-mail communications cannot be guaranteed to be secure or error free, as information could be intercepted, corrupted, amended, lost, destroyed, arrive late or incomplete, or contain viruses. It is the recipient's responsibility to ensure that e-mail transmissions and any attachments are virus free. We do not accept liability for any damages or other consequences caused by information that is intercepted, corrupted, amended, lost, destroyed, arrives late or incomplete or contains viruses.
******************************************
Loading...