unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: "W. Trevor King" <wking@tremily.us>
To: David Bremner <david@tethera.net>
Cc: notmuch@notmuchmail.org
Subject: Re: [PATCH v2 2/4] nmbug-status: Add meta.message-url config setting
Date: Wed, 23 Mar 2016 09:42:49 -0700	[thread overview]
Message-ID: <20160323164249.GX10674@odin.tremily.us> (raw)
In-Reply-To: <87zitpjvax.fsf@zancas.localnet>

[-- Attachment #1: Type: text/plain, Size: 2525 bytes --]

On Wed, Mar 23, 2016 at 08:19:34AM -0300, David Bremner wrote:
> W. Trevor King writes:
> >  from __future__ import print_function
> > @@ -232,6 +232,10 @@ class Page (object):
> >  class HtmlPage (Page):
> >      _slug_regexp = re.compile('\W+')
> >
> > +    def __init__(self, message_url_template, **kwargs):
> > +        self.message_url_template = message_url_template
> > +        super(HtmlPage, self).__init__(**kwargs)
> > +
>
> > @@ -395,6 +400,8 @@ _PAGES['text'] = Page()
> >  _PAGES['html'] = HtmlPage(
> >      header=header_template.format(**context),
> >      footer=footer_template.format(**context),
> > +    message_url_template=config['meta'].get(
> > +        'message-url', 'http://mid.gmane.org/{message-id}'),
> >      )
> >
>
> Maybe I'm missing some python knowledged, but it looks the
> constructor is defined to take a regular argument for
> message_url_template, but only passed in as a keyword. Does this
> really work?

Yup.  From [1]:

  positional-only: specifies an argument that can be supplied only by
    position. Python has no syntax for defining positional-only
    parameters. However, some built-in functions have positional-only
    parameters (e.g. abs()).

I can't find a similar Python 3 glossary, but see [2].  Whether we use:

  def __init__(self, message_url_template, **kwargs):
      …

or:

  def __init__(self, message_url_template='foobar', **kwargs):
      …

just controls whether the message_url_template has a default or not,
and not whether it can be set via positional or keyword arguments.

There is Python syntax for keyword-only arguments, and it would look
like [2]:

  def __init__(self, *, message_url_template, **kwargs):
      …

or:

  def __init__(self, *, message_url_template='foobar', **kwargs):
      …

in the former case, you'd have to call __init__ with a
message_url_template=… keyword argument or you'd get:

  TypeError: __init__() missing 1 required keyword-only argument: 'message_url_template'

With the latter case, calling __init__ without a message_url_template
argument would just get you the default value (‘foobar’ in these
examples).

Cheers,
Trevor

[1]: https://docs.python.org/2/glossary.html#term-parameter
[2]: https://docs.python.org/3/reference/compound_stmts.html#function-definitions

-- 
This email may be signed or encrypted with GnuPG (http://www.gnupg.org).
For more information, see http://en.wikipedia.org/wiki/Pretty_Good_Privacy

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

  reply	other threads:[~2016-03-23 16:51 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-02  6:07 [PATCH v2 0/4] nmbug-status: meta.message-url and query parens W. Trevor King
2016-01-02  6:07 ` [PATCH v2 1/4] NEWS: Remove trailing comma from an old nmbug-status config W. Trevor King
2016-01-07 13:27   ` David Bremner
2016-01-02  6:07 ` [PATCH v2 2/4] nmbug-status: Add meta.message-url config setting W. Trevor King
2016-03-23 11:19   ` David Bremner
2016-03-23 16:42     ` W. Trevor King [this message]
2016-01-02  6:07 ` [PATCH v2 3/4] nmbug-status: Wrap query phrases in parentheses when and-ing together W. Trevor King
2016-01-02  6:07 ` [PATCH v2 4/4] status-config.json: Remove parens from query entry W. Trevor King
2016-03-24 10:53   ` David Bremner

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

  List information: https://notmuchmail.org/

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

  git send-email \
    --in-reply-to=20160323164249.GX10674@odin.tremily.us \
    --to=wking@tremily.us \
    --cc=david@tethera.net \
    --cc=notmuch@notmuchmail.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.
Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

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 read-only IMAP folder(s) and NNTP newsgroup(s).