-
Notifications
You must be signed in to change notification settings - Fork 669
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
Feature request: Access to _lookup #330
Comments
This is a good idea. Alternative #1 is not great because How about an |
I don't think Enum will work here, member names can't have spaces. This works -
This doesn't -
|
Right, but the enum type can implement |
I didn't know that, thanks. The approach below might be simpler and it avoids the _lookup.py would look like this -
We would need to update core.py -
Plus a few other minor changes. Thoughts? If you are OK with this I can submit a pull request. |
I was thinking of returing the enumerations directly (for example from In this context, the main issue I see with # intenums.py
from enum import IntEnum
class _CustomNamedEnum(IntEnum):
def __new__(cls, value, human_name):
member = int.__new__(cls, value)
member._value_ = value
member._human_name = human_name
return member
def __str__(self):
return self._human_name
class DeviceClasses(_CustomNamedEnum):
SPECIFIED_AT_INTERFACE = (0x0, "Specified at interface")
COMUNICATIONS_DEVICE = (0x2, "Communications Device")
HUB = (0x9, "Hub")
PERSONAL_HEALTHCARE_DEVICE = (0xf, "Personal Healthcare Device")
DIAGNOSTIC_DEVICE = (0xdc, "Diagnostic Device")
WIRELESS_CONTROLLER = (0xe0, "Wireless Controller")
MISCELLANEOUS = (0xef, "Miscellaneous")
VENDOR_SPECIFIC = (0xff, "Vendor-specific")
def test_basic_enum_api():
some_class = DeviceClasses.HUB
assert some_class == DeviceClasses.HUB
assert some_class.value == 9
assert some_class.name == "HUB"
assert str(some_class) == "Hub"
def test_comparison_with_int():
some_class = DeviceClasses.HUB
assert some_class == 9
def test_lookup_on_int_dict():
some_class = DeviceClasses.HUB
table = { 9: "Hub Device" }
assert table[some_class] == "Hub Device"
While the above worked, renaming the file and replacing the beginning with: # enums.py
from enum import Enum
class _CustomNamedEnum(bytes, Enum):
def __new__(cls, value, human_name):
member = bytes.__new__(cls, [value])
[...] results in:
P.S. I was wrong and Apart from this, I think the enum names should be kept as valid Python identifiers. But there may be no need for a field like (I thought about doing something like I'm fine with the use of the functional API, I didn't use it simply out of habit.
Please do! We can check and work on any remaining (or new issues if the CI complains) there. |
Hm, is it legal for a USB device to return an undefined value, say If that's the case (with any of the affected tables) we would need to implement |
Would you be comfortable with accepting a pull request implementing this as I described above for now? That approach already manages for device id's not in a table by returning default. I'll commit to delivering a new pull request that re-implements this to return it as a property of |
We shouldn't create a public interface just to deprecate it in three months. And as a private interface (=which a user could rely on at their own risk), I don't see a benefit over just using the current I also made a mistake in suggesting the use of enums: while |
@jonasmalacofilho sounds good. I don't want to start working on a new public interface now and end up with too many merge conflicts next year. Please do me a favour and update this ticket when you think the master branch is stable enough to support me building this for 3.6+ and I'll get started. |
Ok, thanks! |
@jonasmalacofilho Just wondering if it is a good time to look at this again now. Thanks. |
I think so. |
Using this USB device as an example -
I'd like the option to get access to the value of
bDeviceClass
asHub
via some method. I can think of two ways to do this; via utils.get_string something like this -or adding a
lookup
export to usb.util something like this -where
type
would supportdescriptor | device | interface | bmattribute
.The text was updated successfully, but these errors were encountered: