0

I am trying to get fully qualified name from a property.

Example class

class Foo:
    def __init__(self, val: int):
       self._val = val

    @property
    def myval(self) -> int:
        return self._val

I am attempting to get full qualified name of different objects. I am aiming to get a result like ooolib.foo.Foo.myval (module, class, attribute).

The idea is that I want to create a script that can do someting like the following.

>>> from ooolib.helper import hlp
>>> from ooolib.foo import Foo
>>>
>>> hlp(Foo.myval)
Launching help for "ooolib.foo.Foo.myval" at "https://ooolib.help.example.com/src/ooolib/foo/Foo#myval"

I have a backend that contains all the fully qualified names and their respective help page links. I want to make it simple for user to look up help in a python interactive console.

My goal it to have users be able to get help for any part of the Library by typing the actual objects. In the interactive console tab complete is enabled so it makes sense to me to do it this way.

>>> hlp(ooolib.bar.Bar.mymethod)
>>> hlp(ooolib.bar.Bar.some_property)
>>> hlp(ooolib.bar.Bar.some_attr)
>>> hlp(ooolib.foo.Foo.__init__)
>>> hlp(ooolib.foo)

Is this possible of just a lofty goal on my part?

Amour Spirit
  • 125
  • 7
  • A `property` object as created by the decorator does not know the class it is added to (except while it is accessed where it gets an instance of the class as argument). So already going from the property to its containing class doesn't work. – Michael Butscher Jul 10 '23 at 21:55
  • When you use a property as an expression, it returns the value being accessed. There's no way for a function like `help()` to know what expression was given to it. – Barmar Jul 10 '23 at 23:51
  • You don't pass a property into the function. You pass the object returned by that property, which is an `int`, it has no knowledge that it comes from some property – juanpa.arrivillaga Jul 11 '23 at 00:16
  • Actually the property passed is property object `assert type(obj) is property`. Because `Foo` is not an instance. However I still can't see how I could use it. – Amour Spirit Jul 11 '23 at 16:11
  • I ended up creating a command line tool that reads from a database. This is done by automatic conversion for Sphinx objects.inv files in to a database using [python-sphinx-cli-help](https://github.com/Amourspirit/python-sphinx-cli-help) template. – Amour Spirit Aug 18 '23 at 21:10

0 Answers0