Skip to content

int literal methods inaccessible #45754

Closed

Description

@mykhal
mannequin
BPO 1413
Nosy @loewis, @tiran

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 = <Date 2007-11-09.21:29:41.427>
created_at = <Date 2007-11-09.14:43:27.255>
labels = ['type-bug', 'invalid']
title = 'int literal methods inaccessible'
updated_at = <Date 2007-11-09.23:28:37.768>
user = 'https://bugs.python.org/mykhal'

bugs.python.org fields:

activity = <Date 2007-11-09.23:28:37.768>
actor = 'loewis'
assignee = 'none'
closed = True
closed_date = <Date 2007-11-09.21:29:41.427>
closer = 'loewis'
components = []
creation = <Date 2007-11-09.14:43:27.255>
creator = 'mykhal'
dependencies = []
files = []
hgrepos = []
issue_num = 1413
keywords = []
message_count = 12.0
messages = ['57304', '57308', '57323', '57324', '57325', '57326', '57327', '57328', '57329', '57334', '57335', '57340']
nosy_count = 3.0
nosy_names = ['loewis', 'christian.heimes', 'mykhal']
pr_nums = []
priority = 'normal'
resolution = 'not a bug'
stage = None
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue1413'
versions = ['Python 2.5']

Activity

  1. mykhal commented on Nov 9, 2007

    mykhalmannequin
    MannequinAuthor

    It's impossible to call methods of int literals directly e.g.
    1.__str__() (the same for oct literals).
    Even through it works for float, hex, literals, etc..

    >>> 0x1.__str__()
    '1'
    >>> 1e0.__str__()
    '1.0'
    >>> 1..__str__()
    '1.0'
    >>> hasattr(1, '__str__')
    True
    >>> 1.__str__()
      File "<stdin>", line 1
        1.__str__()
                ^
    SyntaxError: invalid syntax
    >>> 01.__str__()
      File "<stdin>", line 1
        01.__str__()
                 ^
    SyntaxError: invalid syntax
  2. added
    type-bugAn unexpected behavior, bug, or error
    on Nov 9, 2007
  3. mykhal commented on Nov 9, 2007

    mykhalmannequin
    MannequinAuthor

    .. OK, now I see than (1).__str__() works..
    however, could be the parser fixed to 1.__str__() work too ?

  4. tiran commented on Nov 9, 2007

    @tiran
    Member

    It's a tricky problem because it's ambiguous:

    >> 1.j

    What's going to happen here? Does it do getattr(1, 'j') or does it
    create the imaginary number 1j?

  5. mykhal commented on Nov 9, 2007

    mykhalmannequin
    MannequinAuthor

    I don't understand why 1.j is 1j .. because there's no int.j .. why then
    1.L is not 1L ?

  6. mykhal commented on Nov 9, 2007

    mykhalmannequin
    MannequinAuthor

    .. however, fixing this is not necessary - because no one would probably
    use it, it's just a syntax inconsistency

  7. mykhal commented on Nov 9, 2007

    mykhalmannequin
    MannequinAuthor

    (finally now I get it.. I have forgotten that complex numbers can be
    float.. :) sorry )

  8. tiran commented on Nov 9, 2007

    @tiran
    Member

    I don't understand why 1.j is 1j .. because there's no int.j .. why then
    1.L is not 1L ?

    Complex numbers from the number domain |C which supersets |R. Complex
    numbers are usually implemented and viewed as 2d vectors made from two
    floating numbers real and img.

    A long or long int however is from number domain |Z which doesn't allow
    fraction and hence no '.', too.

    It should explain why 1.L is illegal but 1.j is 1.0 * 1j.

    .. however, fixing this is not necessary - because no one would
    probably use it, it's just a syntax inconsistency

    I don't if it's possible to fix the problem with Python's parser.
    However the inconsistency should be documented. Is it explained in the
    docs and do the docs also mention the (1).__attr__ trick? I wasn't aware
    that it works.

    Christian

  9. mykhal commented on Nov 9, 2007

    mykhalmannequin
    MannequinAuthor

    I don't know it's in docs, it came into my mind, maybe logically (but
    later) to put 1 into parentheses

  10. mykhal commented on Nov 9, 2007

    mykhalmannequin
    MannequinAuthor

    .. I remember.. it came onto my mind when I tried also -1.__str__() and
    found out that the dot has higher priority than unary minus :)

  11. loewis commented on Nov 9, 2007

    loewismannequin
    Mannequin

    As now should be clear, there really is no bug here.

    Notice that you can also write

    1 .__str__()

  12. mykhal commented on Nov 9, 2007

    mykhalmannequin
    MannequinAuthor

    interesting. I'm not sure I've read anywhere that it is allowed to place
    a whitespace between object and attributes. Thanks

  13. loewis commented on Nov 9, 2007

    loewismannequin
    Mannequin

    See

    http://www.python.org/doc/2.5/ref/whitespace.html

    which says that you can put spaces between arbitrary tokens, and

    http://www.python.org/doc/2.5/ref/attribute-references.html

    which says that all of primary, ".", and identifier are separate tokens
    in an attributeref (not so in a literal, where the . is part of the
    floating point literal).

  14. transferred this issue fromon Apr 10, 2022
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

    type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions