[issue39759] os.getenv documentation is misleading
New submission from Rémi Lapeyre <remi.lapeyre@henki.fr>: The documentation states that "*key*, *default* and the result are str." at https://github.com/python/cpython/blame/3.8/Doc/library/os.rst#L224 but either I'm missing something or it's not actually true: $ python -c 'import os; print(type(os.getenv("FOO")))' <class 'NoneType'> $ python -c 'import os; print(type(os.getenv("FOO", default=1)))' <class 'int'> Only *key* needs to be a string as it is used to lookup the value in os.environ. I think this can be fixed by a new contributor ---------- assignee: docs@python components: Documentation messages: 362689 nosy: docs@python, remi.lapeyre priority: normal severity: normal status: open title: os.getenv documentation is misleading type: enhancement versions: Python 3.9 _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue39759> _______________________________________
Change by Andrei Daraschenka <dorosch.github.io@yandex.ru>: ---------- keywords: +patch nosy: +dorosch nosy_count: 2.0 -> 3.0 pull_requests: +18024 stage: -> patch review pull_request: https://github.com/python/cpython/pull/18668 _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue39759> _______________________________________
Andrew Svetlov <andrew.svetlov@gmail.com> added the comment: I consider a free type for the default as an implementation detail, not the encouraged approach. Since the value is always a string, using the same type for the default sounds like a sane design for me. ---------- nosy: +asvetlov _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue39759> _______________________________________
Rémi Lapeyre <remi.lapeyre@henki.fr> added the comment: I don't really have a preference regarding saying that `default` should be a string or not but the phrase should still be reworded to be less confusing. In typeshed it's documented with a generic type: https://github.com/python/typeshed/blob/master/stdlib/3/os/__init__.pyi#L363. ---------- _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue39759> _______________________________________
participants (3)
-
Andrei Daraschenka -
Andrew Svetlov -
Rémi Lapeyre