PEP 3102 for review and comment

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • molasses

    #1

    PEP 3102 for review and comment

    I don't mind the naked star and will be happy if thats what we end up with.

    Though how about using *None?
    I think that makes the intention of the function clearer.

    eg.
    def compare(a, b, *None, key=None):

    Which to me reads as "no further positional arguments".

    Or alternatively:
    def compare(a, b, *0, key=None):

    -- Mark
  • gangesmaster

    #2
    Re: PEP 3102 for review and comment

    None is not currently a keyword

    Comment

    • Kay Schluehr

      #3
      Re: PEP 3102 for review and comment


      molasses wrote:[color=blue]
      > I don't mind the naked star and will be happy if thats what we end up with.
      >
      > Though how about using *None?
      > I think that makes the intention of the function clearer.
      >
      > eg.
      > def compare(a, b, *None, key=None):
      >
      > Which to me reads as "no further positional arguments".
      >
      > Or alternatively:
      > def compare(a, b, *0, key=None):
      >
      > -- Mark[/color]

      Argh!

      Sorry, but this syntax seems to me a perlish hackaround. Although the
      star is clearly beautifull and veeeery pythonic ;)
      [color=blue]
      >From the PEP:[/color]
      One can easily envision a function
      which takes a variable number of arguments, but also takes one
      or more 'options' in the form of keyword arguments. Currently,
      the only way to do this is to define both a varargs argument,
      and a 'keywords' argument (**kwargs), and then manually extract
      the desired keywords from the dictionary.

      The current solution is fine and not very troublesome. But if you want
      to drop a named dict just replace it by an unnamed one ( unless you
      think this will seduce people to use devilish, horrible lambda ... ).

      Suggestions:

      def compare(a, b, *args, **kwd): # the classics

      def compare(a, b, *args, {"key":None} ): # pass keywords in unnamed
      dict

      def compare(a, b, *args, {key=None}): # alternative syntax

      def compare(a, b, *args, **kwd={...,"key ":None}): # having the
      cake and eating it

      Regards,
      Kay

      Comment

      Working...