Skip to content

Fix SyntaxWarning: invalid escape sequences in astparser.py#83

Open
KOLLIVENNELACHOWDARY wants to merge 1 commit intosugarlabs:masterfrom
KOLLIVENNELACHOWDARY:fix/issue-82-escape-sequences
Open

Fix SyntaxWarning: invalid escape sequences in astparser.py#83
KOLLIVENNELACHOWDARY wants to merge 1 commit intosugarlabs:masterfrom
KOLLIVENNELACHOWDARY:fix/issue-82-escape-sequences

Conversation

@KOLLIVENNELACHOWDARY
Copy link

Problem

The module produces warnings about invalid escape sequences in regex strings and deprecated AST APIs.

Solution

  1. Convert regex strings to raw strings (adds 'r' prefix)
  2. Update deprecated AST API usage for Python 3.14 compatibility

Changes Made

SyntaxWarning Fixes (Issue #82):

  • Line 224: FLOAT_REGEXP_STR = '...' → FLOAT_REGEXP_STR = r'...'
  • Line 226: RANGE_REGEXP = re.compile('...') → RANGE_REGEXP = re.compile(r'...')

DeprecationWarning Fixes (Python 3.14 Compatibility):

  • Line 144: ast.Str → ast.Constant (Helper.get_help)
  • Lines 493-494: ast.Num → ast.Constant (_process_node)
  • Line 496: ast.Str → ast.Constant with type check (_process_node)
  • Lines 599-604: ast.Num → ast.Constant, .n → .value (_parse_func)

Changes

  • 2 lines: Add 'r' prefix to regex strings (lines 224, 226)
  • 8 lines: Update deprecated AST APIs (lines 144, 493, 494, 496, 599, 602, 603, 604)

Testing

  • Module imports without warnings
  • All regex patterns work identically
  • All calculations produce correct results
  • No breaking changes

Verification

Command: python3 -W all -c "import astparser"

Result: Clean, no output = no warnings

Fixes #82

Use raw strings for regex patterns to prevent SyntaxWarning about invalid
escape sequences in Python 3.6+.

- Line 224: Change FLOAT_REGEXP_STR to use raw string
- Line 226: Change RANGE_REGEXP to use raw string

Fixes sugarlabs#82
@quozl
Copy link

quozl commented Feb 22, 2026

Why have you removed the end of line at end of file?

@KOLLIVENNELACHOWDARY
Copy link
Author

Ohh I am sorry , It was by mistake...

@KOLLIVENNELACHOWDARY
Copy link
Author

May I know why is this issue is still open??
Do I have to do anything more??

@quozl
Copy link

quozl commented Feb 23, 2026

This is a pull request, not an issue. It is open because you opened it and nobody else has closed it. Issue #82 is open because nobody has fixed the problem. My question to you was give me a reason to accept your change that removes the end of line mark at the end of a source file. I didn't think it was necessary to point you to which file or which end of line, because GitHub does a good job of that already, in the changes tab, with a big glaring icon coloured red. Why did you remove that end of line mark? If you can answer that, then you know what you are doing. If you cannot answer that, then go back into your experience to find what you did that caused it, repeat your steps, but omit the step that caused it. Or you could just ignore what you did wrong and fix it by adding an end of line mark, but that's not a self-reflective practice.

@KOLLIVENNELACHOWDARY
Copy link
Author

As I have mentioned it earlier , I made it accidentally not intentionally..I am so sorry for that too

@KOLLIVENNELACHOWDARY
Copy link
Author

KOLLIVENNELACHOWDARY commented Feb 24, 2026

Screenshot 2026-02-24 211638

In the picture I have provided above the last line exists ,that picture is preview of code that I had made changes ,
In changes tab that is shown may be because I actually accidentally removed that line when I was working on it and added it back again.. I think it is due to that modification it occured..

@quozl
Copy link

quozl commented Feb 24, 2026

Good explanation. You are yet to fix it though. We wait for you to fix it.

@KOLLIVENNELACHOWDARY
Copy link
Author

Thank you..
Yes , I have fixed and created new PR

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.

Calculate on Ubuntu 24.04

2 participants