Skip to content

iris0329/pyfqname

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 

Repository files navigation

pyfqname: Python Fully Qualified Name Finder

Overview

pyfqname.py determines the fully qualified name for a given Python source file and line number. It resolves the enclosing scopes and reports key metadata:

  • fqname: The fully qualified name, e.g. module.Class.function.
  • class: The nearest enclosing class name (if any).
  • function: The nearest enclosing function/method name (if any).
  • location: Repository-relative file path and line number (e.g. pkg/module.py#L10).
  • line: The source line text; if it contains backticks, it is rendered as a fenced code block for Markdown safety.

Editor Integration (VS Code/Cursor)

One-time setup to trigger the script with a keybinding:

  1. Open "Preferences: Open Keyboard Shortcuts (JSON)".
  2. Add a keybinding entry like:
    {
        "key": "cmd+alt+c",
        "command": "workbench.action.terminal.sendSequence",
        "args": {
            "text": "python3 -u pyfqname.py ${file} ${lineNumber} ${workspaceFolder}\n"
        },
        "when": "editorTextFocus && editorLangId == python && remoteName =~ /ssh|wsl/"
    },
  3. Ensure scripts/pyfqname.py is located under the scripts directory.
  4. In Python file, press cmd + alt + c on a Python file to invoke the script.

pyfqname:Python 完全限定名定位器

简介

pyfqname.py 用于在给定 Python 源文件与行号时,定位该行所处的类/函数作用域,并输出其模块的完全限定名(Fully Qualified Name,FQName)、类名、函数名、相对路径位置以及该行内容。

环境要求

  • Python 3.8+(仅依赖标准库 astossys

编辑器集成(VS Code/Cursor)

按如下步骤配置快捷键来调用脚本:

1️⃣ 打开「Preferences: Open Keyboard Shortcuts (JSON)」并添加:

{
    "key": "cmd+alt+c",
    "command": "workbench.action.terminal.sendSequence",
    "args": {
        "text": "python3 -u pyfqname.py ${file} ${lineNumber} ${workspaceFolder}\n"
    },
    "when": "editorTextFocus && editorLangId == python && remoteName =~ /ssh|wsl/"
},

2️⃣ 确保当前脚本位于 scripts 目录下(scripts/pyfqname.py)。

3️⃣ 聚焦到 Python 文件后,按 cmd + alt + c 触发脚本。

输出示例

- fqname: `train.train_3d.Trainer.fit`
- class: `Trainer`
- function: `fit`
- location: `train/train_3d.py#L123`
- line: `loss = self.compute_loss(batch)`

About

用于在给定 Python 源文件与行号时,定位该行所处的类/函数作用域,并输出其模块的完全限定名(Fully Qualified Name,FQName)、类名、函数名、相对路径位置以及该行内容。

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages