Enumap

Latest version: v1.5.0

Safety actively analyzes 621776 Python packages for vulnerabilities to keep your Python projects secure.

Scan your dependencies

1.4.0

* Errors during type casting (calls to `.map_casted` and `.tuple_casted`) will now be re-raised to the user as a `TypeCastError` that contains clearer information about which key/field was given an uncastable value
* Fixed a bug (issue 5) where sparse declarative defaults resulted in `KeyErrors`. Basically, `SparseEnumap` must always have a _complete_ dictionary of defaults. The goal of `SparseEnumap` is that you can get collections out of your data specs no matter what's missing. `SparseEnumap.set_defaults` works this way, so sparse usage of `default()` in the declarative style should work too.

Many thank to jonemo for finding bugs, suggesting fixes, and suggesting the sparse declarative default feature.

1.3.0

SparseEnumap` gets declarative default values in the style of `typing.NamedTuple`:

python

class Horse(SparseEnumap):
speckled = auto() enum.auto for auto unique values
brown = 55 not a default
shetland = default(30) both unique AND a default for tuple/map collections


Collections made from this `SparseEnumap` will have defaults for the `shetland` field:

python
>>> Horse.tuple()
Horse_tuple(speckled=None, brown=None, shetland=30)

1.2.3

A bugfix
Previously, `Enumap` allowed for too many positional args to be passed. These extra positional args were discarded silently.

Sparse types are _always_ allowed
Sparse type mappings are now allowed even for the strict, non sparse `Enumap`. This is because I think type mappings are often sparse in the real world.

Better performance for sparse, typed collections
Sparse, typed collections are up to 2x faster with realistic sparse data after some low hanging optimizations. The executive summary is that, given sparse types and sparse inputs, we save cycles by not looping over types/values that aren't provided.

1.2.1

The type mapping of `SparseEnumap` can, itself, be sparse. If a certain key doesn't have a type callable, the corresponding value (if present) won't be casted at all.

1.2.0

Faster casted collections
Casted collections made somewhat faster.

Arbitrary default values for sparse collections
`SparseEnumap` takes default values with `set_defaults`. Casted collections with missing values won't attempt to type cast the default values.

1.1.0

Made `Enumap` methods faster in general with a few strategies:

* No longer discarding temporary dictionaries in construction of name-checked mappings: they get reused as `**kwargs` in namedtuple and OrderedDict construction
* `Enumap.tuple` now attempts a normal namedtuple construction and catches a `TypeError` when duplicate or incomplete arguments are given to it. This way, the case where all data is passed to `Enumap.tuple` is as fast as possible.
* `Enumap.names` is now a cached tuple, not the slower `odict_keys` dictionary key view. A valuable side effect of this is that you can construct `Enumap`s from another `Enumap.names()`.

Links

Releases

© 2024 Safety CLI Cybersecurity Inc. All Rights Reserved.