GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||
GeezerVison is showing github.com — Fix potential usage of None and Unbound variables issues by Avasam · Pull Request #248 · python-xlib/python-xlib Conversation
|
Codecov Report
Additional details and impacted files@@ Coverage Diff @@ ## master #248 +/- ## ========================================== - Coverage 78.21% 78.16% -0.06% ========================================== Files 42 42 Lines 4705 4735 +30 ========================================== + Hits 3680 3701 +21 - Misses 1025 1034 +9 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Could I get a review on this? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@python-xlib yearly bump |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…b#248 - `Colormap.copy_colormap_and_free` works again. Its parameter was named `scr_cmap` while the body used `src_cmap`, so every call raised `NameError`. - `Resource.parse_value` and `ResourceObj.parse_value` return the raw value when no display is given. The `if not display` check was commented out, so they raised `AttributeError` on `None.get_resource_class`. - `String16.parse_binary_value` with no length field (`length=None`) reads the whole buffer, like `String8` and `Binary` already do. It used to fail on `None` arithmetic. - `Struct.to_binary` raises a `RuntimeError` naming the field when a variable size field has no `pack_value`, instead of calling `None`. - `Display.close_internal` resets the queues and buffers to empty lists and bytes instead of `None`, and returns the `ConnectionClosedError` it stores so callers raise it directly. `send_request` still raises that stored error before touching the queues. - `ReplyRequest._data` starts as an empty dict per instance, and `reply()` waits on `not self._data`. A reply always has fields, so this is equivalent to the old `is None` check. Calling `reply()` again after the response arrived is still a no-op, as its comment promises.
1fa7079 to
46f8a33
Compare
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Co-authored-by: Avasam <[email protected]>
- `Struct.__init__` collects the variable size fields that have no `pack_value`, without raising, since parse-only structs such as xinput's `DeviceEvent` must still build. `to_binary` raises one `RuntimeError` naming all of them before packing, instead of checking each field on every call. - `PropertyData.parse_binary_value` returns `None` for format 0 before computing a length, so `length=None` no longer divides by zero, and raises `BadDataError` for a format other than 0, 8, 16 or 32. `ret` is now assigned on every path without a `None` default. - Tests cover `Resource.parse_value` and `ResourceObj.parse_value` without a display, a struct with a parse-only field, `PropertyData` formats, and `Display.close_internal`, including each of its `raise self.close_internal(...)` call sites in `send_and_recv`.
`reply()` waited on `not self._data`, but `ListFontsWithInfo` stores `[]` as its reply when no font matches, so `list_fonts_with_info` with no match looped forever. The `None` check tells a missing reply apart from an empty one.
Applies 46f8a33, adapted to the stubs this package ships. - `Resource.parse_value` and `ResourceObj.parse_value` return the raw value when no display is given. The `if not display` check was commented out, so they raised `AttributeError` on `None.get_resource_class`. - `Struct.to_binary` raises a `RuntimeError` naming every variable size field that has no `pack_value`, instead of an `AttributeError`. `Struct.__init__` collects those fields once, without raising, since parse-only structs such as xinput's `DeviceEvent` must still build. - `PropertyData.parse_binary_value` returns `None` for format 0 before computing a length, so `length=None` no longer divides by zero, and raises `BadDataError` for a format other than 0, 8, 16 or 32 instead of `UnboundLocalError`. - `Display.close_internal` resets the queues and buffers to empty lists and bytes instead of `None`, and returns the `ConnectionClosedError` it stores so callers raise it directly. `send_request` still raises that stored error before touching the queues. - For type checkers: `parse_response` initializes `rtype`, and the stubs declare `Request._request`, `ReplyRequest._request`, `Event._fields` and `ClassInfoClass.check_value`, and the return type of `close_internal`. Left out from the original commit: - `Colormap.copy_colormap_and_free` was already fixed, and `XK.pyi` already re-exports the keysyms. - The `length is None` checks in `String16.parse_binary_value` and `ButtonState.parse_binary_value` were never reached, and the stubs already type `length` as not `None`. - `ReplyRequest._data` keeps starting as `None`. Waiting on `not self._data` hung `list_fonts_with_info` when no font matched, since its reply data is then `[]`. - Inline type comments moved to the stubs.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.