attributes completion

Request Features and Feature Changes

attributes completion

Postby vds2212 » Sun Mar 01, 2009 9:46 am

I should first say that I'm impressed by the code completion code of Editra for me it is nearly perfect :-)

But I think attribute completion could be improved. Attribute completion works fine for attributes set outside of a method definition.

When an attribute is set outside of a method definition, Editra add the attribute to the list of possible completion of instance of the class. Even in a method definition the 'self' instance completion list contains the attributes set outside of the method definition.

Code: Select all
class A:
    pass

a = A()
a.name

a.<Editra propose name>

b = a
b.<Editra propose name>


But when the attribute are set inside a method definition the attribute is not added to the list of possible completion

Code: Select all
class A:
    def __init__(self, name):
        self.name = name

    def hello(self):
        print "Hello, I'm %s" % self.<Editra do not propose name>

a = A()
a.<Editra do not propose name>


I suspect code completion to be tricky and maybe this is by design or it is very difficult to fix but I noticed it and want it to share with you.

Thanks again for Editra :-)

Vivian.
vds2212
User
 
Posts: 29
Joined: Mon Nov 17, 2008 2:44 pm

Re: attributes completion

Postby cody » Sun Mar 01, 2009 5:32 pm

Hello,

Yes I am aware of this issue. Sometimes it does work other times it does not. It is quite a difficult task to properly fix this though as the attributes a can be defined at any point in the code and dynamically changed. Its also nearly impossible to tell what type of object an attribute is.

I have been contemplating changing whether to try to write a new completer from scratch again or to try and fix the current one, but either way it is on my todo list.


cody
User avatar
cody
Site Admin
 
Posts: 1315
Joined: Mon Oct 09, 2006 2:49 am
Location: United States

Re: attributes completion

Postby bibile » Wed Mar 04, 2009 10:13 pm

Hello,

Thank you for a great editor!!
I think that my request is similar to that topic.

Code: Select all
class A:
    def __init__(self, name):
        self.name = name

    def hello(self):
        self.<Editra do not propose name>


Code: Select all
def fff(val):
    var1 = val
    va<Editra do not propose var1>


So, basically, the completion of Class and function's variables.
I use another editor for another language, and it does it. It's really convienient. and makes coding really fast and smooth.

Thank you for Editra !
bibile
Limited User
 
Posts: 3
Joined: Wed Mar 04, 2009 2:30 pm

Re: attributes completion

Postby cody » Wed Mar 04, 2009 10:51 pm

To try and get word completions like you are asking for (mid word) you need to hit Ctrl+Space key and if the completer can find options to suggest they will be shown.

Let me know if that works for you.

Cody
User avatar
cody
Site Admin
 
Posts: 1315
Joined: Mon Oct 09, 2006 2:49 am
Location: United States

Re: attributes completion

Postby bibile » Wed Mar 04, 2009 10:56 pm

Ctrl+Space, perfect !

For the other part of the request (get completion for self.xxx in a class), actually, I understood that it works, but only for methods.
Is there a way to make it works for Class' properties ?

Thank you !
bibile
Limited User
 
Posts: 3
Joined: Wed Mar 04, 2009 2:30 pm

Re: attributes completion

Postby cody » Thu Mar 05, 2009 3:05 am

As mentioned in my original reply to this thread. There is support for it but its not very reliable yet. Sometimes it will work and sometimes it will not. This is because it is very difficult to determine class attributes in Python due to the dynamic nature of the language.

It should be able to reliably provide completions for properties though as they are defined objects in a class and easier to find.

Code: Select all
class myClass:
    def __init__(self):
        # Attributes
        self.a1 = 0
        self.a2 = 'a'

    @property
    def myProperty(self):
        return "HELLO"

    def someFun(self):
         self.<may or may not be able to show 'a1', 'a2' but should almost always be able to show 'myProperty'>




Cody
User avatar
cody
Site Admin
 
Posts: 1315
Joined: Mon Oct 09, 2006 2:49 am
Location: United States

Re: attributes completion

Postby bibile » Thu Mar 05, 2009 6:59 am

ok, I did not get it at first.
I could get the methods, but never the properties. not yet.
I will wait for next upgrades :)
bibile
Limited User
 
Posts: 3
Joined: Wed Mar 04, 2009 2:30 pm

Re: attributes completion

Postby mojo2012 » Sun Jun 26, 2011 11:16 am

Did you ever think of using some kind of more complex annotations to declare public methods, properties, fields and return types?

This could look like this:

@property: randomNumber as int
@property: description as string
@function: test as None
@function: test2 as string
class Test(object):
def __init__(self):
randomNumber = 2
description = "test test test"

def test(self):
pass

@a as string
def test2(self, a)
return "text"

The advantage would be that not only statically added functions and properties but also their return and argument types could be easily indexed and provided by code completion. So you easily know what to pass to "a" in function "test2". At least python 3 has native support for annotation but it's also possible to support that in python 2.x if the @annotations are packed into a comment, eg #@property instead of @property.

This kind of service could outbeat any other code completion service in any other python ide I know of so far. It would make programming python really easy.

Hope to see this implemented in PyStudio in the near future ;-)
mojo2012
Limited User
 
Posts: 2
Joined: Fri Jun 24, 2011 9:24 pm

Re: attributes completion

Postby mcarans » Mon Jun 27, 2011 10:18 am

Sorry about the delay to your post appearing but the forum has been hacked a number of times lately, so Cody has had to introduce more security which slows things down. Don't blame Cody - blame the people who keep hacking the forum and posting advertisements.

Regarding the attributes completion, this would be a nice addition to PyStudio. It can go on to the TODO list, but remember there are just two of us doing this in our spare time. Volunteers to add features like this would be gratefully accepted.
mcarans
User
 
Posts: 38
Joined: Wed Oct 13, 2010 8:03 am

Re: attributes completion

Postby cody » Sun Jul 03, 2011 5:16 pm

Hi,

Just to be clear the site has not been hacked. Just had been getting abused by a large number of automated bots registering and posting spam. I have tweaked a number anti spam measures and they seem to be working as the bots have dropped off to zero over the last week so the posting moderation has been turned off for the time being.

Cody
User avatar
cody
Site Admin
 
Posts: 1315
Joined: Mon Oct 09, 2006 2:49 am
Location: United States


Return to Feature Requests

Who is online

Users browsing this forum: No registered users and 1 guest

cron