https://github.com/brexhq/pyrefchecker
Check python code for potentially undefined references
https://github.com/brexhq/pyrefchecker
Last synced: 3 months ago
JSON representation
Check python code for potentially undefined references
- Host: GitHub
- URL: https://github.com/brexhq/pyrefchecker
- Owner: brexhq
- License: isc
- Created: 2020-10-16T01:47:51.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2021-02-27T00:33:18.000Z (about 4 years ago)
- Last Synced: 2025-01-04T02:30:07.519Z (4 months ago)
- Language: Python
- Size: 59.6 KB
- Stars: 0
- Watchers: 6
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# PyRefChecker
Py-Ref checker checks for _potential_ undefined references in Python code.
## Installation
```
git clone [email protected]:brexhq/pyrefchecker.git
cd pyrefchecker
pip install --upgrade pip
pip install .
```## Usage
```
pyrefchecker .
```Pyrefchecker checks all files and recursively checks all directories. It returns an exit code of 0 if no files have problems, and 1 otherwise.
Files containing `import *` statements cannot be checked, so they are ignored by default. This can be changed with `--disallow-import-star`.## Configuration
```
> poetry run pyrefchecker --helpUsage: pyrefchecker [OPTIONS] [PATHS]...
Check python files for potentially undefined references.
Example:
pyrefchecker .
Options:
--show-successes / --hide-successes
When set, show checks for good files
[default: (hide)]--timeout INTEGER Maximum processing time for a single file
[default: 5]--allow-import-star / --disallow-import-star
Whether or not to consider `import *` a
failure [default: (allowed)]--exclude REGEX Regex for paths to exclude [default: (\.egg
s|\.git|\.hg|\.mypy_cache|\.nox|\.tox|\.venv
|\.svn|_build|buck-out|build|dist)]--include REGEX Regex for paths to include [default:
\.pyi?$]--help Show this message and exit.
```Commandline options can also be configured in _pyproject.toml_ under `tool.pyrefchecker`. For example
```
[tool.pyrefchecker]
allow_import_star = False
exclude = "_pb2"
```## Examples
Here are some examples, which tools like mypy, pylint and pyflakes do not catch:
```py
if False:
a = "Hello!"print(a)
``````py
try:
assert False
a = "Hello!"
except Exception:
passprint(a)
``````py
for _ in range(0):
a = "Hello!"print(a)
```However, this is a difficult problem. Since pyrefchecker does not check semantics, it does produce 'false positives'. Often, though,
the false positives are pretty weird code anyway. For example, it will warn about this, unless you include a `ref: ignore` comment:```py
if True:
a = "Hello!"if True:
print(a) # ref: ignore
```## Library usage
You can also use pyrefchecker as a library:
```py
import pyrefcheckerprint(pyrefchecker.check("""
if True:
a = "hello"
print(a)
"""))# [RefWarning(line=4, column=6, reference='a')]
```