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
help([object]) returns "Not enough memory." on standard Python types, object and object functions #64113
Comments
not sure if this ever worked. first time using help([object]), but these should work according to the documentation. OS is Win7 SP1 32-bit. Python 3.3.3 (v3.3.3:c3896275c0f6, Nov 18 2013, 21:18:40) [MSC v.1600 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> help(list)
Not enough memory.
>>> help(list())
Not enough memory.
>>> help([])
Not enough memory.
>>> help(tuple())
Not enough memory.
>>> help(())
Not enough memory.
>>> help(str.format)
Not enough memory.
>>> help(str)
Not enough memory.
>>> help(b'1234')
Not enough memory.
>>> help(str.strip)
Not enough memory.
>>> help(str.count)
Not enough memory.
|
This works in general, so there must be something odd going on with your system. |
verified issue is due to code page was set to 65001, but I set PYTHONIOENCODING to utf-8 (tried UTF-8, utf8, utf-8...etc), so I'm not sure why there is problem with code page 65001 setting code page back to ascii (non-Unicode) fixed the issue. |
I can confirm that code page 65001 is the problem using 3.3.3 on Windows 7. |
It looks like the issue comes from the "more" system command, used as a pager for the documentation. When the OEM code page is set to 65001 (ex: type "chcp 65001" in a Windows console), "more document.txt" does nothing (display nothing and exit). Try commamands: It might be related to this: |
the other issue I'm also seeing is that help() doesn't seem to take exactly an object as an optional argument. perhaps Python manual for help() should be updated according to the actual implementation? >>> help('hello')
no Python documentation found for 'hello'
>>> type('hello')
<class 'str'>
>>> a='hello'
>>> help(a)
no Python documentation found for 'hello'
|
cp65001 fails in many ways quite independent of Python.
Idle:
>>> "ሴé€㑖Ѓ⌴*"
'ሴé€㑖Ѓ⌴*'
Pasting the same string into Command Prompt (Win 7, USA, updated):
C:\Users\Terry>echo "?‚????*"
"?‚????*" C:\Users\Terry>chcp 65001 C:\Users\Terry>echo "*" help('xyz') treats string instances specially. Try 'topics' or 'LISTS'. |
For posterity for anyone that finds this old issue, I investigated this problem in the debugger in Windows 7. It turns out that more.com (the pager used by Python's help) calls MultiByteToWideChar 1 with dwFlags passed as MB_PRECOMPOSED (1), which is forbidden for UTF-8. The error message is just a generic error that incorrectly assumes decoding the byte string failed due to running out of memory. You may be happy to learn that this problem is fixed in Windows 10. Here are a few snapshots from the debugger. more.com calls SetConsoleConversions from its init function, InitializeThings:
This causes decoding byte strings to use the current console codepage instead of the system ANSI or OEM codepage. The intention here is to allow a user to correctly display a text file that's in a different encoding. The decoded text is written to the console as Unicode via WriteConsoleW. Here is the bad call where dwFlags (register rdx) is passed as MB_PRECOMPOSED (1), which is invalid for codepage 65001 (register rcx).
In Windows 10 this argument is passed as 0, the correct value. This problem occurs indirectly via a utility library named ulib.dll, which is used by Windows command-line utilities. It should only occur when console conversions are enabled. Otherwise ulib converts using the system OEM and ANSI codepages. I searched for other utilities that use ulib!WSTRING::SetConsoleConversions:
I found that find.exe is also subject to this bug in Windows 7. It fails to print the result if the console is using codepage 65001:
This works correctly in Windows 10. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: