github / github/codeql

LGTM.com - false positive: unused argument to format

Đang mở
#2,650 1 bình luận 0 reaction 0 người được giao Xem trên GitHub
false-positive Python
Ngôn ngữ chính
CodeQL
Star
10.1k
Fork
2.1k
Merge trung bình
2 ngày 15 giờ
Pull request đã merge (30 ngày)
141

Mô tả

**Description of the false positive**

Impressively, the analysis found a statically defined string in the `main` function which does not have certain keywords in it that the call to `format` in a separate function `output_format` has. Unfortunately, the analysis missed the fact that there is a second code path where `output_format` is called with user-provided strings (that may have those keywords).

Seemingly relevant bits:
```python
def output_format(fmt, jobs):
for job in jobs:
s = fmt.format(
id=job["id"],
userid=job["userid"],
username=job_username(job),
priority=job["priority"],
state=statetostr(job, False),
state_single=statetostr(job, True),
name=job["name"],
ntasks=job["ntasks"],
t_submit=job["t_submit"],
t_depend=job["t_depend"],
t_sched=job["t_sched"],
t_run=job["t_run"],
t_cleanup=job["t_cleanup"],
t_inactive=job["t_inactive"],
runtime=runtime(job, False),
runtime_fsd=runtime_fsd(job, False),
runtime_fsd_hyphen=runtime_fsd(job, True),
runtime_hms=runtime_hms(job),
)
print(s)

def main():
args = parse_args()
jobs = fetch_jobs(args)

if args.format:
output_format(args.format, jobs)
else:
fmt = (
"{id:>18} {username:<8.8} {name:<10.10} {state:<8.8} "
"{ntasks:>6} {runtime_fsd_hyphen}"
)
if not args.suppress_header:
s = fmt.format(
id="JOBID",
username="USER",
name="NAME",
state="STATE",
ntasks="NTASKS",
runtime_fsd_hyphen="RUNTIME",
)
print(s)
output_format(fmt, jobs)
```

Output from LGTM:
```
Surplus named argument for string format. An argument named 'priority' is provided, but it is not required by format "{id:>18} {username:<8.8} {name:<10.10} {state:<8.8} {ntasks:>6} {runtime_fsd_hyphen}".
```

This is an easy-enough error to suppress, but I figured I'd file the false positive. Really amazing tool BTW!

**URL to the alert on the project page on LGTM.com**

https://lgtm.com/projects/g/flux-framework/flux-core/snapshot/ee30ed85d95632cea4f1bb1a1a4deb1046fd95b5/files/src/cmd/flux-jobs.py#xc23648d36039a520:1

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.