linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Bartosz Golaszewski <brgl@bgdev.pl>
To: Darrien <darrien@freenet.de>,
	"open list:GPIO SUBSYSTEM" <linux-gpio@vger.kernel.org>
Subject: Re: [libgpiod] python binding decidedly unpythonic
Date: Mon, 16 Sep 2019 10:10:53 +0200	[thread overview]
Message-ID: <CAMRc=MdjzVZOi9YA8WSt6ag8XGkTg+zia3BzpjT4g+t3+oHV1Q@mail.gmail.com> (raw)
In-Reply-To: <CAMRc=Mez=0L8jemxC5r_+1pkT1vmpyZdoTws00ssf0kq_ELDXw@mail.gmail.com>

sob., 14 wrz 2019 o 10:42 Bartosz Golaszewski <brgl@bgdev.pl> napisał(a):
>
> pt., 13 wrz 2019 o 15:05 Darrien <darrien@freenet.de> napisał(a):
> >
> > Hello,
> >
>
> Hi Darrien,
>
> > I just started working with python3-libgpiod and noticed that it is
> > decidedly unpythonic.
> >
>
> I'm not really sure what that means. A quick google search yields many
> answers but not necessarily with regard to what should or should not
> be handled as properties.
>
> > For example the Line object functions active_state, consumer, direction,
> > is_open_drain, is_open_source, is_requested, is_used, name, offset and
> > owner should be properties, and set_value/get_value should be merged
> > into one property.
> >
>
> For the first part: you may be right that it would be somehow "better"
> or more standardized (I didn't really find any official documentation
> that would suggest always using properties when possible - mostly some
> stackoverflow posts), but I decided at the time of writing that when
> in C, methods cause less churn. Also: these methods make the object
> call underlying C code, so I considered it more of "telling the object
> what to do". I may have been wrong - python is not my main language.
>
> As for get/set values: this leads to execution of underlying code that
> can fail, it's definitely not a property but an operation on the
> object conceptually.
>
> > Line.direction should probably also be writable for bidirectional pin use.
> >
>
> Definitely not. Direction can be changed by an external actor or by
> the current process when it runs the request operation. Even as a
> property it should be read-only.
>
> > Regards
> >
> > Darrien
> >
>
> Let's say I'd want to convert the methods you listed to properties:
> this would be a backward incompatible change of the interface. I'd say
> it's the right thing to do if the API was fundamentally broken and
> didn't work but it's not the case. I'd prefer not to force people to
> change their existing code without a very strong reason.
>
> In other words - if ever there'll be a change of API major version to
> 2, I'll be sure to address python bindings as well. For now I believe
> we should leave it like it is.
>
> Best regards,
> Bartosz Golaszewski

We discussed the python bindings off list with Darrien and he
convinced me that it's worth improving them and doing it earlier will
impact less people. At the same time I don't want to break the
existing, already released interface. The plan is to implement a new
module with the API that is more 'pythonic' and converting the current
gpiod module into a compatibility layer that will be deprecated over
time and eventually removed. This isn't however going to happen very
soon as I'm busy with other things ATM and also I'd really like to get
this right this time.

Bart

  reply	other threads:[~2019-09-16  8:11 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-13 12:57 [libgpiod] python binding decidedly unpythonic Darrien
2019-09-14  8:42 ` Bartosz Golaszewski
2019-09-16  8:10   ` Bartosz Golaszewski [this message]
2019-09-13 15:37 Darrien

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAMRc=MdjzVZOi9YA8WSt6ag8XGkTg+zia3BzpjT4g+t3+oHV1Q@mail.gmail.com' \
    --to=brgl@bgdev.pl \
    --cc=darrien@freenet.de \
    --cc=linux-gpio@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).