[Home] [Downloads] [Search] [Help/forum]

Gammon Forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Bug reports
. . -> [Subject]  GetChatList() in python returns wrong type.
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

GetChatList() in python returns wrong type.

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page


Pages: 1 2  

Posted by Mr.lundmark   (46 posts)  [Biography] bio
Date Sun 24 Oct 2010 09:45 AM (UTC)
Message
If no connection available,
chatList = world.GetChatList()

returns wrong type:
Execution of line 1 column 0
Immediate execution
Traceback (most recent call last):
File "<Script Block 6>", line 1, in <module>
chatList = world.GetChatList()
TypeError: 'NoneType' object is not callable

NoneType isn't correct, it should be "None".
[Go to top] top

Posted by Worstje   Netherlands  (899 posts)  [Biography] bio
Date Reply #1 on Sun 24 Oct 2010 12:13 PM (UTC)
Message
This might very well be another quirk in the Python <-> WSH bindings.

Are there any other functions in MUSHclient that ought to return 'None' at a certain point, and actually do that right?
[Go to top] top

Posted by Mr.lundmark   (46 posts)  [Biography] bio
Date Reply #2 on Sun 24 Oct 2010 03:06 PM (UTC)
Message
I haven't tried that much tbh, but it seems wrong to return a type that python can't handle at all. There should be functions that returns nil or none, I'll try to see if I can find any.
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #3 on Sun 24 Oct 2010 07:47 PM (UTC)

Amended on Sun 24 Oct 2010 07:48 PM (UTC) by Nick Gammon

Message
There are quite a few functions that have that sort of code. For example:


VARIANT CMUSHclientDoc::AcceleratorList() 
{
  COleSafeArray sa;   // for wildcard list

  long iCount = m_AcceleratorToCommandMap.size ();

  if (iCount) // cannot create empty array dimension
    {
    sa.CreateOneDim (VT_VARIANT, iCount);
  
    // add accelerators here

    } // end of having at least one

  return sa.Detach ();
}   // end of CMUSHclientDoc::AcceleratorList


This is used fairly extensively and doesn't seem to cause problems in VBscript. So it seems that Python is mapping a COleSafeArray with no elements to some unknown type. However the test is there because you can't create a zero-length array.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Worstje   Netherlands  (899 posts)  [Biography] bio
Date Reply #4 on Mon 25 Oct 2010 03:36 AM (UTC)
Message
Does WSH support explicitly adding a NULL parameter, or something along those lines?

Maybe the fact you do not add any value is the reason Python interprets the return value as 'having no type', rather than 'a value'. VBScript might not have such a distinction, and thus map both to the same thing.
[Go to top] top

Posted by Twisol   USA  (2,257 posts)  [Biography] bio
Date Reply #5 on Mon 25 Oct 2010 03:57 AM (UTC)
Message
COM VARIANT types default to VT_EMPTY, and the VARIANT inside COleSafeArray is no exception. If you don't dimension the array before you detach it, it seems likely that Detach() would return VT_EMPTY, rather than VT_NULL.

I don't know which one is what we want, but maybe that will help.

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #6 on Mon 25 Oct 2010 04:47 AM (UTC)
Message
According to the docs for COleSafeArray:


All of these constructors create new COleSafeArray objects. If there is no parameter, an empty COleSafeArray object is created (VT_EMPTY).


I don't see why I can't return an empty variant, as that is a well-defined variant type. It would be different if the variant type was some undefined random value, but VT_EMPTY is a documented value, and can be tested in VBscript.


- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #7 on Mon 25 Oct 2010 04:55 AM (UTC)
Message
Doing a Google for "TypeError: 'NoneType' object is not callable" seems to return quite a few results, nothing to do with MUSHclient.

My guess is that the empty variant returned by the call cannot be assigned to another variable (because it is empty?) and thus the error. If there was a way of testing for NoneType that might help.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Twisol   USA  (2,257 posts)  [Biography] bio
Date Reply #8 on Mon 25 Oct 2010 04:58 AM (UTC)
Message
I would guess that it depends solely on the script engine in question, and how it implements its WSH interface. WSH defines a language-agnostic API for users, but the engine implementors have to bind it to the specific scripting engine. If they do something wrong - like not handle VT_EMPTY values properly - it'll reflect in the engine's behavior.

Does VT_NULL work as expected?

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
[Go to top] top

Posted by Twisol   USA  (2,257 posts)  [Biography] bio
Date Reply #9 on Mon 25 Oct 2010 05:03 AM (UTC)

Amended on Mon 25 Oct 2010 05:06 AM (UTC) by Twisol

Message
I did some searching of my own, and it looks like NoneType is just the type that None is a [pseudo-]instance of. This is similar to Ruby, which has true, false, and nil, all instances of TrueClass, FalseClass, and NilClass respectively.

I expect that the error really isn't anything out of the ordinary, especially because if I run 'python' from the command line and type "None()", I get "TypeError: 'NoneType' object is not callable". In other words, world.GetChatList() is in fact returning None, and everything is as it should be.

[EDIT]: stupidly used "Null" when I meant "None". Fixed.

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
[Go to top] top

Posted by Worstje   Netherlands  (899 posts)  [Biography] bio
Date Reply #10 on Mon 25 Oct 2010 05:41 AM (UTC)
Message
Look at the error and the line only, I get a totally different impression, but of course it all depends on the exact line in the WSH bindings where the error occurs.

My instinctive way to read the TypeError: 'NoneType' object is not callable error is that Python looks up the world object for a GetChatList attribute, is not able to find it and it returns NoneType instead of throwing an AttributeError as Python ought to do when trying to access attributes that do not exist. Then, due to the (), it tries to _call_ said NoneType, which gives the error you see.

Alternatively, the error is indeed in decoding the result from the GetChatList() call in the WSH bindings, meaning it does get executed but gives a really weird and cryptic error.

Can you try

world.Note(repr(world.GetChatList))   # Note, not calling the function.


and show the result?
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #11 on Mon 25 Oct 2010 05:56 AM (UTC)
Message
Well, I'm confused. I set up a chat session so the call *would* return an array, and then did:


/chatList = world.GetChatList()


and got:


Script error
World: SmaugFUSS
Execution of line 1 column 0
Immediate execution
Traceback (most recent call last):
  File "<Script Block 8>", line 1, in <module>
    chatList = world.GetChatList()
TypeError: 'tuple' object is not callable

Line in error: 
chatList = world.GetChatList()



Well what is this: "'tuple' object is not callable"?

Who is calling it?

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Twisol   USA  (2,257 posts)  [Biography] bio
Date Reply #12 on Mon 25 Oct 2010 06:15 AM (UTC)

Amended on Mon 25 Oct 2010 06:16 AM (UTC) by Twisol

Message
Worstje said:
My instinctive way to read the TypeError: 'NoneType' object is not callable error is that Python looks up the world object for a GetChatList attribute, is not able to find it and it returns NoneType instead of throwing an AttributeError as Python ought to do when trying to access attributes that do not exist.

I'm pretty sure the method -does- exist, because it's on the world object, whether it's connected or not. I'm pretty sure that's guaranteed by the IDL that defines the world object's bound methods and attributes.

When it's called, it returns None. Calling a None value gives the error described. I can replicate this in non-WSH python: I have Python installed on my Ubuntu partition and doing this from the REPL has the same effect.

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
[Go to top] top

Posted by Worstje   Netherlands  (899 posts)  [Biography] bio
Date Reply #13 on Mon 25 Oct 2010 03:50 PM (UTC)
Message
You're probably right, I must be overanalyzing the error message.

Either way, that _does_ remind me of something else which is likely at the very root of this issue.

Try leaving the () off, which basically signify a callable. Some functions like Connect that lack parameters have never needed the () in Python, whereas the moment they were needed, you had to put them in.

Basically, rather than calling the function when you treat it as a callable, it calls it when you try to access the attribute, which is very unpythonic and has disgusted me pretty much always. Only good part is that you pretty much never run into functions without parameters when dealing with scripting in MUSHclient, so you tend not to notice it. But the few times it is an issue, it is ugly.

So... try:

chatList = world.GetChatList


Probably that is the quirk the WSH bindings are pushing on us. In anything actually Python, that would be a totally wrong syntax. :/

(How much a good night worth of sleep can help when analyzing this stuff, heh.)
[Go to top] top

Posted by Twisol   USA  (2,257 posts)  [Biography] bio
Date Reply #14 on Mon 25 Oct 2010 07:58 PM (UTC)
Message
Actually, you're probably spot on. Somehow I managed to miss that my explanation of the issue would involve two calls, when there's only one set of ()'s. It would also explain Nick's problem with calling a tuple.

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
[Go to top] top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


11,240 views.

This is page 1, subject is 2 pages long: 1 2  [Next page]

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at FutureQuest]