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

Unexpected behavior by TypeError in query_xinput method #8674

Open
marinelay opened this issue Apr 8, 2024 · 0 comments
Open

Unexpected behavior by TypeError in query_xinput method #8674

marinelay opened this issue Apr 8, 2024 · 0 comments

Comments

@marinelay
Copy link
Contributor

marinelay commented Apr 8, 2024

Software Versions

  • Python: 3.9.18
  • OS: Ubuntu 22.04
  • Kivy: 2.3.0
  • Kivy installation method: pip install

Describe the bug
I found a potential unexpected behavior due to a TypeError between str and bytes in query_xinput function.

def query_xinput():
global _cache_xinput
if _cache_xinput is None:
_cache_xinput = []
devids = getout('xinput', '--list', '--id-only')
for did in devids.splitlines():
devprops = getout('xinput', '--list-props', did)
evpath = None
for prop in devprops.splitlines():
prop = prop.strip()
if (prop.startswith(b'Device Enabled') and
prop.endswith(b'0')):
evpath = None
break
if prop.startswith(b'Device Node'):
try:
evpath = prop.split('"')[1]
except Exception:
evpath = None
if evpath:
_cache_xinput.append(evpath)

The variable prop is bytes type, but this code is trying to split it using string type, such as prop.split('"')[1] at line 132.
This always raise TypeError, so evpath is always None type when prop.startswith(b'Device Node') is true.
I believe it is a miss point when supporting Python 3.x (related issue #3373 and pr #3417).

Expected behavior
prop.split(b'"')[1]

To Reproduce
I regret to say that I can't reproduce this error because I found this bug through my type checker.
Nevertheless, I report this issue because I think it is the miss point when changing string to bytes.
If this is not indeed a bug, I apologize for any inconvenience caused.

Thank you.

Code and Logs and screenshots

def query_xinput():
global _cache_xinput
if _cache_xinput is None:
_cache_xinput = []
devids = getout('xinput', '--list', '--id-only')
for did in devids.splitlines():
devprops = getout('xinput', '--list-props', did)
evpath = None
for prop in devprops.splitlines():
prop = prop.strip()
if (prop.startswith(b'Device Enabled') and
prop.endswith(b'0')):
evpath = None
break
if prop.startswith(b'Device Node'):
try:
evpath = prop.split('"')[1]
except Exception:
evpath = None
if evpath:
_cache_xinput.append(evpath)

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

No branches or pull requests

1 participant