kdev-python: Argument type guessing, advanced list content type support and more

It has been a while since my last post about kdev-python, the python language support plugin for KDevelop; I have been quite busy recently. Neverthereless, I got quite a few cool features (almost) finished now.

First, there’s support for argument type guessing. So whenever you call a function, KDevelop will try to find out the type of the parameters you passed, and add them to the possible types for that parameter. Look at the screenshot: the constructor of the “Material” class is called with a string as parameter (in the “currentMaterial = Material(name)” line). Thus, the “name” argument of the constructor is probably a string, and the “Material.name” attribute thus is, too. This also works for stuff like return types, and everything:

Especially for editing functions which are already being used in your code, you also get cool autocompletion this way:

Another feature I’ve implemented is better support for list content type tracking. Look at this:

“materials” is being initialized as an empty list. Then, somewhere something is appended to the list with the “append” function. This function is marked as altering the type of the list in the documentation file of kdev-python; thus, the type of its argument gets added to the type of the list. This behaviour is controlled by decorators (in the internal documentation code) and is thus very flexible; it will be easy to get other libraries’ container classes to work with this as well.

There’s a few more, not as huge features. For example, generators are supported now as follows:

I also fixed quite a few bugs.

You can get the code of the plugin by checking out the “alpha3” tag of the git://anongit.kde.org/kdev-python repository. I hope it doesn’t have nasty crash bugs, if it has, I’ll correct them in subsequent “alpha3.x” tags, so if any of those appear, please use them.

If you have any suggestions or problems, feel free to mail me or report a bug at bugs.kde.org.

Oh, and by the way: If the plugin seems slow, it currently spends more than 95% of its time for writing debug output to the console. You can disable that by typing “kdebugdialog” into a shell, then searching for “python”  and disable both (9011 and 15000) debug areas which are found.

Categories: Everything

Tags: , ,

21 replies

  1. Great work! Cannot wait for this to make it into kdevelop trunk!

  2. afiestas felt the need of learning more python thanks to this πŸ˜€

  3. That looks awesome! Can I use this for production yet?

  4. @Owl well, I guess you could if you don't mind a few glitches. It's not like it would crash with every line you type or so, usually it's fairly stable.
    However, you want a backup solution if something breaks — and I don't take any responsiblity, especially for fixing grave bugs quickly or so. πŸ™‚

  5. That looks really great! This kind of features is what I was looking for πŸ™‚

  6. pretty amazing what types you can get correctly! You are ahead of what Php supports πŸ˜€

    How does it work with "real" code (like a project consisting of many files)?

  7. Performance-wise, okay I think.
    From types and stuff heavily depends on the project. In some projects it's very good (django seems to work quite well, for example), others do wicked stuff which cannot possibly be read correctly. This especially applies to the python standard library, but you usually don't want to edit that.

  8. Hi,

    thank you for the great plugin.
    Is there a way to debug python code from inside kdevelop. Or in other words, is there integration of the python debugger into kdevelop?

  9. I started implementing support for the python debugger, there's even a branch in the repository, but it doesn't do much yet (you can just step forward through your code, and you can't look at variable values or so). Shouldn't be very difficult to finish, but it needs to be done and I didn't yet have the time for that. So if you want to work on that, you're welcome πŸ™‚

  10. Thanks for the quick answer. I am not good with C++ but lets see.

  11. Well, basically its a copy of the xdebug plugin, with every occurence of "xdebug" replaced by "python -m pdb". The only difficult thing may be reading variables, implementing the other commands should be very straightforward (as the code is already there, it just needs to be adapted from xdebug to pdb). In case you want to have a look at it, git://projects.kde.org/kdev-python, then check out the "debugger" branch. You want to merge "master" into that branch then, too, probably.
    My network is a bit broken atm, I'll push the branch soon (just noticed it's not online yet)

  12. Hi, I can not see a remote debugging branch. What is its name?

  13. Hi,

    I'm sorry, seems like I forgot to push it. Look again.

    Cheers

  14. Have it.
    Thanks

  15. hello, first of all – thanks for your great work :).

    i have git version of kdevelop and your plugin & kdevelop crashes when i write

    {}

    first and then try to write content into it

    { foo : bar }.

    when i write it in a continuous shot { foo …, it's ok. it also works when i first write {}, than expand it to { : bar}, or {:} and then to {foo:}. so the problem is when identifier is typed first into blank {}.

  16. Hi,

    you might want to report that as a bug on bugs.kde.org. I'll look into it, thanks for the report.

  17. This is fixed in commit b7dd6d1. The reason for the crash was that {a} is a new syntax introduced in python2.7 which was not known to the plugin so far, so it asserted.

  18. it’s pretty harsh for an IDE plugin to crash in order to punish you for syntax errors πŸ˜‰

  19. Cool stuff πŸ™‚

    Can you do refactoring yet?

  20. Barely. You can just rename everything, that's about all.
    It's also not my main focus for the next time, there's quite a few things on the to-do-list before that πŸ™‚

  21. Thank you so much for doing this!

Leave a Reply

Your email address will not be published. Required fields are marked *