namelint 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- namelint-0.1.0/.gitignore +8 -0
- namelint-0.1.0/CHANGES.md +21 -0
- namelint-0.1.0/LICENSE +215 -0
- namelint-0.1.0/Makefile +35 -0
- namelint-0.1.0/PKG-INFO +181 -0
- namelint-0.1.0/README.md +160 -0
- namelint-0.1.0/notes/01-background.md +147 -0
- namelint-0.1.0/notes/02-specs.md +210 -0
- namelint-0.1.0/noxfile.py +38 -0
- namelint-0.1.0/pyproject.toml +83 -0
- namelint-0.1.0/ruff.toml +55 -0
- namelint-0.1.0/src/namelint/__init__.py +7 -0
- namelint-0.1.0/src/namelint/__main__.py +10 -0
- namelint-0.1.0/src/namelint/checks.py +262 -0
- namelint-0.1.0/src/namelint/cli.py +136 -0
- namelint-0.1.0/src/namelint/finding.py +44 -0
- namelint-0.1.0/src/namelint/py.typed +0 -0
- namelint-0.1.0/src/namelint/report.py +57 -0
- namelint-0.1.0/src/namelint/visitor.py +63 -0
- namelint-0.1.0/tests/a_unit/__init__.py +0 -0
- namelint-0.1.0/tests/a_unit/test_nam101_uncollected_test.py +98 -0
- namelint-0.1.0/tests/a_unit/test_nam106_get_performs_io.py +85 -0
- namelint-0.1.0/tests/a_unit/test_nam107_unlazy_generator.py +123 -0
- namelint-0.1.0/tests/b_integration/__init__.py +0 -0
- namelint-0.1.0/tests/b_integration/test_cli.py +121 -0
- namelint-0.1.0/tests/c_e2e/__init__.py +0 -0
- namelint-0.1.0/tests/conftest.py +42 -0
- namelint-0.1.0/tools/calibrate.py +295 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
4
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
5
|
+
|
|
6
|
+
## [0.1.0] - 2026-10-02
|
|
7
|
+
|
|
8
|
+
First release, to claim the name. Pre-release in substance: three of the eight specified checks, one of them on probation.
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- `NAM101`: a function in a test module that asserts, takes no arguments, and is not named `test*`, so pytest never collects it.
|
|
13
|
+
- `NAM106`: a `get_` whose body reaches a disk, a socket, a subprocess or a database.
|
|
14
|
+
- `NAM107`: a generator whose name reads as if it returned a container.
|
|
15
|
+
- The `namelint` CLI: `--select`, `--ignore`, `--json`, `--stats`, `--version`. Exit 0 clean, 1 findings, 2 the tool itself failed.
|
|
16
|
+
- `tools/calibrate.py`: fetches the nine-project golden corpus and measures every check against it, writing a summary table, every finding as JSONL, and a seeded sample to adjudicate by hand.
|
|
17
|
+
|
|
18
|
+
### Known
|
|
19
|
+
|
|
20
|
+
- `NAM107` fires at 15.9 per thousand functions in `httpx` and 13.7 in `rich`, which is a rule in question rather than a result about those codebases. The false-positive class is the undecorated protocol generator.
|
|
21
|
+
- No configuration file and no suppression mechanism yet; both wait on corpus evidence about what needs suppressing.
|
namelint-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
202
|
+
|
|
203
|
+
Copyright 2026 Abilian SAS
|
|
204
|
+
|
|
205
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
206
|
+
you may not use this file except in compliance with the License.
|
|
207
|
+
You may obtain a copy of the License at
|
|
208
|
+
|
|
209
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
210
|
+
|
|
211
|
+
Unless required by applicable law or agreed to in writing, software
|
|
212
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
213
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
214
|
+
See the License for the specific language governing permissions and
|
|
215
|
+
limitations under the License.
|
namelint-0.1.0/Makefile
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
.PHONY: all test build format check lint clean
|
|
2
|
+
|
|
3
|
+
all: test lint
|
|
4
|
+
|
|
5
|
+
check: lint
|
|
6
|
+
|
|
7
|
+
lint:
|
|
8
|
+
uv run --active ruff check
|
|
9
|
+
uv run --active ruff format --check
|
|
10
|
+
uv run --active ty check src
|
|
11
|
+
uv run --active pyrefly check src
|
|
12
|
+
uv run --active mypy src
|
|
13
|
+
# uv run --active mypy --strict src
|
|
14
|
+
|
|
15
|
+
format:
|
|
16
|
+
uv run --active ruff format src tests
|
|
17
|
+
uv run --active ruff check src tests --fix
|
|
18
|
+
uv run --active ruff format src tests
|
|
19
|
+
|
|
20
|
+
test:
|
|
21
|
+
uv run pytest
|
|
22
|
+
|
|
23
|
+
test-cov:
|
|
24
|
+
uv run pytest --cov=namelint --cov-report=html --cov-report=term tests
|
|
25
|
+
|
|
26
|
+
clean:
|
|
27
|
+
rm -rf .pytest_cache .ruff_cache dist build __pycache__ .mypy_cache \
|
|
28
|
+
.coverage htmlcov .coverage.* *.egg-info
|
|
29
|
+
-adt clean
|
|
30
|
+
|
|
31
|
+
build: clean
|
|
32
|
+
uv build
|
|
33
|
+
|
|
34
|
+
publish: build
|
|
35
|
+
uv publish
|
namelint-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: namelint
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Reports where a Python function's name contradicts its body.
|
|
5
|
+
Project-URL: Homepage, https://github.com/abilian/namelinter
|
|
6
|
+
Project-URL: Repository, https://github.com/abilian/namelinter
|
|
7
|
+
Project-URL: Issues, https://github.com/abilian/namelinter/issues
|
|
8
|
+
Project-URL: Changelog, https://github.com/abilian/namelinter/blob/main/CHANGES.md
|
|
9
|
+
Author: Abilian SAS
|
|
10
|
+
License-Expression: Apache-2.0
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Keywords: ast,linter,naming,static-analysis
|
|
13
|
+
Classifier: Development Status :: 3 - Alpha
|
|
14
|
+
Classifier: Environment :: Console
|
|
15
|
+
Classifier: Intended Audience :: Developers
|
|
16
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
17
|
+
Classifier: Topic :: Software Development :: Quality Assurance
|
|
18
|
+
Classifier: Typing :: Typed
|
|
19
|
+
Requires-Python: >=3.12
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
|
|
22
|
+
# namelint
|
|
23
|
+
|
|
24
|
+
Reports where a Python function's **name contradicts its body**.
|
|
25
|
+
|
|
26
|
+
`ruff` already knows that `getUserName` is not `snake_case`. Nothing knows that `get_user` opens a socket, that `cleanup_files` is a generator nobody will iterate twice, or that `check_user_is_valid` sits in a test module asserting things pytest will never collect. That gap is what this tool is for: every check needs the AST, and none of them is a grep over identifiers.
|
|
27
|
+
|
|
28
|
+
It holds **no opinion about vocabulary**. "Too generic", "too long", "prefer a domain term" belong in a style guide and a code review. namelint only reports that a name and the code under it disagree, and it names the fact that made it disagree, so you can argue with that fact rather than with the rule.
|
|
29
|
+
|
|
30
|
+
## Install
|
|
31
|
+
|
|
32
|
+
```sh
|
|
33
|
+
uv tool install namelint # on PATH, globally
|
|
34
|
+
uvx namelint src/ # or without installing anything
|
|
35
|
+
pip install namelint
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
No runtime dependencies, and that is a constraint rather than an accident: a linter you hesitate to add to a project because of what it drags in is a linter that does not get added. Python 3.12 or newer.
|
|
39
|
+
|
|
40
|
+
## Use
|
|
41
|
+
|
|
42
|
+
```sh
|
|
43
|
+
namelint src/ # lint a tree
|
|
44
|
+
namelint src/app/users.py # or one file
|
|
45
|
+
namelint --select NAM106 src/ # one check only (repeatable)
|
|
46
|
+
namelint --ignore NAM107 src/ # everything but one (repeatable)
|
|
47
|
+
namelint --json src/ # one JSON object per line
|
|
48
|
+
namelint --stats src/ # counts per check, with a rate
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Output is the one line every editor and CI annotator already parses:
|
|
52
|
+
|
|
53
|
+
```
|
|
54
|
+
src/app/users.py:42:5: NAM106 get_user performs I/O (calls httpx.get); get_ promises a cheap lookup, use fetch_, load_ or read_
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Exit codes: **0** clean, **1** findings, **2** namelint itself failed. A file it cannot parse is reported on stderr and skipped — one Python 2 file in a vendored tree must not end a run over 80,000 functions.
|
|
58
|
+
|
|
59
|
+
`--stats` exists for calibration rather than for daily use, and reports per thousand functions so that two codebases of different sizes can be compared:
|
|
60
|
+
|
|
61
|
+
```
|
|
62
|
+
$ namelint --stats ~/src/cpython/Lib
|
|
63
|
+
functions scanned: 61820
|
|
64
|
+
NAM101 28 0.45 per 1000
|
|
65
|
+
NAM106 26 0.42 per 1000
|
|
66
|
+
NAM107 115 1.86 per 1000
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## The checks
|
|
70
|
+
|
|
71
|
+
Three of the eight specified checks are implemented. Each is listed with what it reports **and what it deliberately stays quiet about**, because for this kind of rule the exemptions are most of the work.
|
|
72
|
+
|
|
73
|
+
### `NAM101` — a test that will never run
|
|
74
|
+
|
|
75
|
+
A function in a test module that contains an assertion, takes no arguments, and is not named `test*`. pytest collects `test*` and nothing else, so this function reports nothing, and a suite that stays green over it is telling you nothing about the code it claims to cover.
|
|
76
|
+
|
|
77
|
+
```python
|
|
78
|
+
# tests/test_users.py
|
|
79
|
+
def check_user_is_valid(): # NAM101 — pytest will not collect this
|
|
80
|
+
assert build().ok
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
Silent on: anything under `src/` (a test module is a `test_*.py`, a `*_test.py`, or any file under a `tests/` directory); a decorated function, which is what a fixture looks like; a `_`-prefixed helper, since a leading underscore says "not collected" as plainly as a name can; and a helper that takes the thing it checks — `assert_ok(response)` is a helper, and arity is the discriminator. A `with pytest.raises(...)` counts as an assertion.
|
|
84
|
+
|
|
85
|
+
### `NAM106` — a `get_` that performs I/O
|
|
86
|
+
|
|
87
|
+
`get` is a contract in Python rather than a lazy choice: `dict.get`, `getattr`, `os.environ.get` are all cheap and total. A `get_` that opens a socket breaks the promise its caller read.
|
|
88
|
+
|
|
89
|
+
```python
|
|
90
|
+
def get_user(uid): # NAM106 — calls httpx.get
|
|
91
|
+
return httpx.get(f"/u/{uid}").json()
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
Reported on `open`, `Path.read_*`/`write_*`, `urlopen`, DBAPI `execute`/`fetchone`/`fetchall`, socket `recv`/`send`, and anything rooted at `requests`, `httpx`, `urllib`, `socket`, `subprocess` or `aiohttp`. The suggestion is `fetch_`, `load_` or `read_`. `dict.get` and `getattr` are never the evidence.
|
|
95
|
+
|
|
96
|
+
### `NAM107` — a generator under a non-lazy name
|
|
97
|
+
|
|
98
|
+
A caller who believes they hold a list and actually hold a one-shot iterator writes a bug that surfaces two loops later, far from this function.
|
|
99
|
+
|
|
100
|
+
```python
|
|
101
|
+
def collect_stale_entry(root): # NAM107 — contains yield
|
|
102
|
+
for path in root.iterdir():
|
|
103
|
+
if stale(path):
|
|
104
|
+
yield path
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
Silent on: a plural final word (`items`, `values`, `user_records`); a lazy prefix (`iter_`, `walk_`, `gen_`, `generate_`, `stream_`, `scan_`, `traverse_`, `produce_`, `yield_`, `enumerate_`, `chunk_`), checked after any leading underscores; dunders; and a `yield` that is a *protocol* rather than iteration — a pytest fixture, a `@contextmanager`, an `@asynccontextmanager`, a pluggy `@hookimpl` wrapper. In all four the noun name is correct on purpose (`db_session`, `temp_config`, `client`).
|
|
108
|
+
|
|
109
|
+
**This check is the one currently in question.** It fires at 15.9 per thousand functions in `httpx` and 13.7 in `rich`, which is far outside what a well-named codebase should produce, and the known false-positive class is the undecorated protocol generator: an ABC method where `yield request` *is* the interface. Expect it to get a narrower detector or to drop to advisory before 1.0.
|
|
110
|
+
|
|
111
|
+
### Still to come
|
|
112
|
+
|
|
113
|
+
`NAM102` a `@property` whose name opens with a verb · `NAM103` an `is_`/`has_`/`can_` that does not return a bool · `NAM104` a bool return under a non-predicate name · `NAM105` a query-shaped name that returns `None` on every path · `NAM108` a method repeating its class name. The three that depend on reading return types share machinery and are being built together; `NAM108` is last because it is the one most likely to be cut.
|
|
114
|
+
|
|
115
|
+
## Calibration
|
|
116
|
+
|
|
117
|
+
A rule firing often on a codebase nobody thinks is badly named is a **wrong rule**, and it is no evidence at all about that codebase. So every check is measured against a fixed corpus of nine projects before it is allowed to ship, and a check running above roughly two false positives in thirty gets a narrower detector, drops to advisory, or is cut.
|
|
118
|
+
|
|
119
|
+
```sh
|
|
120
|
+
uv run tools/calibrate.py # fetch what is missing, then measure
|
|
121
|
+
uv run tools/calibrate.py --only click # one project
|
|
122
|
+
uv run tools/calibrate.py --no-fetch # re-measure after changing a detector
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
It shallow-clones CPython's `Lib/`, attrs, pydantic, requests, httpx, rich, click, pytest and flask into `corpus/`, then writes `calibration/summary.md` (the table), `findings.jsonl` (every finding, so two runs can be diffed) and `sample.md` (a seeded random sample per check, with source lines, as checkboxes to adjudicate by hand). The sample is seeded deliberately: measuring a changed detector against a fresh sample measures the sample. Every row records the commit it came from, because a number with no commit behind it is a rumour.
|
|
126
|
+
|
|
127
|
+
The current run — 85,368 functions, 308 findings:
|
|
128
|
+
|
|
129
|
+
| Project | NAM101 | NAM106 | NAM107 |
|
|
130
|
+
|---|---:|---:|---:|
|
|
131
|
+
| cpython `Lib/` | 0.45 | 0.42 | 1.86 |
|
|
132
|
+
| attrs | 0.00 | 0.00 | 0.87 |
|
|
133
|
+
| pydantic | 0.79 | 0.56 | 0.68 |
|
|
134
|
+
| requests | 0.00 | 0.00 | 0.00 |
|
|
135
|
+
| httpx | 0.00 | 0.88 | **15.87** |
|
|
136
|
+
| rich | 0.55 | 0.00 | **13.71** |
|
|
137
|
+
| click | 0.00 | 0.00 | **7.43** |
|
|
138
|
+
| pytest | 0.46 | 0.46 | **7.97** |
|
|
139
|
+
| flask | 0.00 | 1.37 | 0.68 |
|
|
140
|
+
|
|
141
|
+
Findings per thousand functions. CPython is pinned to `v3.13.0`, since `main` uses syntax a 3.14 interpreter cannot parse and measuring it would measure the interpreter instead of the corpus.
|
|
142
|
+
|
|
143
|
+
## As a library
|
|
144
|
+
|
|
145
|
+
`check_module(tree, path) -> list[Finding]` is also flake8's plugin contract, so a flake8 adapter is an entry point and a wrapper rather than a second implementation. `checks.py` imports nothing but `ast` and two frozen records, and is a pure function of a node and a `Context` — no filesystem, no configuration.
|
|
146
|
+
|
|
147
|
+
```python
|
|
148
|
+
import ast
|
|
149
|
+
from pathlib import Path
|
|
150
|
+
from namelint.visitor import check_module, check_source
|
|
151
|
+
|
|
152
|
+
for finding in check_source(
|
|
153
|
+
"def get_user(u):\n return httpx.get(u)\n", Path("x.py")
|
|
154
|
+
):
|
|
155
|
+
print(finding.code, finding.name, finding.evidence)
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
Every `Finding` carries `code`, `line`, `col`, `name`, `message` and `evidence`. `evidence` names the fact that produced the finding: "calls `httpx.get`" is arguable, "performs I/O" is not.
|
|
159
|
+
|
|
160
|
+
There is no ruff plugin because ruff has no plugin API.
|
|
161
|
+
|
|
162
|
+
## Status
|
|
163
|
+
|
|
164
|
+
**0.1.0, pre-release.** Three checks of eight, one of which is on probation. The output format and the `NAM1xx` codes are not frozen yet. There is no configuration file and no suppression mechanism; both are waiting on evidence from the corpus about what actually needs suppressing — `requests`, where `get` is the HTTP verb, already shows that the first exception needed is module-scoped.
|
|
165
|
+
|
|
166
|
+
## Development
|
|
167
|
+
|
|
168
|
+
```sh
|
|
169
|
+
uv sync
|
|
170
|
+
make test # pytest
|
|
171
|
+
make lint # ruff check, ruff format --check, ty, pyrefly, mypy
|
|
172
|
+
nox -s tests # against 3.12, 3.13 and 3.14
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
Reasoning behind each rule, the corpus design and the open questions: `notes/02-specs.md`. Where the rules came from, and what was rejected: `notes/01-background.md`.
|
|
176
|
+
|
|
177
|
+
A new check is not finished when it passes its tests. It is finished when it has been run over the corpus and adjudicated, and the sample is in the commit.
|
|
178
|
+
|
|
179
|
+
## Licence
|
|
180
|
+
|
|
181
|
+
Apache 2.0. Copyright 2026 Abilian SAS.
|
namelint-0.1.0/README.md
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
# namelint
|
|
2
|
+
|
|
3
|
+
Reports where a Python function's **name contradicts its body**.
|
|
4
|
+
|
|
5
|
+
`ruff` already knows that `getUserName` is not `snake_case`. Nothing knows that `get_user` opens a socket, that `cleanup_files` is a generator nobody will iterate twice, or that `check_user_is_valid` sits in a test module asserting things pytest will never collect. That gap is what this tool is for: every check needs the AST, and none of them is a grep over identifiers.
|
|
6
|
+
|
|
7
|
+
It holds **no opinion about vocabulary**. "Too generic", "too long", "prefer a domain term" belong in a style guide and a code review. namelint only reports that a name and the code under it disagree, and it names the fact that made it disagree, so you can argue with that fact rather than with the rule.
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
uv tool install namelint # on PATH, globally
|
|
13
|
+
uvx namelint src/ # or without installing anything
|
|
14
|
+
pip install namelint
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
No runtime dependencies, and that is a constraint rather than an accident: a linter you hesitate to add to a project because of what it drags in is a linter that does not get added. Python 3.12 or newer.
|
|
18
|
+
|
|
19
|
+
## Use
|
|
20
|
+
|
|
21
|
+
```sh
|
|
22
|
+
namelint src/ # lint a tree
|
|
23
|
+
namelint src/app/users.py # or one file
|
|
24
|
+
namelint --select NAM106 src/ # one check only (repeatable)
|
|
25
|
+
namelint --ignore NAM107 src/ # everything but one (repeatable)
|
|
26
|
+
namelint --json src/ # one JSON object per line
|
|
27
|
+
namelint --stats src/ # counts per check, with a rate
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Output is the one line every editor and CI annotator already parses:
|
|
31
|
+
|
|
32
|
+
```
|
|
33
|
+
src/app/users.py:42:5: NAM106 get_user performs I/O (calls httpx.get); get_ promises a cheap lookup, use fetch_, load_ or read_
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Exit codes: **0** clean, **1** findings, **2** namelint itself failed. A file it cannot parse is reported on stderr and skipped — one Python 2 file in a vendored tree must not end a run over 80,000 functions.
|
|
37
|
+
|
|
38
|
+
`--stats` exists for calibration rather than for daily use, and reports per thousand functions so that two codebases of different sizes can be compared:
|
|
39
|
+
|
|
40
|
+
```
|
|
41
|
+
$ namelint --stats ~/src/cpython/Lib
|
|
42
|
+
functions scanned: 61820
|
|
43
|
+
NAM101 28 0.45 per 1000
|
|
44
|
+
NAM106 26 0.42 per 1000
|
|
45
|
+
NAM107 115 1.86 per 1000
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## The checks
|
|
49
|
+
|
|
50
|
+
Three of the eight specified checks are implemented. Each is listed with what it reports **and what it deliberately stays quiet about**, because for this kind of rule the exemptions are most of the work.
|
|
51
|
+
|
|
52
|
+
### `NAM101` — a test that will never run
|
|
53
|
+
|
|
54
|
+
A function in a test module that contains an assertion, takes no arguments, and is not named `test*`. pytest collects `test*` and nothing else, so this function reports nothing, and a suite that stays green over it is telling you nothing about the code it claims to cover.
|
|
55
|
+
|
|
56
|
+
```python
|
|
57
|
+
# tests/test_users.py
|
|
58
|
+
def check_user_is_valid(): # NAM101 — pytest will not collect this
|
|
59
|
+
assert build().ok
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Silent on: anything under `src/` (a test module is a `test_*.py`, a `*_test.py`, or any file under a `tests/` directory); a decorated function, which is what a fixture looks like; a `_`-prefixed helper, since a leading underscore says "not collected" as plainly as a name can; and a helper that takes the thing it checks — `assert_ok(response)` is a helper, and arity is the discriminator. A `with pytest.raises(...)` counts as an assertion.
|
|
63
|
+
|
|
64
|
+
### `NAM106` — a `get_` that performs I/O
|
|
65
|
+
|
|
66
|
+
`get` is a contract in Python rather than a lazy choice: `dict.get`, `getattr`, `os.environ.get` are all cheap and total. A `get_` that opens a socket breaks the promise its caller read.
|
|
67
|
+
|
|
68
|
+
```python
|
|
69
|
+
def get_user(uid): # NAM106 — calls httpx.get
|
|
70
|
+
return httpx.get(f"/u/{uid}").json()
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Reported on `open`, `Path.read_*`/`write_*`, `urlopen`, DBAPI `execute`/`fetchone`/`fetchall`, socket `recv`/`send`, and anything rooted at `requests`, `httpx`, `urllib`, `socket`, `subprocess` or `aiohttp`. The suggestion is `fetch_`, `load_` or `read_`. `dict.get` and `getattr` are never the evidence.
|
|
74
|
+
|
|
75
|
+
### `NAM107` — a generator under a non-lazy name
|
|
76
|
+
|
|
77
|
+
A caller who believes they hold a list and actually hold a one-shot iterator writes a bug that surfaces two loops later, far from this function.
|
|
78
|
+
|
|
79
|
+
```python
|
|
80
|
+
def collect_stale_entry(root): # NAM107 — contains yield
|
|
81
|
+
for path in root.iterdir():
|
|
82
|
+
if stale(path):
|
|
83
|
+
yield path
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
Silent on: a plural final word (`items`, `values`, `user_records`); a lazy prefix (`iter_`, `walk_`, `gen_`, `generate_`, `stream_`, `scan_`, `traverse_`, `produce_`, `yield_`, `enumerate_`, `chunk_`), checked after any leading underscores; dunders; and a `yield` that is a *protocol* rather than iteration — a pytest fixture, a `@contextmanager`, an `@asynccontextmanager`, a pluggy `@hookimpl` wrapper. In all four the noun name is correct on purpose (`db_session`, `temp_config`, `client`).
|
|
87
|
+
|
|
88
|
+
**This check is the one currently in question.** It fires at 15.9 per thousand functions in `httpx` and 13.7 in `rich`, which is far outside what a well-named codebase should produce, and the known false-positive class is the undecorated protocol generator: an ABC method where `yield request` *is* the interface. Expect it to get a narrower detector or to drop to advisory before 1.0.
|
|
89
|
+
|
|
90
|
+
### Still to come
|
|
91
|
+
|
|
92
|
+
`NAM102` a `@property` whose name opens with a verb · `NAM103` an `is_`/`has_`/`can_` that does not return a bool · `NAM104` a bool return under a non-predicate name · `NAM105` a query-shaped name that returns `None` on every path · `NAM108` a method repeating its class name. The three that depend on reading return types share machinery and are being built together; `NAM108` is last because it is the one most likely to be cut.
|
|
93
|
+
|
|
94
|
+
## Calibration
|
|
95
|
+
|
|
96
|
+
A rule firing often on a codebase nobody thinks is badly named is a **wrong rule**, and it is no evidence at all about that codebase. So every check is measured against a fixed corpus of nine projects before it is allowed to ship, and a check running above roughly two false positives in thirty gets a narrower detector, drops to advisory, or is cut.
|
|
97
|
+
|
|
98
|
+
```sh
|
|
99
|
+
uv run tools/calibrate.py # fetch what is missing, then measure
|
|
100
|
+
uv run tools/calibrate.py --only click # one project
|
|
101
|
+
uv run tools/calibrate.py --no-fetch # re-measure after changing a detector
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
It shallow-clones CPython's `Lib/`, attrs, pydantic, requests, httpx, rich, click, pytest and flask into `corpus/`, then writes `calibration/summary.md` (the table), `findings.jsonl` (every finding, so two runs can be diffed) and `sample.md` (a seeded random sample per check, with source lines, as checkboxes to adjudicate by hand). The sample is seeded deliberately: measuring a changed detector against a fresh sample measures the sample. Every row records the commit it came from, because a number with no commit behind it is a rumour.
|
|
105
|
+
|
|
106
|
+
The current run — 85,368 functions, 308 findings:
|
|
107
|
+
|
|
108
|
+
| Project | NAM101 | NAM106 | NAM107 |
|
|
109
|
+
|---|---:|---:|---:|
|
|
110
|
+
| cpython `Lib/` | 0.45 | 0.42 | 1.86 |
|
|
111
|
+
| attrs | 0.00 | 0.00 | 0.87 |
|
|
112
|
+
| pydantic | 0.79 | 0.56 | 0.68 |
|
|
113
|
+
| requests | 0.00 | 0.00 | 0.00 |
|
|
114
|
+
| httpx | 0.00 | 0.88 | **15.87** |
|
|
115
|
+
| rich | 0.55 | 0.00 | **13.71** |
|
|
116
|
+
| click | 0.00 | 0.00 | **7.43** |
|
|
117
|
+
| pytest | 0.46 | 0.46 | **7.97** |
|
|
118
|
+
| flask | 0.00 | 1.37 | 0.68 |
|
|
119
|
+
|
|
120
|
+
Findings per thousand functions. CPython is pinned to `v3.13.0`, since `main` uses syntax a 3.14 interpreter cannot parse and measuring it would measure the interpreter instead of the corpus.
|
|
121
|
+
|
|
122
|
+
## As a library
|
|
123
|
+
|
|
124
|
+
`check_module(tree, path) -> list[Finding]` is also flake8's plugin contract, so a flake8 adapter is an entry point and a wrapper rather than a second implementation. `checks.py` imports nothing but `ast` and two frozen records, and is a pure function of a node and a `Context` — no filesystem, no configuration.
|
|
125
|
+
|
|
126
|
+
```python
|
|
127
|
+
import ast
|
|
128
|
+
from pathlib import Path
|
|
129
|
+
from namelint.visitor import check_module, check_source
|
|
130
|
+
|
|
131
|
+
for finding in check_source(
|
|
132
|
+
"def get_user(u):\n return httpx.get(u)\n", Path("x.py")
|
|
133
|
+
):
|
|
134
|
+
print(finding.code, finding.name, finding.evidence)
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
Every `Finding` carries `code`, `line`, `col`, `name`, `message` and `evidence`. `evidence` names the fact that produced the finding: "calls `httpx.get`" is arguable, "performs I/O" is not.
|
|
138
|
+
|
|
139
|
+
There is no ruff plugin because ruff has no plugin API.
|
|
140
|
+
|
|
141
|
+
## Status
|
|
142
|
+
|
|
143
|
+
**0.1.0, pre-release.** Three checks of eight, one of which is on probation. The output format and the `NAM1xx` codes are not frozen yet. There is no configuration file and no suppression mechanism; both are waiting on evidence from the corpus about what actually needs suppressing — `requests`, where `get` is the HTTP verb, already shows that the first exception needed is module-scoped.
|
|
144
|
+
|
|
145
|
+
## Development
|
|
146
|
+
|
|
147
|
+
```sh
|
|
148
|
+
uv sync
|
|
149
|
+
make test # pytest
|
|
150
|
+
make lint # ruff check, ruff format --check, ty, pyrefly, mypy
|
|
151
|
+
nox -s tests # against 3.12, 3.13 and 3.14
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
Reasoning behind each rule, the corpus design and the open questions: `notes/02-specs.md`. Where the rules came from, and what was rejected: `notes/01-background.md`.
|
|
155
|
+
|
|
156
|
+
A new check is not finished when it passes its tests. It is finished when it has been run over the corpus and adjudicated, and the sample is in the commit.
|
|
157
|
+
|
|
158
|
+
## Licence
|
|
159
|
+
|
|
160
|
+
Apache 2.0. Copyright 2026 Abilian SAS.
|