Unexpected drop down box appears whilst Python3 phat coding


#1

Whilst doing some basic coding for various phat boards to learn about them I have noticed the following:
Say I am typing print (automationhat. its after you press the fullstop…if you pause for a few seconds before typing the rest of the code then a drop down box appears ( like MS visual basic etc) which shows a lot of possible following commands some of which are documented and lots more which are not and if you try to use them errors show at run time. So is this for future development or something else?
Its almost like in the old days of Z80 CPU machine code programming where you found an unsupported op code and tried to find out what it did!


#2

This will be the code auto-completion in the editor. It’s trying to be clever about detecting which methods you might want to call on a specific class/module and listing them so you don’t have to remember the whole API.

It probably doesn’t work too well with Automation HAT, since the way the library structures everything is odd, and not typical of Python.


#3

As a technical point, has this been programmed by the person who wrote the phat drivers, as all the options in the box refer to that bit of hardware? Also I have seen it in in drivers for other phats as well. But if you click on an option in the box, it doesn’t insert it, so its suggesting, as you say, which methods you want to call on. But other than the ones that are listed in documentation, or tutorials, if you try to use them, whatever they may be designed to do, gives Syntax error, as if there is no code written to support them


#4

Those options exist within the drivers, but the IDE is auto-detecting them from the Python library and building that options list for your convenience. It may not always prove to be convenient, however.

In the case of Automation HAT, the library does some weird things that basically mean the options presented in this menu are mostly nonsense.

For example you can use: automationhat.relay.one but you can’t see one in the drop down when you type automationhat.relay because the one object doesn’t exist in a way that the IDE understands.

The one is actually handled on the fly, because when you attempt to access something inside a class in Python (relay is a class instance in this case), Python will call a special function __getattr__ to handle actually finding where this something is.

So when you type automationhat.relay.one you are actually implicitly typing automationhat.relay.__getattr__("one") and calling this method: