8000 os.getenv documentation is misleading · Issue #83940 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

os.getenv documentation is misleading #83940

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
remilapeyre mannequin opened this issue Feb 26, 2020 · 4 comments
Closed

os.getenv documentation is misleading #83940

remilapeyre mannequin opened this issue Feb 26, 2020 · 4 comments
Labels
3.9 only security fixes docs Documentation in the Doc dir type-feature A feature request or enhancement

Comments

@remilapeyre
Copy link
Mannequin
remilapeyre mannequin commented Feb 26, 2020
BPO 39759
Nosy @asvetlov, @serhiy-storchaka, @sir-sigurd, @remilapeyre, @dorosch
PRs
  • bpo-39759: fixed os.getenv docs #18668
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = None
    created_at = <Date 2020-02-26.11:44:26.910>
    labels = ['type-feature', '3.9', 'docs']
    title = 'os.getenv documentation is misleading'
    updated_at = <Date 2021-07-02.21:03:40.470>
    user = 'https://github.com/remilapeyre'

    bugs.python.org fields:

    activity = <Date 2021-07-02.21:03:40.470>
    actor = 'serhiy.storchaka'
    assignee = 'docs@python'
    closed = False
    closed_date = None
    closer = None
    components = ['Documentation']
    creation = <Date 2020-02-26.11:44:26.910>
    creator = 'remi.lapeyre'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 39759
    keywords = ['patch']
    message_count = 4.0
    messages = ['362689', '362694', '362697', '396879']
    nosy_count = 6.0
    nosy_names = ['asvetlov', 'docs@python', 'serhiy.storchaka', 'sir-sigurd', 'remi.lapeyre', 'dorosch']
    pr_nums = ['18668']
    priority = 'normal'
    resolution = None
    stage = 'patch review'
    status = 'open'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue39759'
    versions = ['Python 3.9']

    @remilapeyre
    Copy link
    Mannequin Author
    remilapeyre mannequin commented Feb 26, 2020

    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

    @remilapeyre remilapeyre mannequin added the 3.9 only security fixes label Feb 26, 2020
    @remilapeyre remilapeyre mannequin assigned docspython Feb 26, 2020
    @remilapeyre remilapeyre mannequin added docs Documentation in the Doc dir type-feature A feature request or enhancement labels Feb 26, 2020
    @asvetlov
    Copy link
    Contributor

    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.

    @remilapeyre
    Copy link
    Mannequin Author
    remilapeyre mannequin commented Feb 26, 2020

    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.

    @serhiy-storchaka
    Copy link
    Member

    It is not so uncommon to write:

        foo_rate = float(os.getenv("FOO_RATE", default_foo_rate))

    where default_foo_rate is float.

    In any case the default value for the default parameter is not a string.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    miss-islington pushed a commit to miss-islington/cpython that referenced this issue Oct 10, 2022
    …-98113)
    
    (cherry picked from commit 187e853)
    
    Co-authored-by: Stanley <46876382+slateny@users.noreply.github.com>
    miss-islington pushed a commit to miss-islington/cpython that referenced this issue Oct 10, 2022
    …-98113)
    
    (cherry picked from commit 187e853)
    
    Co-authored-by: Stanley <46876382+slateny@users.noreply.github.com>
    miss-islington added a commit that referenced this issue Oct 10, 2022
    (cherry picked from commit 187e853)
    
    Co-authored-by: Stanley <46876382+slateny@users.noreply.github.com>
    miss-islington added a commit that referenced this issue Oct 10, 2022
    (cherry picked from commit 187e853)
    
    Co-authored-by: Stanley <46876382+slateny@users.noreply.github.com>
    @slateny slateny closed this as completed Oct 10, 2022
    pablogsal pushed a commit that referenced this issue Oct 22, 2022
    (cherry picked from commit 187e853)
    
    Co-authored-by: Stanley <46876382+slateny@users.noreply.github.com>
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.9 only security fixes docs Documentation in the Doc dir type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants
    0