Open photonbit opened 2 months ago
Based on your suggestion, I have summarized the following points that need to be modified:
Based on your suggestion, I have summarized the following points that need to be modified:
- Pydantic V2 compliance:Pydantic V2 way of configuring the class is using a model_config of type ConfigDict, instead of defining a Config class.
- Class properties harmonization: The proposal is to use snake case in all the properties, allowing the alias_generator = to_camel of the base class to operate. I will make modifications based on your suggestions.
- Default values: I have set default values for all optional parameters in all_types
- Incorrect / incomplete type definition: I will pay attention to checking the definition of the class in the future.
- Separate the code and the example files.
- Restore to the original basic_types and extended-types modes to prevent damage to backward compatibility. I will make revisions to each of these issues in the future. Thank you for your valuable suggestions.
Hello!
From all the mentioned ones, the 6. is the one it might be best just to continue with the all_types approach and at a later stage make the division in different files. The mention about backwards compatibility was something to take into account in the future, but at the current stage is not that important as the library was in a non installable state in previous versions.
I can happily help with any of the tasks :smile_cat:
I made this pull request from the work of making the tests pass.
The work in this pull request is outdated after https://github.com/openrsgis/pytdml/pull/15 was merged.
The changes on that pull request are really difficult to grasp, as the code was moved and heavily modified in a single commit.
The present pull request includes items that I think should be included in the mainstream classes.
Pydantic V2 compliance
Pydantic V2 way of configuring the class is using a model_config of type ConfigDict, instead of defining a Config class.
It also changes the way to serialize and de-serialize the models, using
model_dump
instead ofdict
, for example, or usingmin_length
instead ofmin_items
Extended base class functionality
Some io functionality was added to the base class, like reading from a yaml or json file, handling exclude_none and exclude_none on
model_dump
Class properties harmonization
Some of the properties were written using camel case and others snake case. The base type allows to define the properties in snake case, as it is customary in python, while at the same time being able to both read and write the io operations correctly according to the standard, that is in camel case.
The proposal is to use snake case in all the properties, allowing the
alias_generator = to_camel
of the base class to operate.Default values
Most of the Optional properties did not have a default value, which is the cause of the point 2 in the issue https://github.com/openrsgis/pytdml/issues/11
Other optional values had a default of a list, an empty string or a minimum number of elements, while they should be initialized with
None
and later automatically remove the properties withNone
values when serializing.Incorrect / incomplete type definition
Some types were updated to comply with the 1.0 encoding, I see some of those updated in the
all_types
, but I am not sure about all the changes, as the new work is in a new file with a different order.I am opening this pull request as a Draft, because it is meant to start a conversation and not to be merged right away.