Shouldn't importing print_function change the keyword.kwlist in python2?

52 Views Asked by At

In python-2.7, shouldn't the keyword.kwlist be updated after importing print_function from __future__?

Python 2.7.18 (default, Feb  1 2021, 00:00:00) 
[GCC 10.2.1 20201125 (Red Hat 10.2.1-9)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import keyword
>>> keyword.iskeyword('print')
True
>>> print = 3
  File "<stdin>", line 1
    print = 3
          ^
SyntaxError: invalid syntax
>>> 
>>> from __future__ import print_function
>>> 
>>> keyword.iskeyword('print')
True
>>> print = 3
>>> 
>>> print
3
>>> keyword.kwlist
['and', 'as', 'assert', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'exec', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'not', 'or', 'pass', 'print', 'raise', 'return', 'try', 'while', 'with', 'yield']

Is this kind of bug? Or it is intentional?

0

There are 0 best solutions below