From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 0CFBF45480; Mon, 17 Jun 2024 13:44:18 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id D9DE7402D7; Mon, 17 Jun 2024 13:44:17 +0200 (CEST) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mails.dpdk.org (Postfix) with ESMTP id AB7384028B for ; Mon, 17 Jun 2024 13:44:10 +0200 (CEST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id BBCDEDA7; Mon, 17 Jun 2024 04:44:34 -0700 (PDT) Received: from [192.168.50.86] (usa-sjc-mx-foss1.foss.arm.com [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 71C353F6A8; Mon, 17 Jun 2024 04:44:09 -0700 (PDT) Message-ID: <7182b9ba-1671-4707-9b2b-dfdb0fcb9995@arm.com> Date: Mon, 17 Jun 2024 12:44:08 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 1/8] dts: add params manipulation module Content-Language: en-GB To: =?UTF-8?Q?Juraj_Linke=C5=A1?= , dev@dpdk.org Cc: Jeremy Spewock , Paul Szczepanek References: <20240326190422.577028-1-luca.vizzarro@arm.com> <20240509112057.1167947-1-luca.vizzarro@arm.com> <20240509112057.1167947-2-luca.vizzarro@arm.com> <19574098-0ee0-4194-b11d-9d9e889fca21@pantheon.tech> From: Luca Vizzarro In-Reply-To: <19574098-0ee0-4194-b11d-9d9e889fca21@pantheon.tech> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org On 06/06/2024 10:19, Juraj Linkeš wrote: > The static method in the other patch is called compose and does > essentially the same thing, right? Can we use the same name (or a > similar one)? > > Also, what is the difference in approaches between the two patches (or, > more accurately, the reason behind the difference)? In the other patch, > we're returning a dict, here we're returning a function directly. They are essentially different. This one is as it's called quite plainly a function reduction. Can be used in any context in reality. The other one is tighter and has some specific controls (exit early if None), and is directly represented as a dictionary as that's the only intended way of consumption. >> +    """Reduces an iterable of :attr:`FnPtr` from end to start to a >> composite function. > > We should make the order of application the same as in the method in > other patch, so if we change the order in the first one, we should do > the same here. While I don't think it feels any natural coding-wise (yet again, a matter of common readability to the developer vs how it's actually run), I won't object as I don't have a preference. >> + >> +    If the iterable is empty, the created function just returns its >> fed value back. >> +    """ >> + >> +    def composite_function(value: Any): > > The return type is missing. I will remove types from the decorator functions as it adds too much complexity and little advantage. I wasn't able to easily resolve with mypy. Especially in conjunction with modify_str, where mypy complains a lot about __str__ being treated as an unbound method/plain function that doesn't take self. >> +    _suffix = "" >> +    """Holder of the plain text value of Params when called directly. >> A suffix for child classes.""" >> + >> +    """========= BEGIN FIELD METADATA MODIFIER FUNCTIONS ========""" >> + >> +    @staticmethod >> +    def value_only() -> ParamsModifier: > > As far as I (or my IDE) can tell, this is not used anywhere. What's the > purpose of this? I guess this is no longer in use at the moment. It could still be used for positional arguments in the future. But will remove for now. >> +    def append_str(self, text: str) -> None: >> +        """Appends a string at the end of the string representation.""" >> +        self._suffix += text >> + >> +    def __iadd__(self, text: str) -> Self: >> +        """Appends a string at the end of the string representation.""" >> +        self.append_str(text) >> +        return self >> + >> +    @classmethod >> +    def from_str(cls, text: str) -> Self: > > I tried to figure out how self._suffix is used and I ended up finding > out this method is not used anywhere. Is that correct? If it's not used, > let's remove it. It is used through Params.from_str. It is used transitionally in the next commits. > What actually should be the suffix? A an arbitrary string that gets > appended to the rendered command line arguments? I guess this would be > here so that we can pass an already rendered string? As we already discussed and agreed before, this is just to use Params plainly with arbitrary text. It is treated as a suffix, because if Params is inherited this stays, and then it can either be a prefix or a suffix in that case. >> +        """Creates a plain Params object from a string.""" >> +        obj = cls() >> +        obj.append_str(text) >> +        return obj >> + >> +    @staticmethod >> +    def _make_switch( >> +        name: str, is_short: bool = False, is_no: bool = False, >> value: str | None = None >> +    ) -> str: >> +        prefix = f"{'-' if is_short else '--'}{'no-' if is_no else ''}" > > Does is_short work with is_no (that is, if both are True)? Do we need to > worry about it if not? They should not work together, and no it is not enforced. But finally that's up to the command line interface we are modelling the parameters against. It is not a problem in reality.