Skip to content

Recognise async def method headers in worder - #859

Open
gadievron wants to merge 1 commit into
python-rope:masterfrom
gadievron:fix/worder-async-def
Open

Recognise async def method headers in worder#859
gadievron wants to merge 1 commit into
python-rope:masterfrom
gadievron:fix/worder-async-def

Conversation

@gadievron

Copy link
Copy Markdown

Description

worder's is_a_class_or_function_name_in_header only recognised the def and
class header prefixes, so an async def method header was not treated as a
definition. As a result find_definition for an async def method called via
self resolved to the call site instead of the def, and Rename from the
call did not reach the def.

class C:
    async def target(self):
        pass
    async def run(self):
        await self.target()   # find_definition here -> the call site, not `def target`

Module-level async def already resolved correctly (different path); only method
resolution via self was affected.

Fix

Add "async def" to the recognised headers and normalise internal whitespace so
async def / async\tdef / line-continued forms also match:

return " ".join(prev_word.split()) in ["def", "class", "async def"]

The predicate reads the blanked real_code, so string/comment text can't spoof
it, and only those three exact strings match — no false-positive surface. The fix
is version-independent (async def has been valid since Python 3.5).

Tests cover find_definition on an async method (canonical and tab/extra-space
spellings), an end-to-end Rename, and two regression controls (sync methods and
module-level async defs still resolve).


Checklist

  • I have added tests that prove my fix is effective
  • I have updated CHANGELOG.md

@gadievron
gadievron force-pushed the fix/worder-async-def branch from e9c8570 to d70366e Compare August 16, 2026 17:53
The predicate only matched the canonical `def`/`class` prefixes, so an
`async def` method header was not treated as a definition: find_definition
on a call via self resolved to the call site instead of the def, and
Rename mis-handled it. Normalize the whitespace run before comparing so
`async def`, `async  def` and `async\tdef` are all recognised. Version
independent.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@gadievron
gadievron force-pushed the fix/worder-async-def branch from d70366e to 93082f7 Compare August 16, 2026 19:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant