[issue33430] Import secrets module in secrets examples
New submission from Daniel Chimeno <daniel@chimeno.me>: In the secrets module documentation, the examples in `15.3.4. Recipes and best practices` need change things, I think this examples must run after a copy & paste into user terminal. Options for first example: 1: ```` import string from secrets import choice alphabet = string.ascii_letters + string.digits password = ''.join(choice(alphabet) for i in range(8)) ```` 2: ``` import string import secrets alphabet = string.ascii_letters + string.digits password = ''.join(secrets.choice(alphabet) for i in range(8)) ```` I've looked in the devguide, but I haven't found what's the standard approach here. First issue here, be nice :) ---------- assignee: docs@python components: Documentation messages: 316200 nosy: dchimeno, docs@python priority: normal severity: normal status: open title: Import secrets module in secrets examples type: enhancement versions: Python 3.7, Python 3.8 _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue33430> _______________________________________
Daniel Chimeno <daniel@chimeno.me> added the comment: Relevant link: https://docs.python.org/3.7/library/secrets.html#recipes-and-best-practices ---------- _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue33430> _______________________________________
Steven D'Aprano <steve+python@pearwood.info> added the comment: I've always expected that documentation for a module can assume that the module itself, and/or the function being described, has been imported. On the other hand, I have no objection to making this explicit, especially in the recipes section where it might not be as clear which functions come from the module and which are builtins. I'm inclined to go for your 2nd option, import the module and use a full-qualified name: password = ''.join(secrets.choice(alphabet) for i in range(8)) ---------- nosy: +steven.daprano _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue33430> _______________________________________
Change by Daniel Chimeno <daniel@chimeno.me>: ---------- keywords: +patch pull_requests: +6397 stage: -> patch review _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue33430> _______________________________________
Steven D'Aprano <steve+python@pearwood.info> added the comment: Unless I've mucked it up, I just committed your patch on Github so I'm closing this ticket. Thanks. ---------- stage: patch review -> resolved status: open -> closed _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue33430> _______________________________________
participants (2)
-
Daniel Chimeno
-
Steven D'Aprano