Skip to content
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

Fix re string type #1077

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

jhunkeler
Copy link
Contributor

  • Replaces string literal with a raw string
  • https://docs.python.org/3/library/re.html#module-re states: [..] any invalid escape sequences in Python’s usage of the backslash in string literals now generate a SyntaxWarning and in the future this will become a SyntaxError. The solution is to use Python's raw string notation for regular expression patterns.

This PR addresses ...

Under Python 3.10:

DeprecationWarning: invalid escape sequence '\.'
    _VERSION_RE = re.compile(f"^[0-9]+\.[0-9]+\.[0-9]+$")

Under 3.11:

    _VERSION_RE = re.compile(f"^[0-9]+\.[0-9]+\.[0-9]+$")
                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^
SyntaxError: invalid escape sequence '\.'

Under 3.12:

SyntaxWarning: invalid escape sequence '\.'
    _VERSION_RE = re.compile(f"^[0-9]+\.[0-9]+\.[0-9]+$")

Tasks

  • update or add relevant tests
  • update relevant docstrings and / or docs/ page
  • Does this PR change any API used downstream? (if not, label with no-changelog-entry-needed)
    • write news fragment(s) in changes/: echo "changed something" > changes/<PR#>.<changetype>.rst (see below for change types)
news fragment change types...
  • changes/<PR#>.hst.rst: HST reference files
  • changes/<PR#>.jwst.rst: JWST reference files
  • changes/<PR#>.roman.rst: Roman reference files
  • changes/<PR#>.doc.rst: documentation change
  • changes/<PR#>.testing.rst: change to tests or test automation
  • changes/<PR#>.general.rst: infrastructure or miscellaneous change

* Replaces string literal with a raw string
* https://docs.python.org/3/library/re.html#module-re states:
  [..] any invalid escape sequences in Python’s usage of the backslash in
  string literals now generate a SyntaxWarning and in the future this will
  become a SyntaxError. The solution is to use Python's raw string notation
  for regular expression patterns.
@jhunkeler jhunkeler requested a review from a team as a code owner September 25, 2024 19:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant