8000 sys.platform and os.name don't operate as expected (cannot equality test or use startswith against shadow string) · Issue #387 · jython/jython · GitHub
[go: up one dir, main page]

Skip to content
sys.platform and os.name don't operate as expected (cannot equality test or use startswith against shadow string) #387
@mwsealey

Description

@mwsealey

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'
>>>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0