Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Finding out if a function in a child class is overriding another function in the base class . #1175

Closed
nicksspirit opened this issue Jul 14, 2018 · 6 comments
Labels

Comments

@nicksspirit
Copy link

nicksspirit commented Jul 14, 2018

Is it possible for Jedi to inspect a method in a class and to determine if that method is overiding the base class's function. So:

class A:
    def ping(self):
        print("pong")


class B(A):
    def ping(self):
        print("overridden")

can Jedi like provide information as to whether the method in Class B is overriding the method in Class A?

@davidhalter
Copy link
Owner

There is currently no such feature. It would be very possible to do that, but it's not implemented, currently. Feel free to do it :)

@nicksspirit
Copy link
Author

Okay, that is good to hear. I am kind of new to this contribution stuff, however i would very much like to work on this feature. So @davidhalter do you have some advice or guidance on how to get started working on Jedi?

@davidhalter
Copy link
Owner

Can you quickly explain your use case? If I understood what you want to do I would probably have a better vision of this feature.

Since this feature is going to be user facing, the first question we have to answer is what the API is going to look like. I can imagine two different ways:

  • As part of goto_assignments it could be possible to just use it as a normal goto function. This has been suggested before and I would be very willing to merge this.
  • Create a new API method on the Definition object. This would probably make it possible to use it way more specifically, but it would also not benefit most Jedi users.

What would you prefer?

For the actual implementation you probably just need to do some name lookups and that's it. It's probably around 20 LOC.

@nicksspirit
Copy link
Author

Sorry for the late reply.

So what I had in mind for the use case was that user would be able to look at the definition of method within a class and then as part of the definition of the method there would be some indication that the method is being overridden because the parent class has the same method defined.

So I guess my description fits into your second suggestion. However now that I think about it an goto_assignments functionality does make sense. Especially when doing a lot of class based programming i.e Django.

I still do think that having some kind of indication or text within the definition object of method of a class would be helpful.

So within the definition of method of a class, the method could have something like foo* to indicate that the method is overriding another method within the parent class or like this
foo <- ParentClass.foo or something like that.

What do you think about what i've said.

@nicksspirit
Copy link
Author

hey @davidhalter you mentioned that this feature has been mentioned before:

This has been suggested before and I would be very willing to merge this

could you point me to the issue this was mentioned?

@davidhalter
Copy link
Owner

davidhalter/jedi-vim#786

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants