Skip to content

Pci class - #9

Open
remijouannet wants to merge 4 commits into
xsuchy:mainfrom
remijouannet:pci_class
Open

Pci class#9
remijouannet wants to merge 4 commits into
xsuchy:mainfrom
remijouannet:pci_class

Conversation

@remijouannet

Copy link
Copy Markdown

Hello,

i've added the possibility to get the information of "PCI Class" from pcis.ids database

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request extends the PCI class in hwdata.py to support parsing and retrieving PCI device classes, subclasses, and programming interfaces. It also fixes several typos in docstrings and updates example.py to demonstrate the new functionality. Feedback focuses on improving the efficiency and idiomatic nature of dictionary membership tests by removing redundant list(keys()) calls and using the 'not in' operator as per PEP 8.

Comment thread hwdata.py
else:
device_class = l[1].lower()
device_class_name = ' '.join(l[2:])
if not device_class in list(PCI.devices_class.keys()):

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Membership testing in a dictionary is more efficient when done directly on the dictionary object. Also, per PEP 8, item not in dict is preferred over not item in ....

Suggested change
if not device_class in list(PCI.devices_class.keys()):
if device_class not in PCI.devices_class:
References
  1. PEP 8 recommends using the 'not in' operator for membership tests and avoiding redundant list creation for dictionary key checks. (link)

Comment thread hwdata.py
"""
device_class = device_class.lower()
if self.cache:
if device_class in list(PCI.devices_class.keys()):

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Redundant use of list(...keys()). Membership testing should be performed directly on the dictionary for better performance and adherence to Python idioms (PEP 8).

Suggested change
if device_class in list(PCI.devices_class.keys()):
if device_class in PCI.devices_class:
References
  1. PEP 8 recommends avoiding redundant list creation for dictionary key checks. (link)

Comment thread hwdata.py
Comment on lines +262 to +263
if device_class in list(PCI.devices_class.keys()):
if subclass in list(PCI.devices_class[device_class][1].keys()):

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Redundant use of list(...keys()) for membership testing. Checking directly against the dictionary is more efficient and follows PEP 8 guidelines.

Suggested change
if device_class in list(PCI.devices_class.keys()):
if subclass in list(PCI.devices_class[device_class][1].keys()):
if device_class in PCI.devices_class:
if subclass in PCI.devices_class[device_class][1]:
References
  1. PEP 8 recommends avoiding redundant list creation for dictionary key checks. (link)

Comment thread hwdata.py
Comment on lines +281 to +283
if device_class in list(PCI.devices_class.keys()):
if subclass in list(PCI.devices_class[device_class][1].keys()):
if prog_if in list(PCI.devices_class[device_class][1][subclass][1].keys()):

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Multiple redundant calls to list(...keys()). These membership checks are more efficient when performed directly on the dictionary objects, as per PEP 8.

Suggested change
if device_class in list(PCI.devices_class.keys()):
if subclass in list(PCI.devices_class[device_class][1].keys()):
if prog_if in list(PCI.devices_class[device_class][1][subclass][1].keys()):
if device_class in PCI.devices_class:
if subclass in PCI.devices_class[device_class][1]:
if prog_if in PCI.devices_class[device_class][1][subclass][1]:
References
  1. PEP 8 recommends avoiding redundant list creation for dictionary key checks. (link)

Comment thread hwdata.py
while True:
line = f.readline()
if not line:
break

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you decide to change the for-loop to while-loop?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i did this a few months ago, i'm trying to remember why. i think it was because i've duplicate the parsing code to avoid having to fully understand it, since the pci class part is the same format. i can take a closer look to make it more logical

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok now i remember, the while-loop was for using f.readline() instead of for f.readlines(), so i can use the same loop twice without changing too much code. using readlines() force you to read the entire file in one loop. readline() retain the read offset so you can continue to read the file in another loop after a break.
do you want me to change it ?

Comment thread hwdata.py
l = line.split()

if line.startswith('# C class'):
break

@xsuchy xsuchy Apr 3, 2026

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why? Ah. I see now why. But can you document the "why" in the comment?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

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.

2 participants