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

networkx-3.2.1_1: /usr/lib/python3.12/site-packages/networkx/readwrite/tests/test_gml.py:557: SyntaxWarning: invalid octal escape sequence '\420' #7149

Closed
datenwolf opened this issue Dec 10, 2023 · 8 comments · Fixed by #7159

Comments

@datenwolf
Copy link

Installing through distribution package manager, at the "Byte-compiling python3.12 code for module networkx..." stage, the following errors are reported:

python3-networkx-3.2.1_1: configuring ...
Byte-compiling python3.12 code for module networkx...
usr/lib/python3.12/site-packages/networkx/readwrite/tests/test_gml.py:557: SyntaxWarning: invalid octal escape sequence '\420'
  "graph [edge [ source u'u\4200' target u'u\4200' ] "
usr/lib/python3.12/site-packages/networkx/readwrite/tests/test_gml.py:558: SyntaxWarning: invalid octal escape sequence '\420'
  + "node [ id u'u\4200' label b ] ]"
usr/lib/python3.12/site-packages/networkx/readwrite/tests/test_gml.py:557: SyntaxWarning: invalid octal escape sequence '\420'
  "graph [edge [ source u'u\4200' target u'u\4200' ] "
usr/lib/python3.12/site-packages/networkx/readwrite/tests/test_gml.py:558: SyntaxWarning: invalid octal escape sequence '\420'
  + "node [ id u'u\4200' label b ] ]"
@MridulS
Copy link
Member

MridulS commented Dec 10, 2023

Hmm, which package manager is this? We only package pypi and conda-forge.

@datenwolf
Copy link
Author

It's installed through my Linux distribution's package manager as some other package's sub-dependency. But that doesn't matter, because the issue can be easily found here

"graph [edge [ source u'u\4200' target u'u\4200' ] "

Don't shoot the messenger! Paste that string into the Python REPL:

Python 3.12.0 (main, Oct  6 2023, 16:16:58) [GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> print( "graph [edge [ source u'u\4200' target u'u\4200' ] " )
<stdin>:1: SyntaxWarning: invalid octal escape sequence '\420'

The code is broken, namely some escape sequences written incorrectly.

@MridulS
Copy link
Member

MridulS commented Dec 10, 2023

Yeah thanks for the report!
It's just weird our tests (or us) didn't catch this, we had similar issues #7064, #7032 before which were fixed.

Which linux distribution is this? How did you arrive at this step? (just trying to debug this)

@datenwolf
Copy link
Author

It's Voidlinux. Their basic philosophy is, to take upstream as is with zero custom patches. On my system networkx is pulled in as a dependency of python3-scikit-image

@dschult
Copy link
Member

dschult commented Dec 10, 2023

Interesting that the syntax warning says the octal sequence is \420 when the actual string says \4200

@rossbar
Copy link
Contributor

rossbar commented Dec 14, 2023

It's just weird our tests (or us) didn't catch this

FWIW I have noticed this warning when I run tests locally, I just hadn't gotten around to fixing it yet. We should double-check to see if we have at least one job in CI (preferably on latest Python) that converters all warnings to errors (at least the ones that are not explicitly caught).

Interesting that the syntax warning says the octal sequence is \420 when the actual string says \4200

I assume the test was going for the unicode 4200 character, but it's hard to know for sure. The potential solution that I went with in #7159 was to turn the \ into a literal escape (\\) so that it's interpreted as \ in the string. Another possible solution would be to replace the whole u\4200 with the actual unicode character. I'm not 100% sure what specifically this was designed to test, so opinions welcome!

@datenwolf
Copy link
Author

Uhhh, aren't Unicode escape sequences supposed to put the u after the backslash? Like print('\u4200')? Am I missing something here?

@rossbar
Copy link
Contributor

rossbar commented Dec 14, 2023

Am I missing something here?

Yeah, I think we all are :). My hypothesis that this was intended to be a unicode character (that was written incorrectly) was really just a guess based on context.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

4 participants