[Python-mode] Simplifying - drop decorator special forms

Andreas Röhler andreas.roehler at online.de
Tue Nov 13 07:38:45 EST 2018



On 12.11.2018 22:58, Barry Warsaw wrote:
> On Nov 12, 2018, at 03:15, Andreas Röhler <andreas.roehler at online.de> wrote:
>>
>> as decorators are part of function definitions, consider to drop all special handling. Beginning of def-or-class would reach the decorator - same with mark, copying and send.
> 
> Is it possible to use C-u to choose whether to go to the first decorator or the function definition?

Sure. Probably a defcustom py-include-decorators-p might be useful too.


   Remember, you can have a bunch of function decorators, not just one. 
So going to the first decorator could put you way off from where you expect.
> 
> E.g. if you use click, from Mailman 3:
> 
> @click.command(
>      cls=I18nCommand,
>      context_settings=dict(help_option_names=['-h', '--help']),
>      help=_("""\
>      Master subprocess watcher.
> 
>      Start and watch the configured runners, ensuring that they stay alive and
>      kicking.  Each runner is forked and exec'd in turn, with the master waiting
>      on their process ids.  When it detects a child runner has exited, it may
>      restart it.
> 
>      The runners respond to SIGINT, SIGTERM, SIGUSR1 and SIGHUP.  SIGINT,
>      SIGTERM and SIGUSR1 all cause a runner to exit cleanly.  The master will
>      restart runners that have exited due to a SIGUSR1 or some kind of other
>      exit condition (say because of an uncaught exception).  SIGHUP causes the
>      master and the runners to close their log files, and reopen then upon the
>      next printed message.
> 
>      The master also responds to SIGINT, SIGTERM, SIGUSR1 and SIGHUP, which it
>      simply passes on to the runners.  Note that the master will close and
>      reopen its own log files on receipt of a SIGHUP.  The master also leaves
>      its own process id in the file specified in the configuration file but you
>      normally don't need to use this PID directly."""))
> @click.option(
>      '-C', '--config', 'config_file',
>      envvar='MAILMAN_CONFIG_FILE',
>      type=click.Path(exists=True, dir_okay=False, resolve_path=True),
>      help=_("""\
>      Configuration file to use.  If not given, the environment variable
>      MAILMAN_CONFIG_FILE is consulted and used if set.  If neither are given, a
>      default configuration file is loaded."""))
> @click.option(
>      '--no-restart', '-n', 'restartable',
>      is_flag=True, default=True,
>      help=_("""\
>      Don't restart the runners when they exit because of an error or a SIGUSR1.
>      Use this only for debugging."""))
> @click.option(
>      '--force', '-f',
>      is_flag=True, default=False,
>      help=_("""\
>      If the master watcher finds an existing master lock, it will normally exit
>      with an error message.  With this option,the master will perform an extra
>      level of checking.  If a process matching the host/pid described in the
>      lock file is running, the master will still exit, requiring you to manually
>      clean up the lock.  But if no matching process is found, the master will
>      remove the apparently stale lock and make another attempt to claim the
>      master lock."""))
> @click.option(
>      '--runners', '-r',
>      metavar='runner[:slice:range]',
>      callback=validate_runner_spec, default=None,
>      multiple=True,
>      help=_("""\
>      Override the default set of runners that the master will invoke, which is
>      typically defined in the configuration file.  Multiple -r options may be
>      given.  The values for -r are passed straight through to bin/runner."""))
> @click.option(
>      '-v', '--verbose',
>      is_flag=True, default=False,
>      help=_('Display more debugging information to the log file.'))
> @click.version_option(MAILMAN_VERSION_FULL)
> @public
> def main(config_file, restartable, force, runners, verbose):
>      # ….
> 
> Cheers,
> =Barry
> 

Thanks for the example,

Cheers,
Andreas


More information about the Python-mode mailing list