From 2c7bcc81e1de6b6f96618c8bd8cea8c6721e813c Mon Sep 17 00:00:00 2001 From: Eric Traut Date: Fri, 15 Apr 2022 21:42:42 -0700 Subject: [PATCH] Updated library guidance to include a small section on positional-only parameters. --- docs/typed-libraries.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/docs/typed-libraries.md b/docs/typed-libraries.md index 0c845fc62..600bdce66 100644 --- a/docs/typed-libraries.md +++ b/docs/typed-libraries.md @@ -252,6 +252,17 @@ def create_user(age: int, *, dob: Optional[date] = None): ... ``` +### Positional-only Parameters +If a function or method is intended to take parameters that are specified only by position, use the positional-only separator ("/") as documented in [PEP 570](https://peps.python.org/pep-0570/). If your library needs to run on versions of Python prior to 3.8, you can alternatively name the positional-only parameters with an identifier that begins with a double underscore. + +```python +def compare_values(value1: T, value2: T, /) -> bool: + ... + +def compare_values(__value1: T, __value2: T) -> bool: + ... +``` + ### Annotating Decorators Decorators modify the behavior of a class or a function. Providing annotations for decorators is straightforward if the decorator retains the original signature of the decorated function.