Skip to content

Commit

Permalink
coverage is 100%
Browse files Browse the repository at this point in the history
tried integrating mypy but that's going to be it's own massive project
  • Loading branch information
redruin1 committed Nov 22, 2023
1 parent 5e9c157 commit 41d4a38
Show file tree
Hide file tree
Showing 198 changed files with 8,273 additions and 3,803 deletions.
31 changes: 30 additions & 1 deletion TODO.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,35 @@
# TODO

### For backwards compat, allow indexing a blueprintable to point to its `_root[_root_item]` sub-index instead of it's true `_root`?
### Redo validation (again)
Swapping to Pydantic was very illuminating in the benefits that it can provide:

* Ergonomic class definitions to define schemas (very nice)
* Being able to inject custom functions at any point of the validation process to massage inputs, discredit validation, and add new criteria (possibly on the fly!) This is probably going to be required by any further implementation going forward
* All of these validation functions are localized to the classes that use them, and everything is in one place; only a single method has to be called for any member modification.
* Validation backend is written in Rust for speed (tempting)

However, it is still not quite entirely perfect:

* RootModel syntax cannot be serialized if not in the correct model format (unacceptable, currently this is sidestepped but suboptimal)
* RootModel syntax is unwieldly; everything is accessed via it's `root` attribute and any methods that you would want to use on `root` have to be reimplemented in the parent class
* I HAVE to use RootModels if I want to be able to reliably validate these members (and ideally propagate their `is_valid` flags)
* Per instance validate assignment is not permitted (even though totally functional), meaning I have to use the model's backend which might be subject to change
* No in-built handling for warnings, which ideally would behave very similarly to errors as Pydantic currently implements them

Based on my search, I can't think of a validation library that has all of these features at once, implying that I would have to roll my own. I'm not really looking forward to this, and especially not to *testing* it, so if there is one out there please message me.

---

### Validation caching
Ideally, whether or not a entity or blueprint is considered valid can be retained as long as the entity does not change after validation. For example, if you validate a single entity, and then add that entity to a blueprint 1000 times, you only have to validate the attributes of the blueprint itself, since the entities are guaranteed to already be in a valid state. Ideally, each exportable object would have a `is_valid` attribute which would be set to false when an attribute is set, which can then be quickly checked in any parent
`validate()` function.

### Integrate with `mypy`

### Revamp the `add_x` data functions so that they support more features
* Inline sorting
* Support additional keyword arguments in line with the prototype documentation
* Perhaps there might be a way to redesign `env.py` such that it can use the data functions, encouraging code reuse

### More elegantly handle when a prototype has no valid members (like `LinkedBelt`)

Expand Down
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
* Added `unknown` keyword to all entity/tile creation constructs which allows the user to specify what should happen when draftsman encounters an entity it doesn't recognize
* Changed `InvalidEntityError` and `InvalidTileErrors` so that they now try to detect a similar tile/entity name and display that information to the user in the error message
* For example, if you accidentally type `Container("wodenchest")`, it will realize you probably meant to type `Container("wooden-chest")` and suggest that to you instead
* Renamed `instruments.index` to `instruments.index_of` and `instruments.names` to `instruments.name_of` to reduce confusion with local names
* Added a bunch of new documentation to document the above
* Added a bunch of new examples to test out the above new features
* Added a fixture that ensures that Draftsman is running a vanilla configuration before running tests, and exits if it detects that it is not the case.
Expand Down
373 changes: 347 additions & 26 deletions docs/discusssion/2.0.0_release/2.0.0_release.md

Large diffs are not rendered by default.

20 changes: 18 additions & 2 deletions draftsman/classes/association.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# association.py

import weakref
from pydantic import Field, WrapValidator
from pydantic_core import core_schema

from typing import TYPE_CHECKING, Any
from typing import TYPE_CHECKING, Annotated, Any
import weakref

if TYPE_CHECKING: # pragma: no coverage
from draftsman.classes.entity import Entity
Expand All @@ -16,6 +18,16 @@ class Association(weakref.ref):
creating blueprints, and better visual representation.
"""

Format = Annotated[
int,
Field(ge=0, lt=2**64),
WrapValidator(
lambda value, handler: value
if isinstance(value, Association)
else handler(value)
),
]

def __init__(self, entity: "Entity"):
super(Association, self).__init__(entity)

Expand Down Expand Up @@ -63,3 +75,7 @@ def __repr__(self) -> str: # pragma: no coverage
" '{}'".format(self().id) if self().id is not None else "",
id(self()),
)

# @classmethod
# def __get_pydantic_core_schema__(cls, _):
# return core_schema.int_schema()
Loading

0 comments on commit 41d4a38

Please sign in to comment.