-
-
Notifications
You must be signed in to change notification settings - Fork 53
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
related to: #760
Currently, the implementation for handling deprecated member variables in certain classes issues a DeprecationWarning directly within the class's constructor.
For example, in the BomMetaData class (cyclonedx/model/bom.py):
@serializable.serializable_class
class BomMetaData:
def __init__(
self, *,
... many other args ...
# Deprecated as of v1.6
manufacture: Optional[OrganizationalEntity] = None,
) -> None:
... many other codes ...
self.manufacture = manufacture
if manufacture:
warn(
'`bom.metadata.manufacture` is deprecated from CycloneDX v1.6 onwards. '
'Please use `bom.metadata.component.manufacturer` instead.',
DeprecationWarning)
However, implementing this logic within the constructor prevents the DeprecationWarning from being issued when the value is set via a setter after the instance has been generated.
Here's an example:
from cyclonedx.model.bom import BomMetaData
from cyclonedx.model.contact import OrganizationalEntity
org = OrganizationalEntity(name='me')
print('DeprecationWarning will be triggerd within construictor')
data2 = BomMetaData(manufacture=org)
print("DeprecationWarning won't be triggerd using setter after instance generated")
data2 = BomMetaData()
data2.manufacture = org
Therefore, this logic needs to be implemented within the corresponding setter.
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working