GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Fix normalizeSelection for Python < 3.8 (#18279) · haedeu/vscode-python@dd76d9d

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • news/2 Fixes
    • 18258.md
  • pythonFiles
    • normalizeSelection.py
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎news/2 Fixes/18258.md‎

Copy file name to clipboard
+1Lines changed: 1 addition & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix "Run Selection/Line in Python Terminal" for Python < 3.8 when the code includes decorators.
Collapse file

‎pythonFiles/normalizeSelection.py‎

Copy file name to clipboardExpand all lines: pythonFiles/normalizeSelection.py
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ def _get_statements(selection):
5050
for node in tree.body[1:]:
5151
line_end = node.lineno - 1
5252
# Special handling of decorators:
53-
# In Python 3, decorators are not taken into account in the value returned by lineno,
53+
# In Python 3.8 and higher, decorators are not taken into account in the value returned by lineno,
5454
# and we have to use the length of the decorator_list array to compute the actual start line.
55-
# In Python 2.7, lineno takes into account decorators, so this offset check is unnecessary.
55+
# Before that, lineno takes into account decorators, so this offset check is unnecessary.
5656
# Also, not all AST objects can have decorators.
57-
if hasattr(node, "decorator_list") and sys.version_info.major >= 3:
57+
if hasattr(node, "decorator_list") and sys.version_info >= (3, 8):
5858
# Using getattr instead of node.decorator_list or pyright will complain about an unknown member.
5959
line_end -= len(getattr(node, "decorator_list"))
6060
ends.append(line_end)
@@ -71,7 +71,7 @@ def _get_statements(selection):
7171
start = node.lineno - 1
7272

7373
# Special handling of decorators similar to what's above.
74-
if hasattr(node, "decorator_list") and sys.version_info.major >= 3:
74+
if hasattr(node, "decorator_list") and sys.version_info >= (3, 8):
7575
# Using getattr instead of node.decorator_list or pyright will complain about an unknown member.
7676
start -= len(getattr(node, "decorator_list"))
7777
block = "\n".join(lines[start:end])

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.