[Python-checkins] bpo-20692: Add Programming FAQ entry for 1.__class__ error. (GH-28918)

miss-islington webhook-mailer at python.org
Wed Oct 13 01:40:23 EDT 2021


https://github.com/python/cpython/commit/cc90732d15b267feb4cb75ec4c448a3c66e6c520
commit: cc90732d15b267feb4cb75ec4c448a3c66e6c520
branch: 3.9
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: miss-islington <31488909+miss-islington at users.noreply.github.com>
date: 2021-10-12T22:40:18-07:00
summary:

bpo-20692: Add Programming FAQ entry for 1.__class__ error. (GH-28918)


To avoid error, add either space or parentheses.
(cherry picked from commit 380c44087505d0d560f97e325028f27393551164)

Co-authored-by: Terry Jan Reedy <tjreedy at udel.edu>

files:
A Misc/NEWS.d/next/Documentation/2021-10-13-00-42-54.bpo-20692.K5rGtP.rst
M Doc/faq/programming.rst

diff --git a/Doc/faq/programming.rst b/Doc/faq/programming.rst
index 4e04b10b0dae6..5286bbbccf073 100644
--- a/Doc/faq/programming.rst
+++ b/Doc/faq/programming.rst
@@ -836,6 +836,27 @@ ago?  ``-190 % 12 == 2`` is useful; ``-190 % 12 == -10`` is a bug waiting to
 bite.
 
 
+How do I get int literal attribute instead of SyntaxError?
+----------------------------------------------------------
+
+Trying to lookup an ``int`` literal attribute in the normal manner gives
+a syntax error because the period is seen as a decimal point::
+
+   >>> 1.__class__
+     File "<stdin>", line 1
+     1.__class__
+      ^
+   SyntaxError: invalid decimal literal
+
+The solution is to separate the literal from the period
+with either a space or parentheses.
+
+   >>> 1 .__class__
+   <class 'int'>
+   >>> (1).__class__
+   <class 'int'>
+
+
 How do I convert a string to a number?
 --------------------------------------
 
diff --git a/Misc/NEWS.d/next/Documentation/2021-10-13-00-42-54.bpo-20692.K5rGtP.rst b/Misc/NEWS.d/next/Documentation/2021-10-13-00-42-54.bpo-20692.K5rGtP.rst
new file mode 100644
index 0000000000000..44ae468d1bccf
--- /dev/null
+++ b/Misc/NEWS.d/next/Documentation/2021-10-13-00-42-54.bpo-20692.K5rGtP.rst
@@ -0,0 +1,2 @@
+Add Programming FAQ entry explaining that int literal attribute access
+requires either a space after or parentheses around the literal.



More information about the Python-checkins mailing list