Skip to content

Draft: shell: Completion of prop/attr typed with enums

Valentin Valls requested to merge check-enum-completion into master

This PR is a proposal to simplify the user object edition in the command line.

In BLISS some object property can be defined with a set of defined values. As we know this list, it is convenient to provide them to the user.

This PR use the standard python annotation. Such annotation can be put to the object attributes and the properties. A new completor was designed in the shell To be waked up at the = typing. From the property description, completions can be provided to the users. A dedicated code was designed to expose an names from any Enums. Finally this enum type is added to the locals of the shell.

prop-assign

  • Create a bliss introspection module with annotation helpers
  • Make sure the function param name foo(func_par=) are not completed by this feature -> basically rework part of the code with jedi
  • Make it more robust on the completion detection, like handlng extra spaces.
  • The annotation should be read from the fset, not the fget
  • Extra types could also be implemented like Enum | None or Literal["pipo", "boby"]

The idea was also to be able to drop some custom code from Gilles:

@berruyer implements such feature with a "selector" pattern (an object which have methods to setup it's content). For example object.my_property.set_the_content_to_1. As it's methods, prompt toolkit provides autocompletion. The down side is the selector is that there is an extra step to get the value object.my_property._value. But it features completion with dynamic values.

Dynamic list

A more advanced implementation (to fit @berruyer use case) could be done by property annotation.

This way, we could also supports BLISS object such as axis.

class Foo:
    @property
    def foo(self):
        return self._foo

    @foo.setter
    def foo(self, value):
        self._foo = value

    @completor_values(foo)
    def _foo_values():
        yield "HOME"
        yield self.axis1
        yield self.axis2
        yield roby
Edited by Valentin Valls

Merge request reports

Loading