-
Notifications
You must be signed in to change notification settings - Fork 3
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
Fix display of non-indexable attribute values #410
base: main
Are you sure you want to change the base?
Conversation
Reviewer's Guide by SourceryThis pull request fixes a bug where global attributes with values that cannot be indexed were displayed as "empty". The fix involves outputting the value repr without additional processing when an IndexError occurs, ensuring that scalar types like float, int, and bool are displayed correctly. Sequence diagram for global attribute value display processsequenceDiagram
participant Client
participant NCDump
participant NCFile
Client->>NCDump: print_global_attrs()
NCDump->>NCFile: getncattr(nc_attr)
NCFile-->>NCDump: ncattr_value
alt value is indexable
NCDump->>NCDump: process and format value
else value is not indexable (IndexError)
NCDump->>NCDump: format using repr(ncattr_value)
end
NCDump-->>Client: display formatted attribute
Flow diagram for attribute value processingflowchart TD
A[Get attribute value] --> B{Can value be indexed?}
B -->|Yes| C[Process value normally]
B -->|No| D[Use repr of value]
C --> E[Display formatted value]
D --> E
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @leroyvn - I've reviewed your changes - here's some feedback:
Overall Comments:
- The approach of catching an IndexError to determine non-indexable attributes works, but it might be clearer to check the type of ncattr_value before attempting to index it. For example, using isinstance(ncattr_value, (list, tuple, str)) would avoid relying on exceptions for control flow.
- The change to use f-string formatting improves readability. However, consider adding a brief inline comment explaining why using repr(ncattr_value) is appropriate here for non-indexable types, to help future maintainers understand the intent.
Here's what I looked at during the review
- 🟢 General issues: all looks good
- 🟢 Security: all looks good
- 🟢 Testing: all looks good
- 🟢 Complexity: all looks good
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Hi, this is a tentative fix for a bug where global attributes with values that cannot be indexed would be displayed as "empty." This is problematic when an attribute value has a scalar type (e.g. float, int, bool...).
I don't know the criteria for flagging an attribute as "empty", so I simply output the value repr without additional processing (empty strings should by displayed as
''
). If this behaviour is not desirable, I'll be happy to change it.Example
Before:
![image](https://private-user-images.githubusercontent.com/34740232/410394180-b061a25e-5394-4a9c-84f1-e171cad3c498.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk1NTU2ODksIm5iZiI6MTczOTU1NTM4OSwicGF0aCI6Ii8zNDc0MDIzMi80MTAzOTQxODAtYjA2MWEyNWUtNTM5NC00YTljLTg0ZjEtZTE3MWNhZDNjNDk4LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTQlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjE0VDE3NDk0OVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWE5MDk5NDRmMjk0NGNiZjc0MGQxMmYwYjYyNDA3NDcwYTg1ZGViNTlkMmMyZmJiNmQ4MWZkMjIxMjdiOGNlMTMmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.KoYdT2i9OyfiT0bOqx3GehPv1jmOVkIKlHgAOUX7vSw)
After:
![image](https://private-user-images.githubusercontent.com/34740232/410394446-1c9945b8-e9bb-4c8f-ac1d-7a826c0e97c9.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk1NTU2ODksIm5iZiI6MTczOTU1NTM4OSwicGF0aCI6Ii8zNDc0MDIzMi80MTAzOTQ0NDYtMWM5OTQ1YjgtZTliYi00YzhmLWFjMWQtN2E4MjZjMGU5N2M5LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTQlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjE0VDE3NDk0OVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWU4MzgwMGEzMTI3NWY5YmFiNjRkNTk2OWNjODZkNjJmNWI3MjMyYmY3MmMzYzc1NjVkNmU0MGMwNWM5NGExMGYmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.gnv20aTr-nhcTZumQoPirQEM2Y09zYSjwITwJenqWpw)
Summary by Sourcery
Bug Fixes: