Skip to content

Conversation

@MrBlenny
Copy link
Contributor

@MrBlenny MrBlenny commented Jul 24, 2025

Currently dataclasses generated in python look like:

class admittance_controller:

    class Params:
        # for detecting if the parameter struct has been updated
        stamp_ = Time()
        ...
        class __Pid:
            rate = 0.005
            class __MapJoints:
                p = 1.0
                i = None
                d = 1.0
            __map_type = __MapJoints
            def add_entry(self, name):
                if not hasattr(self, name):
                    setattr(self, name, self.__map_type())
                return getattr(self, name)
            def get_entry(self, name):
                return getattr(self, name)
        pid = __Pid()

The problem with this is you cannot access the child classes using admittance_controller.Params.__Pid because of the __. This PR changes this so the classes are no longer private.

class admittance_controller:

    class Params:
        # for detecting if the parameter struct has been updated
        stamp_ = Time()
        ...
        class Pid:
            rate = 0.005
            class MapJoints:
                p = 1.0
                i = None
                d = 1.0
            _map_type = MapJoints
            def add_entry(self, name):
                if not hasattr(self, name):
                    setattr(self, name, self.__map_type())
                return getattr(self, name)
            def get_entry(self, name):
                return getattr(self, name)
        pid = Pid()

Given they were private before I don't expect this will cause any backwards compatbility issues.

@MrBlenny MrBlenny changed the title fix: make dataclasss public fix: make nested dataclass public in generated python Jul 24, 2025
Copy link
Collaborator

@christophfroehlich christophfroehlich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need this being public?

@MrBlenny
Copy link
Contributor Author

MrBlenny commented Dec 6, 2025

So children of the Params class can be used as type annotations and passed into functions.

@saikishor
Copy link
Contributor

So children of the Params class can be used as type annotations and passed into functions.

I understand that you would like to use type annotations, but the GPL is not meant for that right?. IMO It is just a way to access the parameters, but not to construct classes

@russkel
Copy link
Contributor

russkel commented Dec 8, 2025

def create_controller(config: Params.Pid) -> PIDController:
  ... do the things

Would seem to be a common use for a sub struct of params in my opinion.

Copy link
Collaborator

@christophfroehlich christophfroehlich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with the changes, but waiting for another approval.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants