ruff/crates/ruff_linter/resources/test/fixtures/flake8_logging/LOG007.py
qdegraaf 2aef46cb6f
Add Expr::Name checks to rules which use is_logger_candidate (#7521)
## Summary

Expands several rules to also check for `Expr::Name` values. As they
would previously not consider:
```python
from logging import error

error("foo")
```
as potential violations
```python
import logging

logging.error("foo")
```
as potential violations leading to inconsistent behaviour. 

The rules impacted are:

- `BLE001`
- `TRY400`
- `TRY401`
- `PLE1205`
- `PLE1206`
- `LOG007`
- `G001`-`G004`
- `G101`
- `G201`
- `G202`

## Test Plan

Fixtures for all impacted rules expanded. 

## Issue Link

Refers: https://github.com/astral-sh/ruff/issues/7502
2023-09-27 00:21:22 +00:00

24 lines
629 B
Python

import logging
logger = logging.getLogger(__name__)
logging.exception("foo") # OK
logging.exception("foo", exc_info=False) # LOG007
logging.exception("foo", exc_info=[]) # LOG007
logger.exception("foo") # OK
logger.exception("foo", exc_info=False) # LOG007
logger.exception("foo", exc_info=[]) # LOG007
logger.error("foo", exc_info=False) # OK
logger.info("foo", exc_info=False) # OK
from logging import exception
exception("foo", exc_info=False) # LOG007
exception("foo", exc_info=True) # OK
exception = lambda *args, **kwargs: None
exception("foo", exc_info=False) # OK
exception("foo", exc_info=True) # OK