GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Float documentation doesn't allow int-like strings as valid arguments for float · Issue #100428 · python/cpython

Float documentation doesn't allow int-like strings as valid arguments for float #100428

New issue
Copy link
New issue
Copy link
Closed
Closed
Float documentation doesn't allow int-like strings as valid arguments for float#100428
Copy link
Labels
docsDocumentation in the Doc dirDocumentation in the Doc dir

Description

@stevendaprano
stevendaprano
opened on Dec 22, 2022
Issue body actions

The documentation for float doesn't explicitly allow int-like strings, although it does give one as an example. E.g. although float('10') works and returns a float, the documentation implies that it shouldn't.

See discussion on Discuss.

Linked PRs

  • gh-100428: Make int documentation more accurate #100436
  • gh-100428: Make float documentation more accurate #100437
  • [3.10] gh-100428: Make float documentation more accurate (GH-100437) #100510
  • [3.11] gh-100428: Make float documentation more accurate (GH-100437) #100511
  • [3.11] gh-100428: Make int documentation more accurate (GH-100436) #100674
  • [3.10] gh-100428: Make int documentation more accurate (GH-100436) #100675

Activity

  1. stevendaprano
    added
    docsDocumentation in the Doc dirDocumentation in the Doc dir
    on Dec 22, 2022
  2. mdickinson commented on Dec 22, 2022

    @mdickinson
    mdickinson
    on Dec 22, 2022
    Member
    More actions

    Maybe remove the indirection (the reference to floating-point literals) from the current documentation and give a direct description of what's permitted instead? That way the information is all in one place. The current documentation feels as though it was a shortcut taken for ease of documentation writing rather than ease of documentation reading.

    On the other hand, it's definitely useful for users to know that any string that's acceptable as a floating-point literal is also acceptable as a string argument to float.

  3. mdickinson commented on Dec 22, 2022

    @mdickinson
    mdickinson
    on Dec 22, 2022
    Member
    More actions

    Another way in which the indirection is inaccurate is that float accepts arbitrary Unicode digits, while literals may only use ASCII digits:

    >>> s = '666.0'
    >>> float(s)
    666.0
    >>> eval(s)
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "<string>", line 1
        666.0
        ^
    SyntaxError: invalid character '6' (U+FF16)
  4. hauntsaninja commented on Dec 22, 2022

    @hauntsaninja
    hauntsaninja
    on Dec 22, 2022
    Contributor
    More actions

    There are inaccuracies in the int documentation too, for instance, the handling of leading zeros isn't really described. Also the following isn't correct:

    Base 0 means to interpret exactly as a code literal

    >>> s = "२३४५६७८९"
    >>> int(s, 0)
    23456789
    >>> eval(s)
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "<string>", line 1
        २३४५६७८९
        ^
    SyntaxError: invalid character '२' (U+0968)
    
  5. hauntsaninja
    added 3 commits that reference this issue on Dec 22, 2022

    pythongh-100428: Make int documentation more accurate

    6678637

    pythongh-100428: Make float documentation more accurate

    50807c3

    gh-100428: Make float documentation more accurate (#100437)

    2e1a9ce
  6. miss-islington
    added 4 commits that reference this issue on Dec 24, 2022

    pythongh-100428: Make float documentation more accurate (pythonGH-100437

    63f7feb

    pythongh-100428: Make float documentation more accurate (pythonGH-100437

    5b89d41

    gh-100428: Make float documentation more accurate (GH-100437)

    0dea924

    gh-100428: Make float documentation more accurate (GH-100437)

    bf0f306
  7. iritkatriel
    added a commit that references this issue on Dec 28, 2022

    Merged main into regmachine branch (#50)

    fdc73cb
  8. hauntsaninja
    added a commit that references this issue on Jan 2, 2023

    gh-100428: Make int documentation more accurate (#100436)

    edfbf56
  9. miss-islington
    added 4 commits that reference this issue on Jan 2, 2023

    pythongh-100428: Make int documentation more accurate (pythonGH-100436)

    5a399bb

    pythongh-100428: Make int documentation more accurate (pythonGH-100436)

    73163a1

    gh-100428: Make int documentation more accurate (GH-100436)

    c92c551

    gh-100428: Make int documentation more accurate (GH-100436)

    af136e9
  10. hauntsaninja
    closed this as completedon Jan 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    docsDocumentation in the Doc dirDocumentation in the Doc dir

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.