Package: xju
Various modules implemented to some broad principles:fine-grained static typingpure context managementuseful functionality that is hard to use incorrectly100% test coverage(see the bottom of this readme for release history)xju.newtype- static and dynamic distinct int, float and str typesunlike typing.NewType the new types are compatible with isinstance, so you
can actually use them to do real stuff, like implement overloaded methodsseexju/newtype.py.testfor sample codexju.cmc- context managementunlike python standard library e.g. open(), these are “pure” context managers: resources
are never acquired until __enter__xju.cmc.cmclass- provides context management for class attributes that are context managersmanaging multiple resource attributes is clumsy with ExitStack, this module implements
__enter__ and __exit__ automatically to ensure correct ordering and cleanup on exceptionsseexju/cmc/cmclass.py.testfor sample codexju.cmc.Dict- dictionary that is a context manager for its (context manager) valuesseexju/cmc/Dict.py.testfor sample codexju.cmc.Opt- context manager for its optional (context manager) valueseexju/cmc/Opt.py.testfor sample codexju.cmc.async_cmclass- provides async context management for class attributes that are async / sync context managersmanaging multiple resource attributes is clumsy with AsyncExitStack, this module implements
__aenter__ and __aexit__ automatically to ensure correct ordering and cleanup on exceptionsseexju/cmc/async_cmclass.py.testfor sample codexju.cmc.AsyncDict- dictionary that is a async context manager for its (async context manager) valuesseexju/cmc/AsyncDict.py.testfor sample codexju.cmc.AsyncOpt- async context manager for its optional (async context manager) valueseexju/cmc/AsyncOpt.py.testfor sample codexju.cmc.io- pure context management for e.g. file reading and writing, non-blocking iosee unit tests for sample code:
*FileLock.py.test*FileMode.py.test*FilePosition.py.test*FileReader.py.test*FileWriter.py.test*UnixStreamListener.py.test*UnixStreamSocket.py.test*Pipe.py.testxju.cmc.tstoretime-based storage, organised as files covering time-rangesseexju/cmc/tstore.py.testfor sample codexju.cmc.perflogtime-based json-format record storage built on xju.cmc.tstorexju.cmc.Thread/Mutex/Lock/Conditionthreading primitives that encourage correct designseexju/cmc/ThreadMutexLockCondition.py.testfor sample codexju.cmc.AsyncTask/Mutex/Lock/Conditionasyncio Task/Mutex/Lock/Condition context managersseexju/cmc/Task.py.testfor sample codexju.cmc.AsyncServiceQueueasyncio thread-safe service queue, allows any thread to queue a coroutine on an event loop
so it is executed by a task in that event loopseexju/cmc/AsyncServiceQueue.py.testfor sample codexju.pqjquery-like html inspection and modificationseexju/pq.py.testfor sample codexju.assert_assert functions that capture term values e.g. x and y in Assert(x)==yseexju/assert_.py.testfor sample codexju.cmdwrapper for subprocess.Popen that captures very common usage without the option-and-flag-warren of subprocessseexju/cmd.py.testfor sample codexju.json_codecencoding/decoding type-hinted dict/list/int/bool/None/float/str/Enum and classes to and from jsondesigned to fit well with type checkingbuilt in support for xju.newtype described abovegenerates json schema equivalent schemas for typesgenerates typescript code (types, type-guards and dynamic casts) equivalentsextensible with custom encodingsseexju/json_codec.py.testfor full sample codexju.jsonschemarepresents JSON schemas as straight-foward, easy-to-read python data structures, because life’s too short for jsonschema.orgseexju/jsonschema.py.testfor sample codexju.patchminimal, simple, direct patching(/stub/mock) utility, unlike mock-warren. Because one shouldn’t need a degree to read and write a unit testseexju/patch.py.testfor sample codexju.timetype-safe time and duration classesseexju/time.py.testfor sample codexju.xnException wrapping to provide human readable context gatheringseexju/xn.py.testfor sample codeRelease History2.0.2 add xju.cmc.delay_cancellation2.0.2 add bytes support to xju.json_codec2.0.2 use class name as xn exception message where exception message is empty2.0.1 add python 3.12 support2.0.0 add xju.time.async_sleep_until()2.0.0 add xju.json_codec_mypy_plugin, avoids type: ignore against json_codec.codec()2.0.0 xn first line -> first parabreaking changexn.in_function_context now uses first paragraph of docstring
not just first line (paragraph ends at empty line); paragraph
lines are stripped and joined by single space2.0.0 add xju.newtype.Bool1.4.1 fix type hints on xju.cmc.async_cmclass and xju.cmc.cmclass1.4.0 add Enum support to xju.json_codec1.3.0 add xju.cmc.AsyncDict, like xju.cmc.Dict but async1.3.0 xju.cmc.AsyncOpt/Opt async context manager that holds an optional async context manager1.3.0 xju.cmc.Opt context manager that holds an optional context manager1.3.0 python xju.cmc add async_cmclass, like xju.cmc.cmclass; handles both async and non-async attrs1.3.0 strip leading whitespace from doc strings, for compatibility with code formatters like black1.2.13 xju.newtype Literals now handle more than one value, e.g. Literal[‘fred’,’jock’]1.2.13 xju.newtype eq/neq now follows python “you can compare apples to oranges”, rely on mypy –strict-equality (which for what it’s worth is broken at mypy 1.3.0)1.2.13 now compatible with mypy –strict-equality1.2.13 add xju.cmc.AsyncTask/Mutex/Condition/Lock (thread equivalents for asyncio); note Task deprecated, use AsyncTask1.2.13 add custom encoding facility to xju.json_codec1.2.13 add typescript aliases to json_codec generated code for xju.newtype Str/Int/Float1.2.12 fixes typescript null v object handling1.2.12 adds typescript aliases for NewStr, NewInt, NewFloat1.2.11 adds typescript –strict support and fixes typescript code generation bugs1.2.11 xju.json_codec supports Literal[int] and Literal[bool]1.2.11 xju.json_codec supports generic classes1.2.10 xju.json_codec supports typing.NewType str/int/bool/float1.2.9 xju.json_codec generates typescript equivalents1.2.9 xju.json_codec adds codec() convenience method1.2.9 xju.json_codec uses kw_args to construct classes1.2.8 xju.json_codec supports string type-hints (for foward definitions)1.2.8 xju.json_codec adds typing.Self support (for recursive types)1.2.8 xju.json_codec requires python 3.11, tested with mypy 1.1.1