Skip to content

Support running stubtest in non-UTF8 terminals #19085

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

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

Conversation

sterliakov
Copy link
Collaborator

@sterliakov sterliakov commented May 12, 2025

Fixes #19071. I looked through the open() calls in the codebase, and only reports.py raises some concerns. Stubtest crashes due to this print call with incompatible encoding.

I tested this on Linux with LC_CTYPE=ru_RU.CP1251 (random non-utf8 locale I found in /usr/share/i18n/SUPPORTED) and confirmed that stubtest crashes without the patch and passes with it.

Using a simple MRE (empty stub file and A = "╙" in a file, this symbol is $'\u2559'), I got this:

error: package.A is not present in stub
Stub: in file /tmp/tmp.Cs4RioNSuR/demo/stub/package/__init__.pyi
MISSING
Runtime:                                                                                                                                                                                                          
'?'
                                                                                                                                                                                                                  
Found 1 error (checked 1 module)

Without the patch I get a crash - same as in the linked issue.

@Avasam could you check this patch on windows, please? My nerves really aren't strong enough to configure whole virtualbox for a tiny encoding problem...

@Avasam
Copy link
Contributor

Avasam commented May 12, 2025

From a local run, the crash seems solved, but the display is incorrect:

error: networkx.classes.reportviews.InMultiEdgeView.dataview variable differs from runtime type abc.ABCMeta
Stub: in file E:\Users\Avasam\Documents\Git\typeshed\stubs\networkx\networkx\classes\reportviews.pyi:334
def [_Node <: typing.Hashable, _D] (viewer: Any, nbunch: Union[_Node`1, typing.Iterable[_Node`1], None] =, data: builtins.bool =, *, default: Union[Any, None] =) -> networkx.classes.reportviews.InMultiEdgeDataView[_Node`1, _D`2]
Runtime: in file C:\Users\Avasam\AppData\Local\Temp\stubtest-ind4bx6n\Lib\site-packages\networkx\classes\reportviews.py:1019
def (viewer, nbunch=None, data=False, *, default=None, keys=False)

error: networkx.classes.reportviews.MultiEdgeView.dataview variable differs from runtime type abc.ABCMeta
Stub: in file E:\Users\Avasam\Documents\Git\typeshed\stubs\networkx\networkx\classes\reportviews.pyi:272
def [_Node <: typing.Hashable, _D] (viewer: Any, nbunch: Union[_Node`1, typing.Iterable[_Node`1], None] =, data: builtins.bool =, *, default: Union[Any, None] =) -> networkx.classes.reportviews.MultiEdgeDataView[_Node`1, _D`2]
Runtime: in file C:\Users\Avasam\AppData\Local\Temp\stubtest-ind4bx6n\Lib\site-packages\networkx\classes\reportviews.py:983
def (viewer, nbunch=None, data=False, *, default=None, keys=False)

error: networkx.readwrite.text.AsciiDirectedGlyphs.vertical_edge is not present in stub
Stub: in file E:\Users\Avasam\Documents\Git\typeshed\stubs\networkx\networkx\readwrite\text.pyi
MISSING
Runtime:
'!'

error: networkx.readwrite.text.AsciiUndirectedGlyphs.vertical_edge is not present in stub
Stub: in file E:\Users\Avasam\Documents\Git\typeshed\stubs\networkx\networkx\readwrite\text.pyi
MISSING
Runtime:
'|'

error: networkx.readwrite.text.UtfDirectedGlyphs.vertical_edge is not present in stub
Stub: in file E:\Users\Avasam\Documents\Git\typeshed\stubs\networkx\networkx\readwrite\text.pyi
MISSING
Runtime:
'?'

error: networkx.readwrite.text.UtfUndirectedGlyphs.vertical_edge is not present in stub
Stub: in file E:\Users\Avasam\Documents\Git\typeshed\stubs\networkx\networkx\readwrite\text.pyi
MISSING
Runtime:
'?'

Found 6 errors (checked 565 modules)

? (I assume that's just meant to be the replacement char �) should be and .
That being said, that's better than a crash.

Oh and I created a branch of typeshed running your branch to see if anything else comes up through the CI: Avasam/typeshed#44
Edit: oh shoot, mypy's main branch doesn't currently pass on typeshed and networkx is tested on linux there XD

Well you have my local results above.

@sterliakov
Copy link
Collaborator Author

sterliakov commented May 13, 2025 via email

@Avasam
Copy link
Contributor

Avasam commented May 13, 2025

Regarding question mark vs replacement character, does it exist in CP1252?

VSCode saves it in "Western (Windows 1252)" as byte 0x9D/157. Which https://www.fileformat.info/info/charset/windows-1252/list.htm doesn't list and https://www.w3schools.com/charsets/ref_html_ansi.asp marks as NOT USED.

image

@sterliakov
Copy link
Collaborator Author

sterliakov commented May 13, 2025 via email

@Avasam
Copy link
Contributor

Avasam commented May 13, 2025

Is this solution good enough for your use case?

Yeah, it definitely is. It's rare enough. And a "unknown character" representation is much, much better than a crash. It's also not too hard to connect the dots and understand why the console is showing ?. Anyway in most cases where stubtest is run, you wouldn't want to copy that exact character.

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

Successfully merging this pull request may close these issues.

stubtest crash with special unicode characters
2 participants