Skip to content

Enforce keyword-only parameters, with deprecation #16607

@gagern

Description

@gagern
mannequin

There are functions all over the library which accept various optional named parameters. Often the intention is that these will only be used as keyword parameters, but that fact is not enforced. Maintaining a huge number of possibly positional parameters can become a maintenance pain. (I'm currently seeing a mild version of this in #16533, but things could be much worse.)

PEP 3102 introduced syntax for this for Python 3.

This ticket introduces a decorator which will limit the number of positional parameters passed to its wrapped function.

  1. To faciliate graceful deprecation, it might be associated with a trac ticket number and pass extra positional arguments after issuing a deprecation warning.

  2. After the deprecation period, it would be replaced by proper keyword-only parameters.

Because of the performance penalty of the decorator, this should be done only for non-performance critical functions.

We demonstrate the use of the decorator on this ticket with a number of examples:

  • get_solver - this would catch the typical user error get_solver('GLPK')

  • more TBD.

CC: @nilesjohnson @fchapoton @mwageringel

Component: misc

Author: Martin von Gagern

Branch/Commit: u/gagern/ticket/16607 @ 9755cda

Reviewer: Volker Braun

Issue created by migration from https://trac.sagemath.org/ticket/16607

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions