Skip to content

Deprecate attribute based IO operations, like v = var.raw #355

Closed
@sveinse

Description

@sveinse

I'd like to propose to deprecate the uses of attribute based operations, e.g. value = var.raw or var.raw = 32 throughout canopen. The problem with the existing implementation is that some of these attr getters and setters end up in IO operations towards the CAN system. This makes it very opaque if the attr ops are "local", i.e. fetching data from the class, vs. doing remote operations. A more explicit API will make it easier to understand when IO happens and it makes the code more portable.

I have created a PR-ready proposal here:

https://github.com/sveinse/canopen-asyncio/tree/feature-deprecate-attr-ops

Compared to canopen master:

master...sveinse:canopen-asyncio:feature-deprecate-attr-ops

All attribute getters and setters in canopen are replaced with explicit methods, .e.g. var.get_raw() and var.set_raw(). The proposal doesn't alter or break the existing attr-based API, but it prints a deprecation warning if used.

I am well aware and understand that this proposal might be controversial. There are advantages to keeping the attr based operations. Its simple and it allows good duck-typing for e.g. local and remote nodes and it has been this way in canopen for a long time. However, this methodology is very implicit. It is difficult to spot when an attr operation results in blocking IO. This type of change will become necessary when porting to async, since async getters and setters is not a thing.

Should I proceed with creating a PR for this change, or is there need to discuss the topic?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions