diff --git a/optype/__init__.py b/optype/__init__.py index 50d065f..94fd19d 100644 --- a/optype/__init__.py +++ b/optype/__init__.py @@ -1,6 +1,6 @@ -from importlib import metadata as _metadata +import importlib as _importlib +import importlib.metadata as _metadata -from . import copy, dataclasses, inspect, json, pickle, string, types, typing from ._core._can import ( CanAEnter, CanAEnterSelf, @@ -315,6 +315,13 @@ ) +__version__: str = _metadata.version(__package__ or __file__.split("/")[-1]) + + +def __c(s: str, k: str, /) -> str: + return "".join(chr(ord(c) ^ ord(k)) for c in s) + + __all__ = [ "CanAEnter", "CanAEnterSelf", @@ -539,8 +546,6 @@ "HasTypeParams", "HasWrapped", "__version__", - "copy", - "dataclasses", "do_abs", "do_add", "do_aiter", @@ -623,20 +628,37 @@ "do_truediv", "do_trunc", "do_xor", - "inspect", - "json", - "pickle", - "rick", - "string", - "types", - "typing", ] -__version__: str = _metadata.version(__package__ or __file__.split("/")[-1]) + +_submodules = { + "copy": "copy", + "dataclasses": "dataclasses", + "dlpack": "dlpack", + "inspect": "inspect", + "json": "json", + "numpy": "numpy", + "pickle": "pickle", + "string": "string", + "types": "types", + "typing": "typing", +} +__all__ += list(_submodules) # pyright: ignore[reportUnsupportedDunderAll] # stop digging for hidden layers and be impressed -rick = pickle +_submodules[__c("πŸ¦žπŸ¦…πŸ¦πŸ¦‡", "🧬")] = __c("🀒🀻🀱🀹🀾🀷", "πŸ₯’") def __dir__() -> list[str]: return __all__ + + +def __getattr__(name: str) -> object: + if submodule := _submodules.get(name): + return _importlib.import_module(f"{__name__}.{submodule}") + try: + return globals()[name] # pyright: ignore[reportAny] + except KeyError: + msg = f"module '{__name__}' has no attribute '{name}'" + module = _importlib.import_module(__name__) + raise AttributeError(msg, name=name, obj=module) from None diff --git a/optype/__init__.pyi b/optype/__init__.pyi new file mode 100644 index 0000000..429c76b --- /dev/null +++ b/optype/__init__.pyi @@ -0,0 +1,643 @@ +from . import ( + copy, + dataclasses, + inspect, + json, + numpy, + pickle, + string, + types, + typing, +) +from ._core._can import ( + CanAEnter, + CanAEnterSelf, + CanAExit, + CanAIter, + CanAIterSelf, + CanANext, + CanAbs, + CanAbsSelf, + CanAdd, + CanAnd, + CanAsyncWith, + CanAsyncWithSelf, + CanAwait, + CanBool, + CanBuffer, + CanBytes, + CanCall, + CanCeil, + CanComplex, + CanContains, + CanDelattr, + CanDelete, + CanDelitem, + CanDir, + CanDivmod, + CanEnter, + CanEnterSelf, + CanEq, + CanExit, + CanFloat, + CanFloor, + CanFloordiv, + CanFormat, + CanGe, + CanGet, + CanGetMissing, + CanGetattr, + CanGetattribute, + CanGetitem, + CanGt, + CanHash, + CanIAdd, + CanIAddSelf, + CanIAnd, + CanIAndSelf, + CanIFloordiv, + CanIFloordivSelf, + CanILshift, + CanILshiftSelf, + CanIMatmul, + CanIMatmulSelf, + CanIMod, + CanIModSelf, + CanIMul, + CanIMulSelf, + CanIOr, + CanIOrSelf, + CanIPow, + CanIPowSelf, + CanIRshift, + CanIRshiftSelf, + CanISub, + CanISubSelf, + CanITruediv, + CanITruedivSelf, + CanIXor, + CanIXorSelf, + CanIndex, + CanInt, + CanInvert, + CanInvertSelf, + CanIter, + CanIterSelf, + CanLe, + CanLen, + CanLengthHint, + CanLshift, + CanLt, + CanMatmul, + CanMissing, + CanMod, + CanMul, + CanNe, + CanNeg, + CanNegSelf, + CanNext, + CanOr, + CanPos, + CanPosSelf, + CanPow, + CanPow2, + CanPow3, + CanRAdd, + CanRAnd, + CanRDivmod, + CanRFloordiv, + CanRLshift, + CanRMatmul, + CanRMod, + CanRMul, + CanROr, + CanRPow, + CanRRshift, + CanRSub, + CanRTruediv, + CanRXor, + CanReleaseBuffer, + CanRepr, + CanReversed, + CanRound, + CanRound1, + CanRound2, + CanRshift, + CanSequence, + CanSet, + CanSetName, + CanSetattr, + CanSetitem, + CanStr, + CanSub, + CanTruediv, + CanTrunc, + CanWith, + CanWithSelf, + CanXor, +) +from ._core._do import ( + do_abs, + do_add, + do_aiter, + do_and, + do_anext, + do_bool, + do_bytes, + do_call, + do_ceil, + do_complex, + do_contains, + do_delattr, + do_delitem, + do_dir, + do_divmod, + do_eq, + do_float, + do_floor, + do_floordiv, + do_format, + do_ge, + do_getattr, + do_getitem, + do_gt, + do_hash, + do_iadd, + do_iand, + do_ifloordiv, + do_ilshift, + do_imatmul, + do_imod, + do_imul, + do_index, + do_int, + do_invert, + do_ior, + do_ipow, + do_irshift, + do_isub, + do_iter, + do_itruediv, + do_ixor, + do_le, + do_len, + do_length_hint, + do_lshift, + do_lt, + do_matmul, + do_missing, + do_mod, + do_mul, + do_ne, + do_neg, + do_next, + do_or, + do_pos, + do_pow, + do_radd, + do_rand, + do_rdivmod, + do_repr, + do_reversed, + do_rfloordiv, + do_rlshift, + do_rmatmul, + do_rmod, + do_rmul, + do_ror, + do_round, + do_rpow, + do_rrshift, + do_rshift, + do_rsub, + do_rtruediv, + do_rxor, + do_setattr, + do_setitem, + do_str, + do_sub, + do_truediv, + do_trunc, + do_xor, +) +from ._core._does import ( + DoesAIter, + DoesANext, + DoesAbs, + DoesAdd, + DoesAnd, + DoesBool, + DoesBytes, + DoesCall, + DoesCeil, + DoesComplex, + DoesContains, + DoesDelattr, + DoesDelitem, + DoesDir, + DoesDivmod, + DoesEq, + DoesFloat, + DoesFloor, + DoesFloordiv, + DoesFormat, + DoesGe, + DoesGetattr, + DoesGetitem, + DoesGt, + DoesHash, + DoesIAdd, + DoesIAnd, + DoesIFloordiv, + DoesILshift, + DoesIMatmul, + DoesIMod, + DoesIMul, + DoesIOr, + DoesIPow, + DoesIRshift, + DoesISub, + DoesITruediv, + DoesIXor, + DoesIndex, + DoesInt, + DoesInvert, + DoesIter, + DoesLe, + DoesLen, + DoesLengthHint, + DoesLshift, + DoesLt, + DoesMatmul, + DoesMissing, + DoesMod, + DoesMul, + DoesNe, + DoesNeg, + DoesNext, + DoesOr, + DoesPos, + DoesPow, + DoesRAdd, + DoesRAnd, + DoesRDivmod, + DoesRFloordiv, + DoesRLshift, + DoesRMatmul, + DoesRMod, + DoesRMul, + DoesROr, + DoesRPow, + DoesRRshift, + DoesRSub, + DoesRTruediv, + DoesRXor, + DoesRepr, + DoesReversed, + DoesRound, + DoesRshift, + DoesSetattr, + DoesSetitem, + DoesStr, + DoesSub, + DoesTruediv, + DoesTrunc, + DoesXor, +) +from ._core._has import ( + HasAnnotations, + HasClass, + HasCode, + HasDict, + HasDoc, + HasFunc, + HasMatchArgs, + HasModule, + HasName, + HasNames, + HasQualname, + HasSelf, + HasSlots, + HasTypeParams, + HasWrapped, +) + +__all__ = [ + "CanAEnter", + "CanAEnterSelf", + "CanAExit", + "CanAIter", + "CanAIterSelf", + "CanANext", + "CanAbs", + "CanAbsSelf", + "CanAdd", + "CanAnd", + "CanAsyncWith", + "CanAsyncWithSelf", + "CanAwait", + "CanBool", + "CanBuffer", + "CanBytes", + "CanCall", + "CanCeil", + "CanComplex", + "CanContains", + "CanDelattr", + "CanDelete", + "CanDelitem", + "CanDir", + "CanDivmod", + "CanEnter", + "CanEnterSelf", + "CanEq", + "CanExit", + "CanFloat", + "CanFloor", + "CanFloordiv", + "CanFormat", + "CanGe", + "CanGet", + "CanGetMissing", + "CanGetattr", + "CanGetattribute", + "CanGetitem", + "CanGt", + "CanHash", + "CanIAdd", + "CanIAddSelf", + "CanIAnd", + "CanIAndSelf", + "CanIFloordiv", + "CanIFloordivSelf", + "CanILshift", + "CanILshiftSelf", + "CanIMatmul", + "CanIMatmulSelf", + "CanIMod", + "CanIModSelf", + "CanIMul", + "CanIMulSelf", + "CanIOr", + "CanIOrSelf", + "CanIPow", + "CanIPowSelf", + "CanIRshift", + "CanIRshiftSelf", + "CanISub", + "CanISubSelf", + "CanITruediv", + "CanITruedivSelf", + "CanIXor", + "CanIXorSelf", + "CanIndex", + "CanInt", + "CanInvert", + "CanInvertSelf", + "CanIter", + "CanIterSelf", + "CanLe", + "CanLen", + "CanLengthHint", + "CanLshift", + "CanLt", + "CanMatmul", + "CanMissing", + "CanMod", + "CanMul", + "CanNe", + "CanNeg", + "CanNegSelf", + "CanNext", + "CanOr", + "CanPos", + "CanPosSelf", + "CanPow", + "CanPow2", + "CanPow3", + "CanRAdd", + "CanRAnd", + "CanRDivmod", + "CanRFloordiv", + "CanRLshift", + "CanRMatmul", + "CanRMod", + "CanRMul", + "CanROr", + "CanRPow", + "CanRRshift", + "CanRSub", + "CanRTruediv", + "CanRXor", + "CanReleaseBuffer", + "CanRepr", + "CanReversed", + "CanRound", + "CanRound1", + "CanRound2", + "CanRshift", + "CanSequence", + "CanSet", + "CanSetName", + "CanSetattr", + "CanSetitem", + "CanStr", + "CanSub", + "CanTruediv", + "CanTrunc", + "CanWith", + "CanWithSelf", + "CanXor", + "DoesAIter", + "DoesANext", + "DoesAbs", + "DoesAdd", + "DoesAnd", + "DoesBool", + "DoesBytes", + "DoesCall", + "DoesCeil", + "DoesComplex", + "DoesContains", + "DoesDelattr", + "DoesDelitem", + "DoesDir", + "DoesDivmod", + "DoesEq", + "DoesFloat", + "DoesFloor", + "DoesFloordiv", + "DoesFormat", + "DoesGe", + "DoesGetattr", + "DoesGetitem", + "DoesGt", + "DoesHash", + "DoesIAdd", + "DoesIAnd", + "DoesIFloordiv", + "DoesILshift", + "DoesIMatmul", + "DoesIMod", + "DoesIMul", + "DoesIOr", + "DoesIPow", + "DoesIRshift", + "DoesISub", + "DoesITruediv", + "DoesIXor", + "DoesIndex", + "DoesInt", + "DoesInvert", + "DoesIter", + "DoesLe", + "DoesLen", + "DoesLengthHint", + "DoesLshift", + "DoesLt", + "DoesMatmul", + "DoesMissing", + "DoesMod", + "DoesMul", + "DoesNe", + "DoesNeg", + "DoesNext", + "DoesOr", + "DoesPos", + "DoesPow", + "DoesRAdd", + "DoesRAnd", + "DoesRDivmod", + "DoesRFloordiv", + "DoesRLshift", + "DoesRMatmul", + "DoesRMod", + "DoesRMul", + "DoesROr", + "DoesRPow", + "DoesRRshift", + "DoesRSub", + "DoesRTruediv", + "DoesRXor", + "DoesRepr", + "DoesReversed", + "DoesRound", + "DoesRshift", + "DoesSetattr", + "DoesSetitem", + "DoesStr", + "DoesSub", + "DoesTruediv", + "DoesTrunc", + "DoesXor", + "HasAnnotations", + "HasClass", + "HasCode", + "HasDict", + "HasDoc", + "HasFunc", + "HasMatchArgs", + "HasModule", + "HasName", + "HasNames", + "HasQualname", + "HasSelf", + "HasSlots", + "HasTypeParams", + "HasWrapped", + "__version__", + "copy", + "dataclasses", + "do_abs", + "do_add", + "do_aiter", + "do_and", + "do_anext", + "do_bool", + "do_bytes", + "do_call", + "do_ceil", + "do_complex", + "do_contains", + "do_delattr", + "do_delitem", + "do_dir", + "do_divmod", + "do_eq", + "do_float", + "do_floor", + "do_floordiv", + "do_format", + "do_ge", + "do_getattr", + "do_getitem", + "do_gt", + "do_hash", + "do_iadd", + "do_iand", + "do_ifloordiv", + "do_ilshift", + "do_imatmul", + "do_imod", + "do_imul", + "do_index", + "do_int", + "do_invert", + "do_ior", + "do_ipow", + "do_irshift", + "do_isub", + "do_iter", + "do_itruediv", + "do_ixor", + "do_le", + "do_len", + "do_length_hint", + "do_lshift", + "do_lt", + "do_matmul", + "do_missing", + "do_mod", + "do_mul", + "do_ne", + "do_neg", + "do_next", + "do_or", + "do_pos", + "do_pow", + "do_radd", + "do_rand", + "do_rdivmod", + "do_repr", + "do_reversed", + "do_rfloordiv", + "do_rlshift", + "do_rmatmul", + "do_rmod", + "do_rmul", + "do_ror", + "do_round", + "do_rpow", + "do_rrshift", + "do_rshift", + "do_rsub", + "do_rtruediv", + "do_rxor", + "do_setattr", + "do_setitem", + "do_str", + "do_sub", + "do_truediv", + "do_trunc", + "do_xor", + "inspect", + "json", + "numpy", + "pickle", + "string", + "types", + "typing", +] + +__version__: str = ... +rick = pickle diff --git a/pyproject.toml b/pyproject.toml index 33ee006..f2ba9c3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -121,6 +121,7 @@ venv = ".venv" typeCheckingMode = "all" useLibraryCodeForTypes = false enableReachabilityAnalysis = false +reportShadowedImports = false # buggy reportUnreachable = false # nothing wrong with `if sys.version_info() >= ...` reportUnusedCallResult = false # https://github.com/microsoft/pyright/issues/8650 reportUnusedImport = false # dupe of F401