Issue : Incorrect usage of `warnings.warn` with formatted strings
- Dominant language
- Python
- Stars
- 84
- Forks
- 51
- PR merge metrics
- No merged PRs in 30d
Description
The `warnings.warn` function should be called with the `stacklevel` parameter to provide more accurate information about the source of the warning. Also, the message should be passed directly instead of using format. This will allow tools to filter based on warning type instead of message.
Consider the following updates to the `read_header` method:
```python
if header["analysis end"] - header["analysis start"] != 0:
warnings.warn(
"There appears to be some information in the ANALYSIS segment of file "
"{0}. However, it might not be read correctly.".format(self.path),
stacklevel=2,
)
```
should be changed to:
```python
if header["analysis end"] - header["analysis start"] != 0:
warnings.warn(
"There appears to be some information in the ANALYSIS segment of file {0}. However, it might not be read correctly.".format(self.path),
stacklevel=2,
)
```
This issue exists elsewhere in the code, such as in `FCSParser._extract_text_dict` and should be updated consistently.
Contributor guide
Assessment
This issue has not been assessed yet.