You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Internally Python implements hasattr with a getattr and checks wether an AttributeError is raised or not. However, pypylon raises a LogicalErrorException which is not according to hasattr expectation.
The problem arises because the hasattr function in Python expects an AttributeError when an attribute is not present, while pypylon currently raises a _genicam.LogicalErrorException.
This is the exception that the underlying genicam model raises for missing nodes.
To address this, we propose the following solution that maintains backward compatibility while providing a path for future improvements.
Solution Overview
Introduce a Strict Mode Flag
A new flag, strict_attribute_error, will be introduced to control how missing attributes are handled.
By default, the behavior will remain the same (raising _genicam.LogicalErrorException) to avoid breaking existing code.
When strict_attribute_error is enabled, the library will raise AttributeError instead, aligning with Python's conventions.
Per-Instance and Global Configuration
Global Setting: Developers can enable strict mode globally for all objects in the library.
Per-Instance Setting: Strict mode can be enabled individually for specific objects (e.g., InstantCamera) to allow finer control.
Future Breaking Change (Next Major Version):
In the next major version release, the library will fully transition to raising AttributeError for missing attributes, removing _genicam.LogicalErrorException from this context. The strict mode flag will then be deprecated.
Changing the behavior and becoming more conforming to Python standards in the next major relase sounds like a good plan.
Not sure if a by-instance "strict mode" is really worth it. Maybe not even a global strict mode at all. Good would be in any case to deprecate the current behavior (raise LogicError).
If you make a change in the next major release perhaps a global legacy mode flag (the inverse of strict mode) (which restores the old behavior) makes sense, in case some existing code relies on the old behavior.
In the meantime you perhaps could document the not-working hasattr as known limitation?
Describe the issue:
hasattr
does not seem to work withInstantCamera
.Internally Python implements
hasattr
with agetattr
and checks wether an AttributeError is raised or not. However, pypylon raises a LogicalErrorException which is not according to hasattr expectation.As a workaround I use the following
Reproduce the code example:
Error message:
No response
Is your camera operational in Basler pylon viewer on your platform
Yes
Hardware setup & camera model(s) used
a2A2590-22gmPRO
Linux 6.1
Runtime information:
The text was updated successfully, but these errors were encountered: