_JujuContext.version default factory has no effect in practice.
Our current code:
@dataclasses.dataclass(frozen=True)
class _JujuContext:
...
version: JujuVersion = dataclasses.field(default_factory=lambda: JujuVersion('0.0.0'))
However, the class is never instantiated directly, instead it's create from the environment, like so:
@classmethod
def from_dict(cls, env: Mapping[str, Any]) -> _JujuContext:
return _JujuContext(
...
version=JujuVersion(env['JUJU_VERSION']),
...
)
If JUJU_VERSION is missing in the environment, the factory method dies with KeyError.
And if it is present, the value is used.
The default factory is never used.
I figure this is a valid Sunday item.
If
JUJU_VERSIONis missing in the environment, the factory method dies withKeyError.
This isn't true after the changes in #1840.
The default factory is never used.
None of the default values are currently used, because we're only using from_dict to create these objects. However, we are considering making the class public in the future, and I don't see any value in removing all the default values now just to add them back at that time. Even if we never do that, do we really gain anything?
I suggest we close this PR and if/when we make _JujuContext public look at the default values at that time.
Unassigning myself from this as this should be resolved by the API changes in the spec to make _JujuContext public. I'm leaving the issue open, but no objections if it gets closed.
Closing as I believe #1996 makes this out-of-date.