Skip to content
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

Anticipate snapshot changes #43

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

ewuerger
Copy link
Member

@ewuerger ewuerger commented May 2, 2023

This PR anticipates the structural changes to the snapshot interface. There are no long_names anymore in the data_types section. Instead only id's are used.

@ewuerger ewuerger self-assigned this May 2, 2023
@ewuerger ewuerger force-pushed the anticipate-snapshot-changes branch from 71a84e9 to e8bd562 Compare May 2, 2023 11:20
@ewuerger ewuerger requested review from Wuestengecko and jamilraichouni and removed request for Wuestengecko May 2, 2023 11:20
@@ -10,20 +10,12 @@ modules:
- id: project/space/example title
long_name: example title
data_types: # Enumeration Data Type Definitions
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think at this point it might make sense to actually rename the data_types key to enumerations or something, because that's really all that is here. data_types suggests that there might be more to it, like "subtype of integer"-style things such as a "UserID".

And similarly below: Currently the type_id key is used to reference the definitions in data_types; that could be renamed to, say, enum_def (or long form enumeration_definition, or simply just enumeration?).

Comment on lines +13 to +32
- identifier: eType
long_name: eType
values:
- identifier: unset
long_name: Unset
promise_id: EnumValue type unset
long_name: unset
promise_id: EnumValue eType unset
- identifier: functional
long_name: Functional
promise_id: EnumValue type functional
promise_id: EnumerationDataTypeDefinition type
long_name: functional
promise_id: EnumValue eType functional
promise_id: EnumerationDataTypeDefinition eType
_type: EnumerationDataTypeDefinition
- identifier: release
long_name: Release
- identifier: eRelease
long_name: eRelease
values:
- identifier: featureRel.1
long_name: Feature Rel. 1
promise_id: EnumValue release featureRel.1
long_name: featureRel.1
promise_id: EnumValue eRelease featureRel.1
- identifier: featureRel.2
long_name: Feature Rel. 2
promise_id: EnumValue release featureRel.2
promise_id: EnumerationDataTypeDefinition release
long_name: featureRel.2
promise_id: EnumValue eRelease featureRel.2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks odd, are identifier and long_name supposed to be the same now? I thought identifier was the internal unique ID and long_name the user-facing descriptive text.

@@ -143,6 +127,10 @@
"multi_values": {
"description": "Whether the Enum Attribute can have multiple values (true) or must always have exactly one value (false).",
"type": "boolean"
},
"type_id": {
"description": "The EnumerationDataTypeDefinition identifier for assication of the available options.",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo.

Suggested change
"description": "The EnumerationDataTypeDefinition identifier for assication of the available options.",
"description": "The EnumerationDataTypeDefinition identifier for association of the available options.",

Comment on lines +63 to 69
"items": {
"patternProperties": {
".": {
"type": "string"
}
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I'm not mistaken, this schema would ask for:

data_types:
  something:
    - some_key: a string
      other_key: another string
    - third_key: more string

What we actually have in the tests is:

data_types:
  something:
    - a string
    - another string

Which would mean, in terms of a schema:

Suggested change
"items": {
"patternProperties": {
".": {
"type": "string"
}
}
}
"items": {
"type": "string"
}

@@ -1208,8 +1235,24 @@ def attribute_definition_mod_action(
mods["long_name"] = data["long_name"]
if data["type"] == "Enum":
dtype = attrdef.data_type
if dtype is None or dtype.identifier != identifier:
mods["data_type"] = identifier
dtid = data["type_id"] # type:ignore[typeddict-item]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can avoid this type: ignore (and the second one further down on line 1258) by changing the definitions of act.AttributeDefinition and act.EnumAttributeDefinition like this:

class AttributeDefinition(te.TypedDict):
    long_name: str
    type: t.Literal["Boolean", "Date", "Float", "Integer", "String"]

class EnumAttributeDefinition(te.TypedDict, total=False):
    long_name: te.Required[str]
    type: te.Required[t.Literal["Enum"]]
    values: list[str]
    multi_values: bool
    type_id: str

This enables the same either-or logic that the JSON schema also uses, and allows mypy to discriminate between the two cases with the above check of if data["type"] == "Enum".


the same either-or logic that the JSON schema also uses

Taking this thought a step further, there actually appears to be a project out there which aims to generate Python types from a JSON schema. This might be worth a look at, so that we don't have to maintain the same information in two places and formats manually.

https://github.com/sbrunner/jsonschema-gentypes

It can also be configured as pre-commit hook, however I haven't yet looked at it in detail - it might as well turn out to not be suited (or too limited) for our use case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants