Skip to content

Conversation

@dhruvmanila
Copy link
Member

@dhruvmanila dhruvmanila commented Sep 15, 2023

Summary

This PR implements a new rule for flake8-logging plugin that checks for
logging.getLogger calls with either __file__ or __cached__ as the first
argument and generates a suggested fix to use __name__ instead.

Refer: #7248

Test Plan

Add test cases and cargo test

@dhruvmanila
Copy link
Member Author

Current dependencies on/for this PR:

This comment was auto-generated by Graphite.

@dhruvmanila dhruvmanila added the rule Implementing or modifying a lint rule label Sep 15, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Sep 15, 2023

PR Check Results

Ecosystem

✅ ecosystem check detected no changes.

@charliermarsh charliermarsh merged commit 0d1fb82 into main Sep 16, 2023
@charliermarsh charliermarsh deleted the dhruv/log002 branch September 16, 2023 16:21
renovate bot referenced this pull request in allenporter/flux-local Sep 24, 2023
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [ruff](https://docs.astral.sh/ruff)
([source](https://togithub.com/astral-sh/ruff),
[changelog](https://togithub.com/astral-sh/ruff/releases)) | `==0.0.290`
-> `==0.0.291` |
[![age](https://developer.mend.io/api/mc/badges/age/pypi/ruff/0.0.291?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://developer.mend.io/api/mc/badges/adoption/pypi/ruff/0.0.291?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://developer.mend.io/api/mc/badges/compatibility/pypi/ruff/0.0.290/0.0.291?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://developer.mend.io/api/mc/badges/confidence/pypi/ruff/0.0.290/0.0.291?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|

---

### Release Notes

<details>
<summary>astral-sh/ruff (ruff)</summary>

###
[`v0.0.291`](https://togithub.com/astral-sh/ruff/releases/tag/v0.0.291)

[Compare
Source](https://togithub.com/astral-sh/ruff/compare/v0.0.290...v0.0.291)

<!-- Release notes generated using configuration in .github/release.yml
at v0.0.291 -->

#### What's Changed

##### Deprecations

**The `format` command-line argument and configuration option has been
renamed to `output-format`.** While Ruff will continue to respect
`format` when passed as a command-line argument or configuration option,
this backwards-compatible support will be dropped in a future release.
See:
[https://github.com/astral-sh/ruff/pull/7514](https://togithub.com/astral-sh/ruff/pull/7514).

##### Rules

- \[`flake8-bandit`] Implement `S201`: `flask-debug-true` by
[@&#8203;mkniewallner](https://togithub.com/mkniewallner) in
[https://github.com/astral-sh/ruff/pull/7503](https://togithub.com/astral-sh/ruff/pull/7503)
- \[`flake8-bandit`] Implement `S507`: `ssh_no_host_key_verification` by
[@&#8203;mkniewallner](https://togithub.com/mkniewallner) in
[https://github.com/astral-sh/ruff/pull/7528](https://togithub.com/astral-sh/ruff/pull/7528)
- \[`flake8-logging`] Implement `LOG002`: `invalid-get-logger-argument`
by [@&#8203;dhruvmanila](https://togithub.com/dhruvmanila) in
[https://github.com/astral-sh/ruff/pull/7399](https://togithub.com/astral-sh/ruff/pull/7399)
- \[`flake8-logging`] Implement `LOG007`: `exception-without-exc-info`
by [@&#8203;qdegraaf](https://togithub.com/qdegraaf) in
[https://github.com/astral-sh/ruff/pull/7410](https://togithub.com/astral-sh/ruff/pull/7410)
- \[`refurb`] Implement `FURB140`: `reimplemented-starmap` by
[@&#8203;SavchenkoValeriy](https://togithub.com/SavchenkoValeriy) in
[https://github.com/astral-sh/ruff/pull/7253](https://togithub.com/astral-sh/ruff/pull/7253)
- \[`refurb`] Implement `FURB148`: `unnecessary-enumerate` by
[@&#8203;tjkuson](https://togithub.com/tjkuson) in
[https://github.com/astral-sh/ruff/pull/7454](https://togithub.com/astral-sh/ruff/pull/7454)
- \[`ruff`] Detect `asyncio.get_running_loop` calls in RUF006 by
[@&#8203;charliermarsh](https://togithub.com/charliermarsh) in
[https://github.com/astral-sh/ruff/pull/7562](https://togithub.com/astral-sh/ruff/pull/7562)

##### Settings

- Show `--no-X` variants in CLI help by
[@&#8203;charliermarsh](https://togithub.com/charliermarsh) in
[https://github.com/astral-sh/ruff/pull/7504](https://togithub.com/astral-sh/ruff/pull/7504)
- Rename `format` option to `output-format` by
[@&#8203;MichaReiser](https://togithub.com/MichaReiser) in
[https://github.com/astral-sh/ruff/pull/7514](https://togithub.com/astral-sh/ruff/pull/7514)
- Enable tab completion for `ruff rule` by
[@&#8203;charliermarsh](https://togithub.com/charliermarsh) in
[https://github.com/astral-sh/ruff/pull/7560](https://togithub.com/astral-sh/ruff/pull/7560)

##### Bug Fixes

- Add padding to prevent some autofix errors by
[@&#8203;charliermarsh](https://togithub.com/charliermarsh) in
[https://github.com/astral-sh/ruff/pull/7461](https://togithub.com/astral-sh/ruff/pull/7461)
- Remove parentheses when rewriting assert calls to statements by
[@&#8203;charliermarsh](https://togithub.com/charliermarsh) in
[https://github.com/astral-sh/ruff/pull/7464](https://togithub.com/astral-sh/ruff/pull/7464)
- Avoid flagging starred elements in C402 by
[@&#8203;charliermarsh](https://togithub.com/charliermarsh) in
[https://github.com/astral-sh/ruff/pull/7466](https://togithub.com/astral-sh/ruff/pull/7466)
- Extend `bad-dunder-method-name` to permit `attrs` dunders by
[@&#8203;tjkuson](https://togithub.com/tjkuson) in
[https://github.com/astral-sh/ruff/pull/7472](https://togithub.com/astral-sh/ruff/pull/7472)
- Avoid N802 violations for
[@&#8203;overload](https://togithub.com/overload) methods by
[@&#8203;JonathanPlasse](https://togithub.com/JonathanPlasse) in
[https://github.com/astral-sh/ruff/pull/7498](https://togithub.com/astral-sh/ruff/pull/7498)
- Avoid flagging starred expressions in UP007 by
[@&#8203;charliermarsh](https://togithub.com/charliermarsh) in
[https://github.com/astral-sh/ruff/pull/7505](https://togithub.com/astral-sh/ruff/pull/7505)
- Ensure that LOG007 only triggers on `.exception()` calls by
[@&#8203;charliermarsh](https://togithub.com/charliermarsh) in
[https://github.com/astral-sh/ruff/pull/7524](https://togithub.com/astral-sh/ruff/pull/7524)
- Use strict sorted and union for NoQA mapping insertion by
[@&#8203;dhruvmanila](https://togithub.com/dhruvmanila) in
[https://github.com/astral-sh/ruff/pull/7531](https://togithub.com/astral-sh/ruff/pull/7531)
- Avoid inserting imports directly after continuation by
[@&#8203;charliermarsh](https://togithub.com/charliermarsh) in
[https://github.com/astral-sh/ruff/pull/7553](https://togithub.com/astral-sh/ruff/pull/7553)
- Add padding in `PERF102` fixes by
[@&#8203;charliermarsh](https://togithub.com/charliermarsh) in
[https://github.com/astral-sh/ruff/pull/7554](https://togithub.com/astral-sh/ruff/pull/7554)
- Avoid invalid fix for parenthesized values in F601 by
[@&#8203;charliermarsh](https://togithub.com/charliermarsh) in
[https://github.com/astral-sh/ruff/pull/7559](https://togithub.com/astral-sh/ruff/pull/7559)
- Treat `os.error` as an `OSError` alias by
[@&#8203;charliermarsh](https://togithub.com/charliermarsh) in
[https://github.com/astral-sh/ruff/pull/7582](https://togithub.com/astral-sh/ruff/pull/7582)
- Extend `bad-dunder-method-name` to permit `__html__` by
[@&#8203;jaap3](https://togithub.com/jaap3) in
[https://github.com/astral-sh/ruff/pull/7492](https://togithub.com/astral-sh/ruff/pull/7492)
- Fix stylist indentation with a formfeed by
[@&#8203;konstin](https://togithub.com/konstin) in
[https://github.com/astral-sh/ruff/pull/7489](https://togithub.com/astral-sh/ruff/pull/7489)

#### New Contributors

- [@&#8203;MicaelJarniac](https://togithub.com/MicaelJarniac) made their
first contribution in
[https://github.com/astral-sh/ruff/pull/5498](https://togithub.com/astral-sh/ruff/pull/5498)
- [@&#8203;maheshsaripalli9](https://togithub.com/maheshsaripalli9) made
their first contribution in
[https://github.com/astral-sh/ruff/pull/7552](https://togithub.com/astral-sh/ruff/pull/7552)
- [@&#8203;T-256](https://togithub.com/T-256) made their first
contribution in
[https://github.com/astral-sh/ruff/pull/7585](https://togithub.com/astral-sh/ruff/pull/7585)

**Full Changelog**:
astral-sh/ruff@v0.0.290...v0.0.291

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://developer.mend.io/github/allenporter/flux-local).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNi45Ny4xIiwidXBkYXRlZEluVmVyIjoiMzYuOTcuMSIsInRhcmdldEJyYW5jaCI6Im1haW4ifQ==-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
dylwil3 added a commit that referenced this pull request Jun 23, 2025
## Summary

Part of #15584

This adds a `Fix safety` section to [invalid-get-logger-argument
(LOG002)](https://docs.astral.sh/ruff/rules/invalid-get-logger-argument/#invalid-get-logger-argument-log002).

The fix/lint was introduced in #7399
No reasoning is given on the unsafety in the PR/code
Unsafe fix demonstration:
[playground](https://play.ruff.rs/e8008cbf-2ef5-4d38-8255-324f90e624cb)
```py
import logging
logger = logging.getLogger(__file__)
```

---------

Co-authored-by: Dylan <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

rule Implementing or modifying a lint rule

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants