-
Notifications
You must be signed in to change notification settings - Fork 213
Description
I don't think the shadow string class is working as intended - the documentation states that PyShadowString:
[...] provides a string that sometimes seems to change value, as far as equality tests and startswith are concerned. This solves a problem that Jython users sometimes experience with libraries that are sensitive to platform.
A library may test for a particular platform in order to adjust to local file name conventions or to decide which operating system commands are available. In Jython, os.name and sys.platform indicate that Java is the platform, which is necessary information in some parts of the standard library, but other libraries assuming CPython then draw incorrect conclusions.
It is definitely not doing that (apologies for Jython 2.7.3 for the demo, I tested it against a newer version, but don't have that readily available right now)
Jython 2.7.3 (tags/v2.7.3:5f29801fe, Sep 10 2022, 18:52:49)
[OpenJDK 64-Bit Server VM (Microsoft)] on java21.0.1
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.platform
PyShadowString('java21.0.1', 'win32')
>>> sys.platform == 'win32'
False
>>> sys.platform == 'java21.0.1'
True
>>> sys.platform.startswith('java')
True
>>> sys.platform.startswith('win')
False
>>> sys.platform.getshadow()
'win32'
>>> import os
>>> os.name
PyShadowString('java', 'nt')
>>> os.name == 'nt'
False
>>> os.name == 'java'
True
>>> os.name.startswith('ja', 0, 2)
True
>>> os.name.startswith('nt', 0, 2)
False
>>> os.name.getshadow()
'nt'
>>>