Python3 int.__sizeof__() 产生语法错误

Python3 int.__sizeof__() produces syntax error

以下代码产生语法错误。有谁知道为什么在使用对象属性时会出现语法错误?

Python 3.7.4 (default, Jul 27 2020, 09:35:23) 
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>1.__sizeof__()
  File "<stdin
    1.__sizeof__()
               ^
SyntaxError: invalid syntax
>>>

The lexer is greedy,因此它将 1.__sizeof__() 识别为 float 文字 1. 后跟标识符 __sizeof__,而不是 int 文字后跟 . 运算符。

$ python -m tokenize <<< "1.__sizeof__()"
1,0-1,2:            NUMBER         '1.'
1,2-1,12:           NAME           '__sizeof__'
1,12-1,13:          OP             '('
1,13-1,14:          OP             ')'
1,14-1,15:          NEWLINE        '\n'
2,0-2,0:            ENDMARKER      ''

使用括号覆盖协助词法分析器:

>>> (1).__sizeof__()
28