Skip to content

Do not assume that assertions are enabled#90

Open
jfly wants to merge 1 commit into
wuub:mainfrom
jfly:do-not-assume-assertions-are-enabled
Open

Do not assume that assertions are enabled#90
jfly wants to merge 1 commit into
wuub:mainfrom
jfly:do-not-assume-assertions-are-enabled

Conversation

@jfly

@jfly jfly commented Dec 29, 2021

Copy link
Copy Markdown

Trying to access self._scenes_cache only works after self.scenes()
has been invoked. Normally, the previous line of code (assert scene_name in self.scenes()) would cause an invocation of
self.scenes() (and thereby populate self._scenes_cache), but that
doesn't actually happen if assertions are disabled!

Before this change

$ PYTHONOPTIMIZE=1 python -c 'import rxv; rxv.RXV("http://receiver/YamahaRemoteControl/ctrl").scene = "BD/DVD"; print("success!")'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/jeremy/src/github.com/wuub/rxv/rxv/rxv.py", line 457, in scene
    scene_number = self._scenes_cache.get(scene_name)
AttributeError: 'NoneType' object has no attribute 'get'

After this change

$ PYTHONOPTIMIZE=1 python -c 'import rxv; rxv.RXV("http://receiver/YamahaRemoteControl/ctrl").scene = "BD/DVD"; print("success!")'
success!

Trying to access `self._scenes_cache` only works after `self.scenes()`
has been invoked. Normally, the previous line of code (`assert
scene_name in self.scenes()`) would cause an invocation of
`self.scenes()` (and thereby populate `self._scenes_cache`), but that
doesn't actually happen if assertions are disabled!

Before this change
==================

    $ PYTHONOPTIMIZE=1 python -c 'import rxv; rxv.RXV("http://receiver/YamahaRemoteControl/ctrl").scene = "BD/DVD"; print("success!")'
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/home/jeremy/src/github.com/wuub/rxv/rxv/rxv.py", line 457, in scene
        scene_number = self._scenes_cache.get(scene_name)
    AttributeError: 'NoneType' object has no attribute 'get'

After this change
=================

    $ PYTHONOPTIMIZE=1 python -c 'import rxv; rxv.RXV("http://receiver/YamahaRemoteControl/ctrl").scene = "BD/DVD"; print("success!")'
    success!
@jfly

jfly commented May 4, 2022

Copy link
Copy Markdown
Author

@wuub any chance of getting this merged up?

@jfly

jfly commented Oct 29, 2023

Copy link
Copy Markdown
Author

@wuub quick ping!

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

Successfully merging this pull request may close these issues.

1 participant