Comments (2)
@pmvd
Could you provide a minimum code example where the problem occurs?
from autopep8.
📝
Example code to be reproduced
# target.py
doc, doc2 = ("""
World:
1 + "programming"
+ " pythonあ""",
"""abc"""
)
with Python3.12 (3.12.4)
$ python --version
Python 3.12.4
$ pycodestyle --version
2.12.0
$ pycodestyle target.py
Traceback (most recent call last):
File "/Users/hideohattori/.pyenv/versions/common3124/bin/pycodestyle", line 8, in <module>
sys.exit(_main())
^^^^^^^
File "/Users/hideohattori/.pyenv/versions/3.12.4/envs/common3124/lib/python3.12/site-packages/pycodestyle.py", line 2671, in _main
report = style_guide.check_files()
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/hideohattori/.pyenv/versions/3.12.4/envs/common3124/lib/python3.12/site-packages/pycodestyle.py", line 2371, in check_files
runner(path)
File "/Users/hideohattori/.pyenv/versions/3.12.4/envs/common3124/lib/python3.12/site-packages/pycodestyle.py", line 2383, in input_file
return fchecker.check_all(expected=expected, line_offset=line_offset)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/hideohattori/.pyenv/versions/3.12.4/envs/common3124/lib/python3.12/site-packages/pycodestyle.py", line 2137, in check_all
self.check_logical()
File "/Users/hideohattori/.pyenv/versions/3.12.4/envs/common3124/lib/python3.12/site-packages/pycodestyle.py", line 1993, in check_logical
mapping = self.build_tokens_line()
^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/hideohattori/.pyenv/versions/3.12.4/envs/common3124/lib/python3.12/site-packages/pycodestyle.py", line 1973, in build_tokens_line
prev_text = self.lines[prev_row - 1][prev_col - 1]
~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^
IndexError: string index out of range
with Python3.11 (3.11.7)
$ python --version
Python 3.11.7
$ pycodestyle --version
2.12.0
$ pycodestyle target.py
t3_2.py:6:1: E128 continuation line under-indented for visual indent
t3_2.py:7:1: E124 closing bracket does not match visual indentation
Why?
The behaviour of tokenize.generate_tokens in Python 3.12 may have changed.
# sample1.py
import tokenize
from io import StringIO
code = """doc, doc2 = (\"\"\"
World:
1 + "programming"
+ " pythonあ\"\"\",
'''abc'''
)
"""
def tokenize_code(code):
tokens = []
for tok in tokenize.generate_tokens(StringIO(code).readline):
tokens.append((tok.type, tok.string, tok.start, tok.end, tok.line))
return tokens
tokens_311 = tokenize_code(code)
for token in tokens_311:
print(token)
print(tokenize.untokenize(tokens_311))
with Python3.11.7
~/.pyenv/versions/3.11.7/bin/python sample1.py
(1, 'doc', (1, 0), (1, 3), 'doc, doc2 = ("""\n')
(54, ',', (1, 3), (1, 4), 'doc, doc2 = ("""\n')
(1, 'doc2', (1, 5), (1, 9), 'doc, doc2 = ("""\n')
(54, '=', (1, 10), (1, 11), 'doc, doc2 = ("""\n')
(54, '(', (1, 12), (1, 13), 'doc, doc2 = ("""\n')
(3, '"""\nWorld:\n1 + "programming"\n+ " pythonあ"""', (1, 13), (4, 14), 'doc, doc2 = ("""\nWorld:\n1 + "programming"\n+ " pythonあ""",\n')
(54, ',', (4, 14), (4, 15), '+ " pythonあ""",\n')
(62, '\n', (4, 15), (4, 16), '+ " pythonあ""",\n')
(3, "'''abc'''", (5, 0), (5, 9), "'''abc'''\n")
(62, '\n', (5, 9), (5, 10), "'''abc'''\n")
(54, ')', (6, 0), (6, 1), ')\n')
(4, '\n', (6, 1), (6, 2), ')\n')
(0, '', (7, 0), (7, 0), '')
doc, doc2 = ("""
World:
1 + "programming"
+ " pythonあ""",
'''abc'''
)
with Python3.12.4
~/.pyenv/versions/3.12.4/bin/python sample1.py
(1, 'doc', (1, 0), (1, 3), 'doc, doc2 = ("""\n')
(55, ',', (1, 3), (1, 4), 'doc, doc2 = ("""\n')
(1, 'doc2', (1, 5), (1, 9), 'doc, doc2 = ("""\n')
(55, '=', (1, 10), (1, 11), 'doc, doc2 = ("""\n')
(55, '(', (1, 12), (1, 13), 'doc, doc2 = ("""\n')
(3, '"""\nWorld:\n1 + "programming"\n+ " pythonあ"""', (1, 13), (4, 14), 'doc, doc2 = ("""\nWorld:\n1 + "programming"\n+ " pythonあ""",\n')
(55, ',', (4, 16), (4, 17), '+ " pythonあ""",\n')
(65, '\n', (4, 17), (4, 18), '+ " pythonあ""",\n')
(3, "'''abc'''", (5, 0), (5, 9), "'''abc'''\n")
(65, '\n', (5, 9), (5, 10), "'''abc'''\n")
(55, ')', (6, 0), (6, 1), ')\n')
(4, '\n', (6, 1), (6, 2), ')\n')
(0, '', (7, 0), (7, 0), '')
doc, doc2 = ("""
World:
1 + "programming"
+ " pythonあ""" ,
'''abc'''
)
from autopep8.
Related Issues (20)
- How to ignore the two-spaces-before-comment rule ? HOT 1
- Dismatch between autopep8 and pep8? HOT 1
- Comments are always formatted at 80 characters maximum
- autopep8 line length not working with async def function
- Questions about Copilot + Open Source Software Hierarchy HOT 1
- Please delete this useless lib
- Inserting newlines into triple-quoted f-strings on Python 3.12 HOT 1
- --experimental --max-line-length does not work on Python 3.12 with f-strings inside of a dict HOT 1
- How to stop <- from becomming < - HOT 6
- 'Staircase' formatting
- Splitting long f strings containing hash sign (#) into multiple lines breaks code syntax HOT 1
- --experimental adds spaces inside an f-string, which exceeds the max length
- Visual indent changed for certain continued strings
- misformatted `type` keyword
- Remove space
- close
- Formatting text with variables using f"" lead to not nice break
- E203 fix gets reversed by `black`
- File got mangled
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from autopep8.