Skip to content

Regex in docstring triggers warnings #8429

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
algonell opened this issue Mar 10, 2023 · 1 comment
Closed

Regex in docstring triggers warnings #8429

algonell opened this issue Mar 10, 2023 · 1 comment

Comments

@algonell
Copy link

Question

I have a function with regex in docstring explaining how the input argument should look like:

def fun(data: str) -> str:
    """Does something.

    Args:
        data: A string metadata (regex: ^[YN]\d\d [YN]\d\d$).

    Returns:
        A string something.
    """

    return 'Something'

Triggers:

************* Module xyz
xyz.py:794:43: W1401: Anomalous backslash in string: '\d'. String constant might be missing an r prefix. (anomalous-backslash-in-string)

Shouldn't it be OK to include whatever in the docstring?
P.S. I've tried marking the entire regex as r'regex' but it still triggered the warning...

Documentation for future user

I don't really know, the available flags do not seem to address this one.

Additional context

Linux ip-172-31-31-219 5.19.0-1020-aws #21-Ubuntu SMP Thu Feb 9 17:37:58 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux

Name: pylint
Version: 2.17.0
Summary: python code static checker
Home-page:
Author:
Author-email: Python Code Quality Authority [email protected]
License: GPL-2.0-or-later
Location: /home/ubuntu/.local/lib/python3.10/site-packages
Requires: astroid, dill, isort, mccabe, platformdirs, tomli, tomlkit
Required-by:

Python 3.10.7

@algonell algonell added Documentation 📗 Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling Question labels Mar 10, 2023
@jacobtylerwalls
Copy link
Member

Thanks for the report.

Shouldn't it be OK to include whatever in the docstring?

Actually no, it raises a SyntaxWarning on 3.12.

P.S. I've tried marking the entire regex as r'regex' but it still triggered the warning...

You need to mark the whole string as a regex, so before the opening """

@jacobtylerwalls jacobtylerwalls removed the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label Jul 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants