Sitelet https://github.com/python/cpython/issues/100428
Skip to content

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

Activity

  1. mdickinson commented on Dec 22, 2022

    @mdickinson
    Member

    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.

  2. mdickinson commented on Dec 22, 2022

    @mdickinson
    Member

    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)
  3. hauntsaninja commented on Dec 22, 2022

    @hauntsaninja
    Contributor

    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)
    
  4. added 3 commits that reference this issue on Dec 22, 2022
  5. added 4 commits that reference this issue on Dec 24, 2022
  6. added a commit that references this issue on Jan 2, 2023
  7. added 4 commits that reference this issue on 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 dir

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions