NewType/TypeVar/ParamSpec reference and rename¶
Python typing helpers often repeat a symbol name inside a string literal. BetterPy connects those string literals to the Python symbol so navigation and rename stay consistent.
How to invoke¶
- Use ⌘+Click / Ctrl+Click on the name string in
NewType,TypeVar, orParamSpeccalls to jump to the matching assigned symbol, for example from"UserId"toUserId. - Use ⇧F6 / Shift+F6 on the Python symbol to rename it. BetterPy keeps the matching string literal in sync.
- For
NewType, if the string was edited manually and no longer matches the assigned symbol, use the quick-fix on the highlighted string to update it.
Examples¶
Renaming UserId to AccountId updates both the target name and the string literal:
If a NewType literal drifted manually, BetterPy highlights the mismatch and offers to update the string:
The quick-fix rewrites it to:
What it supports¶
typing.NewType,typing.TypeVar, andtyping.ParamSpecstyle declarations.- String-literal references from the helper call back to the assigned Python symbol.
- Rename synchronization for the declaration and the literal.
- A quick-fix for manual
NewTypestring drift when the literal no longer matches the assigned symbol. PyCharm's built-in quick-fix handles the same drift forTypeVarandParamSpec. - Navigation and reference search in regular project files.
What it deliberately avoids¶
- Calls where the string literal intentionally does not match the assigned symbol.
- Dynamic names or computed string arguments.
- Unrelated string literals that happen to contain the same text.
- Library and stub files outside your project.
Notes¶
- This feature reduces rename drift in typing-heavy modules without changing runtime behavior.
- The feature is gated by the NewType/TypeVar/ParamSpec reference & rename setting under Settings | BetterPy | Typing & Type Hints | Completions.