Skip to content

Commit

Permalink
uh missed some more. no full code coverage. pronouns lol
Browse files Browse the repository at this point in the history
  • Loading branch information
bitplane committed Sep 24, 2023
1 parent 5f5e6f1 commit 3f0f35e
Showing 1 changed file with 21 additions and 22 deletions.
43 changes: 21 additions & 22 deletions arranges/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,45 +11,44 @@ It it kinda grew into a monster so I've split it out into this separate
package. The main feature is a pair of classes that can represent ranges:

* `Segment` is a class that can be treated like a `set` and its constructor is
compatible with `range` and `slice`. It is derived from `str` so serializes
without custom JSON encoders. It is immutable, hashable and has a stable
compatible with `range` and `slice`. It is derived from `str` so is easy to
compare and serializes nicely. It is immutable, hashable and has a stable
string representation.
* `Ranges` is an ordered `tuple` of `Segment`s. It is also immutable and
derived from `str` so serializes without custom JSON encoders like the above.
It can be constructed from comma-separated Python-style slice notation strings
(e.g. `"1:10, 20:"`, `"0x00:0xff` and `":"`), integers, `slice`s, `range`s,
integers and (nested) iterables of the above.
derived from `str` like the above. It can be constructed from comma-separated
Python-style slice notation strings (e.g. `"1:10, 20:"`, `"0x00:0xff` and
`":"`), integers, `slice`s, `range`s, integers and (nested) iterables of the
above.
* An `inf` singleton that is a `float` with a value of `math.inf` but has an
`__index__` that returns `sys.maxsize` and compares equal to infinity and
`maxsize`, and its string representation is `"inf"`.

The range classes are designed to be used as fields in Pydantic `BaseModel`s,
but they can be used anywhere you need a range. They are not designed with
speed in mind, and comparisons usually use the canonical string form by
converting other things into `Ranges` objects.
The range class is designed to be used as fields in Pydantic `BaseModel`s,
but can be used anywhere you need a range. They are not designed with speed in
mind, and comparisons usually use the canonical string form by converting other
things into `Ranges` objects. Their preferred pronoun is they/them.

## Constraints

I made it to select lines or bytes in a stream of data, so it:
I made them to select lines or bytes in a stream of data, so they:

* only supports `int`s;
* does not allow negative indices, the minimum is 0 and the maximum is
unbounded;
* it's compatible with `range` and `slice`, but `step` is fixed to `1`. If
* only support `int`s;
* do not allow negative indices, the minimum is 0 and the maximum is unbounded;
* are compatible with `range` and `slice`, but `step` is fixed to `1`. If
you pass something with a step into its constructor it'll be converted to
a list of `int`s (`range(0, 10, 2)` becomes `"0,2,4,6,8"`);
* does not support duplicate ranges. Ranges are merged together as they are
* do not support duplicate ranges. Ranges are merged together as they are
added to the `Ranges` object;
* it is unpydantic in that its constructors are duck-typed, which is what I
need; and
* it violates the Zen of Python by having multiple ways to do the same thing,
but it's also useful.
* they are unpydantic in that its constructors are duck-typed, which is what I
need;
* they violates the Zen of Python by having multiple ways to do the same thing,
but I found that useful; and
* Currently the interface is *unstable*, so lock the exact version in if you
don't want breaking changes.

## Installation

`pip install arranges` if you want to use it. You'll need Python 3.10 or
`pip install arranges` if you want to use them. You'll need Python 3.10 or
above.

### Dev setup
Expand All @@ -67,7 +66,7 @@ Type `make help` to see the other options, or run the one-liner scripts in the
## Usage

* [RTFM](https://bitplane.github.io/arranges/)
* Read [the tests](../arranges/tests/), which have full coverage.
* Read [the tests](../arranges/tests/)
* [Read the pydocs](../docs/pydocs.md)

## License
Expand Down

0 comments on commit 3f0f35e

Please sign in to comment.