-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Bindings for libpython -- -- These bindings allow Haskell code to call CPython code. It is not -- currently possible to call Haskell code from CPython, but this feature -- is planned. @package cpython @version 3.9.0 module CPython.Constants none :: IO SomeObject -- | The Python True object. -- -- The Python None object, denoting lack of value. true :: IO SomeObject -- | The Python False object. false :: IO SomeObject isNone :: SomeObject -> IO Bool isTrue :: SomeObject -> IO Bool isFalse :: SomeObject -> IO Bool module CPython -- | Initialize the Python interpreter. In an application embedding Python, -- this should be called before using any other Python/C API -- computations; with the exception of setProgramName, -- initThreads, releaseLock, and acquireLock. -- This initializes the table of loaded modules (sys.modules), -- and creates the fundamental modules builtins, -- main and sys. It also initializes the module -- search path (sys.path). It does not set sys.argv; -- use setArgv for that. This is a no-op when called for a second -- time (without calling finalize first). There is no return -- value; it is a fatal error if the initialization fails. -- -- Return True when the Python interpreter has been initialized, -- False if not. After finalize is called, this returns -- False until initialize is called again. initialize :: IO () isInitialized :: IO Bool -- | Undo all initializations made by initialize and subsequent use -- of Python/C API computations, and destroy all sub-interpreters (see -- newInterpreter below) that were created and not yet destroyed -- since the last call to initialize. Ideally, this frees all -- memory allocated by the Python interpreter. This is a no-op when -- called for a second time (without calling initialize again -- first). There is no return value; errors during finalization are -- ignored. -- -- This computation is provided for a number of reasons. An embedding -- application might want to restart Python without having to restart the -- application itself. An application that has loaded the Python -- interpreter from a dynamically loadable library (or DLL) might want to -- free all memory allocated by Python before unloading the DLL. During a -- hunt for memory leaks in an application a developer might want to free -- all memory allocated by Python before exiting from the application. -- -- Bugs and caveats: The destruction of modules and objects in -- modules is done in arbitrary order; this may cause destructors -- (del() methods) to fail when they depend on other -- objects (even functions) or modules. Dynamically loaded extension -- modules loaded by Python are not unloaded. Small amounts of memory -- allocated by the Python interpreter may not be freed (if you find a -- leak, please report it). Memory tied up in circular references between -- objects is not freed. Some memory allocated by extension modules may -- not be freed. Some extensions may not work properly if their -- initialization routine is called more than once; this can happen if an -- application calls initialize and finalize more than -- once. finalize :: IO () -- | Create a new sub-interpreter. This is an (almost) totally separate -- environment for the execution of Python code. In particular, the new -- interpreter has separate, independent versions of all imported -- modules, including the fundamental modules builtins, -- main and sys. The table of loaded modules -- (sys.modules) and the module search path (sys.path) -- are also separate. The new environment has no sys.argv -- variable. It has new standard I/O stream file objects -- sys.stdin, sys.stdout and sys.stderr -- (however these refer to the same underlying FILE structures -- in the C library). -- -- The return value points to the first thread state created in the new -- sub-interpreter. This thread state is made in the current thread -- state. Note that no actual thread is created; see the discussion of -- thread states below. If creation of the new interpreter is -- unsuccessful, Nothing is returned; no exception is set since -- the exception state is stored in the current thread state and there -- may not be a current thread state. (Like all other Python/C API -- computations, the global interpreter lock must be held before calling -- this computation and is still held when it returns; however, unlike -- most other Python/C API computations, there needn’t be a current -- thread state on entry.) -- -- Extension modules are shared between (sub-)interpreters as follows: -- the first time a particular extension is imported, it is initialized -- normally, and a (shallow) copy of its module’s dictionary is -- squirreled away. When the same extension is imported by another -- (sub-)interpreter, a new module is initialized and filled with the -- contents of this copy; the extension’s init procedure is not -- called. Note that this is different from what happens when an -- extension is imported after the interpreter has been completely -- re-initialized by calling finalize and initialize; in -- that case, the extension’s initmodule procedure is -- called again. -- -- Bugs and caveats: Because sub-interpreters (and the main -- interpreter) are part of the same process, the insulation between them -- isn’t perfect — for example, using low-level file operations like -- os.close() they can (accidentally or maliciously) affect each -- other’s open files. Because of the way extensions are shared between -- (sub-)interpreters, some extensions may not work properly; this is -- especially likely when the extension makes use of (static) global -- variables, or when the extension manipulates its module’s dictionary -- after its initialization. It is possible to insert objects created in -- one sub-interpreter into a namespace of another sub-interpreter; this -- should be done with great care to avoid sharing user-defined -- functions, methods, instances or classes between sub-interpreters, -- since import operations executed by such objects may affect the wrong -- (sub-)interpreter’s dictionary of loaded modules. (XXX This is a -- hard-to-fix bug that will be addressed in a future release.) -- -- Also note that the use of this functionality is incompatible with -- extension modules such as PyObjC and ctypes that use the -- PyGILState_*() APIs (and this is inherent in the way the -- PyGILState_*() procedures work). Simple things may work, but -- confusing behavior will always be near. newInterpreter :: IO (Maybe ThreadState) -- | Destroy the (sub-)interpreter represented by the given thread state. -- The given thread state must be the current thread state. See the -- discussion of thread states below. When the call returns, the current -- thread state is NULL. All thread states associated with this -- interpreter are destroyed. (The global interpreter lock must be held -- before calling this computation and is still held when it returns.) -- finalize will destroy all sub-interpreters that haven’t been -- explicitly destroyed at that point. endInterpreter :: ThreadState -> IO () -- | Return the program name set with setProgramName, or the -- default. getProgramName :: IO Text -- | This computation should be called before initialize is called -- for the first time, if it is called at all. It tells the interpreter -- the value of the argv[0] argument to the main -- procedure of the program. This is used by getPath and some -- other computations below to find the Python run-time libraries -- relative to the interpreter executable. The default value is -- "python". No code in the Python interpreter will change the -- program name. setProgramName :: Text -> IO () -- | Return the prefix for installed platform-independent files. This is -- derived through a number of complicated rules from the program name -- set with setProgramName and some environment variables; for -- example, if the program name is "/usr/local/bin/python", the -- prefix is "/usr/local". This corresponds to the -- prefix variable in the top-level Makefile and the -- --prefix argument to the configure script at build -- time. The value is available to Python code as sys.prefix. It -- is only useful on UNIX. See also getExecPrefix. getPrefix :: IO Text -- | Return the exec-prefix for installed platform-dependent -- files. This is derived through a number of complicated rules from the -- program name set with setProgramName' and some environment variables; -- for example, if the program name is "/usr/local/bin/python", -- the exec-prefix is "/usr/local". This corresponds to the -- exec_prefix variable in the top-level Makefile and the -- --exec-prefix argument to the configure script at -- build time. The value is available to Python code as -- sys.exec_prefix. It is only useful on UNIX. -- -- Background: The exec-prefix differs from the prefix when platform -- dependent files (such as executables and shared libraries) are -- installed in a different directory tree. In a typical installation, -- platform dependent files may be installed in the -- /usr/local/plat subtree while platform independent may be -- installed in /usr/local. -- -- Generally speaking, a platform is a combination of hardware and -- software families, e.g. Sparc machines running the Solaris 2.x -- operating system are considered the same platform, but Intel machines -- running Solaris 2.x are another platform, and Intel machines running -- Linux are yet another platform. Different major revisions of the same -- operating system generally also form different platforms. Non-UNIX -- operating systems are a different story; the installation strategies -- on those systems are so different that the prefix and exec-prefix are -- meaningless, and set to the empty string. Note that compiled Python -- bytecode files are platform independent (but not independent from the -- Python version by which they were compiled!). -- -- System administrators will know how to configure the mount or -- automount programs to share /usr/local between -- platforms while having /usr/local/plat be a different -- filesystem for each platform. getExecPrefix :: IO Text -- | Return the full program name of the Python executable; this is -- computed as a side-effect of deriving the default module search path -- from the program name (set by setProgramName above). The value -- is available to Python code as sys.executable. getProgramFullPath :: IO Text -- | Return the default module search path; this is computed from the -- program name (set by setProgramName above) and some environment -- variables. The returned string consists of a series of directory names -- separated by a platform dependent delimiter character. The delimiter -- character is ':' on Unix and Mac OS X, ';' on -- Windows. The value is available to Python code as the list -- sys.path, which may be modified to change the future search -- path for loaded modules. getPath :: IO Text -- | Return the version of this Python interpreter. This is a string that -- looks something like -- --
--   "3.0a5+ (py3k:63103M, May 12 2008, 00:53:55) \n[GCC 4.2.3]"
--   
-- -- The first word (up to the first space character) is the current Python -- version; the first three characters are the major and minor version -- separated by a period. The value is available to Python code as -- sys.version. getVersion :: IO Text -- | Return the platform identifier for the current platform. On Unix, this -- is formed from the “official” name of the operating system, converted -- to lower case, followed by the major revision number; e.g., for -- Solaris 2.x, which is also known as SunOS 5.x, the value is -- "sunos5". On Mac OS X, it is "darwin". On Windows, -- it is "win". The value is available to Python code as -- sys.platform. getPlatform :: IO Text -- | Return the official copyright string for the current Python version, -- for example -- --
--   "Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam"
--   
-- -- The value is available to Python code as sys.copyright. getCopyright :: IO Text -- | Return an indication of the compiler used to build the current Python -- version, in square brackets, for example: -- --
--   "[GCC 2.7.2.2]"
--   
-- -- The value is available to Python code as part of the variable -- sys.version. getCompiler :: IO Text -- | Return information about the sequence number and build date and time -- of the current Python interpreter instance, for example -- --
--   "#67, Aug  1 1997, 22:34:28"
--   
-- -- The value is available to Python code as part of the variable -- sys.version. getBuildInfo :: IO Text -- | Set sys.argv. The first parameter is similar to the result of -- getProgName, with the difference that it should refer to the -- script file to be executed rather than the executable hosting the -- Python interpreter. If there isn’t a script that will be run, the -- first parameter can be an empty string. If this function fails to -- initialize sys.argv, a fatal condition is signalled using -- Py_FatalError(). -- -- This function also prepends the executed script’s path to -- sys.path. If no script is executed (in the case of calling -- python -c or just the interactive interpreter), the empty -- string is used instead. setArgv :: Text -> [Text] -> IO () -- | Return the default “home”, that is, the value set by a previous call -- to setPythonHome, or the value of the PYTHONHOME -- environment variable if it is set. getPythonHome :: IO (Maybe Text) -- | Set the default “home” directory, that is, the location of the -- standard Python libraries. The libraries are searched in -- home/lib/python version and -- home/lib/python version. No code in the Python -- interpreter will change the Python home. setPythonHome :: Maybe Text -> IO () module CPython.Protocols.Iterator class Object a => Iterator a toIterator :: Iterator a => a -> SomeIterator data SomeIterator -- | Attempt to convert an object to a generic Iterator. If the -- object does not implement the iterator protocol, returns -- Nothing. castToIterator :: Object a => a -> IO (Maybe SomeIterator) -- | Return the next value from the iteration, or Nothing if there -- are no remaining items. next :: Iterator iter => iter -> IO (Maybe SomeObject) module CPython.Protocols.Mapping class Object a => Mapping a toMapping :: Mapping a => a -> SomeMapping data SomeMapping castToMapping :: Object a => a -> IO (Maybe SomeMapping) getItem :: (Mapping self, Object key) => self -> key -> IO SomeObject setItem :: (Mapping self, Object key, Object value) => self -> key -> value -> IO () deleteItem :: (Mapping self, Object key) => self -> key -> IO () size :: Mapping self => self -> IO Integer hasKey :: (Mapping self, Object key) => self -> key -> IO Bool keys :: Mapping self => self -> IO List values :: Mapping self => self -> IO List items :: Mapping self => self -> IO List instance CPython.Internal.Mapping CPython.Internal.Dictionary module CPython.Protocols.Object.Enums data HSCPythonComparisonEnum HSCPYTHON_LT :: HSCPythonComparisonEnum HSCPYTHON_LE :: HSCPythonComparisonEnum HSCPYTHON_EQ :: HSCPythonComparisonEnum HSCPYTHON_NE :: HSCPythonComparisonEnum HSCPYTHON_GT :: HSCPythonComparisonEnum HSCPYTHON_GE :: HSCPythonComparisonEnum instance GHC.Enum.Enum CPython.Protocols.Object.Enums.HSCPythonComparisonEnum module CPython.Reflection -- | Return a Dictionary of the builtins in the current execution -- frame, or the interpreter of the thread state if no frame is currently -- executing. -- -- Return a Dictionary of the local variables in the current -- execution frame, or Nothing if no frame is currently executing. getBuiltins :: IO Dictionary getLocals :: IO (Maybe Dictionary) -- | Return a Dictionary of the global variables in the current -- execution frame, or Nothing if no frame is currently executing. getGlobals :: IO (Maybe Dictionary) -- | Return the current thread state's frame, which is Nothing if no -- frame is currently executing. getFrame :: IO (Maybe SomeObject) -- | Return the name of func if it is a function, class or instance -- object, else the name of func's type. getFunctionName :: Object func => func -> IO Text -- | Return a description string, depending on the type of func. Return -- values include "()" for functions and methods, -- "constructor", "instance", and "object". -- Concatenated with the result of getFunctionName, the result -- will be a description of func. getFunctionDescription :: Object func => func -> IO Text module CPython.System -- | Return the object name from the sys module, or -- Nothing if it does not exist. getObject :: Text -> IO (Maybe SomeObject) -- | Set name in the sys module to a value. setObject :: Object a => Text -> a -> IO () -- | Delete name from the sys module. deleteObject :: Text -> IO () -- | Add an entry to sys.warnoptions. -- -- Reset sys.warnoptions to an empty list. resetWarnOptions :: IO () addWarnOption :: Text -> IO () -- | Set sys.path to a list object of paths found in the -- parameter, which should be a list of paths separated with the -- platform's search path delimiter (':' on Unix, ';' -- on Windows). setPath :: Text -> IO () module CPython.Types.ByteArray data ByteArray byteArrayType :: Type toByteArray :: ByteString -> IO ByteArray fromByteArray :: ByteArray -> IO ByteString -- | Create a new byte array from any object which implements the buffer -- protocol. fromObject :: Object self => self -> IO ByteArray append :: ByteArray -> ByteArray -> IO ByteArray length :: ByteArray -> IO Integer resize :: ByteArray -> Integer -> IO () instance CPython.Internal.Object CPython.Types.ByteArray.ByteArray instance CPython.Internal.Concrete CPython.Types.ByteArray.ByteArray module CPython.Types.Bytes data Bytes bytesType :: Type toBytes :: ByteString -> IO Bytes fromBytes :: Bytes -> IO ByteString -- | Create a new byte string from any object which implements the buffer -- protocol. fromObject :: Object self => self -> IO Bytes length :: Bytes -> IO Integer append :: Bytes -> Bytes -> IO Bytes instance CPython.Internal.Object CPython.Types.Bytes.Bytes instance CPython.Internal.Concrete CPython.Types.Bytes.Bytes module CPython.Types.Capsule data Capsule capsuleType :: Type -- | Retrieve the pointer stored in the capsule. On failure, throws an -- exception. -- -- The name parameter must compare exactly to the name stored in the -- capsule. If the name stored in the capsule is Nothing, the name -- passed in must also be Nothing. Python uses the C function -- strcmp() to compare capsule names. getPointer :: Capsule -> Maybe Text -> IO (Ptr ()) -- | Return the current context stored in the capsule, which might be -- NULL. getContext :: Capsule -> IO (Ptr ()) -- | Return the current name stored in the capsule, which might be -- Nothing. getName :: Capsule -> IO (Maybe Text) -- | Import a pointer to a C object from a capsule attribute in a module. -- The name parameter should specify the full name to the attribute, as -- in "module.attribute". The name stored in the capsule must -- match this string exactly. If the second parameter is False, -- import the module without blocking (using -- PyImport_ImportModuleNoBlock()). Otherwise, imports the -- module conventionally (using PyImport_ImportModule()). -- -- Return the capsule’s internal pointer on success. On failure, throw an -- exception. If the module could not be imported, and if importing in -- non-blocking mode, returns Nothing. importNamed :: Text -> Bool -> IO (Maybe (Ptr ())) -- | Determines whether or not a capsule is valid. A valid capsule's type -- is capsuleType, has a non-NULL pointer stored in it, and its -- internal name matches the name parameter. (See getPointer for -- information on how capsule names are compared.) -- -- In other words, if isValid returns True, calls to any of -- the accessors (any function starting with get) are guaranteed -- to succeed. isValid :: Capsule -> Maybe Text -> IO Bool -- | Set the void pointer inside the capsule. The pointer may not be -- NULL. setPointer :: Capsule -> Ptr () -> IO () -- | Set the context pointer inside the capsule. setContext :: Capsule -> Ptr () -> IO () instance CPython.Internal.Object CPython.Types.Capsule.Capsule instance CPython.Internal.Concrete CPython.Types.Capsule.Capsule module CPython.Types.Cell data Cell cellType :: Type -- | Create and return a new cell containing the value obj. new :: Object obj => Maybe obj -> IO Cell -- | Return the contents of a cell. get :: Cell -> IO (Maybe SomeObject) -- | Set the contents of a cell to obj. This releases the reference -- to any current content of the cell. set :: Object obj => Cell -> Maybe obj -> IO () instance CPython.Internal.Object CPython.Types.Cell.Cell instance CPython.Internal.Concrete CPython.Types.Cell.Cell module CPython.Types.Code data Code codeType :: Type instance CPython.Internal.Object CPython.Types.Code.Code instance CPython.Internal.Concrete CPython.Types.Code.Code module CPython.Types.Complex data Complex complexType :: Type toComplex :: Complex Double -> IO Complex fromComplex :: Complex -> IO (Complex Double) instance CPython.Internal.Object CPython.Types.Complex.Complex instance CPython.Internal.Concrete CPython.Types.Complex.Complex module CPython.Types.Dictionary data Dictionary dictionaryType :: Type new :: IO Dictionary -- | Empty an existing dictionary of all key-value pairs. clear :: Dictionary -> IO () -- | Determine if a dictionary contains key. If an item in the -- dictionary matches key, return True, otherwise return -- False. On error, throws an exception. This is equivalent to the -- Python expression key in d. contains :: Object key => Dictionary -> key -> IO Bool -- | Return a new dictionary that contains the same key-value pairs as the -- old dictionary. copy :: Dictionary -> IO Dictionary -- | Return the object from a dictionary which has a key key. Return -- Nothing if the key is not present. getItem :: Object key => Dictionary -> key -> IO (Maybe SomeObject) -- | Inserts value into a dictionary with a key of key. -- key must be hashable; if it isn’t, throws TypeError. setItem :: (Object key, Object value) => Dictionary -> key -> value -> IO () -- | Remove the entry in a dictionary with key key. key must -- be hashable; if it isn’t, throws TypeError. deleteItem :: Object key => Dictionary -> key -> IO () -- | Return a List containing all the items in the dictionary, as in -- the Python method dict.items(). items :: Dictionary -> IO List -- | Return a List containing all the keys in the dictionary, as in -- the Python method dict.keys(). keys :: Dictionary -> IO List -- | Return a List containing all the values in the dictionary, as -- in the Python method dict.values(). values :: Dictionary -> IO List -- | Return the number of items in the dictionary. This is equivalent to -- len(d). size :: Dictionary -> IO Integer -- | Iterate over mapping object b adding key-value pairs to a -- dictionary. b may be a dictionary, or any object supporting -- keys and getItem. If the third parameter is True, -- existing pairs in will be replaced if a matching key is found in -- b, otherwise pairs will only be added if there is not already a -- matching key. merge :: Mapping b => Dictionary -> b -> Bool -> IO () -- | This is the same as (\a b -> merge a b True) in -- Haskell, or a.update(b) in Python. update :: Mapping b => Dictionary -> b -> IO () -- | Update or merge into a dictionary, from the key-value pairs in -- seq2. seq2 must be an iterable object producing iterable -- objects of length 2, viewed as key-value pairs. In case of duplicate -- keys, the last wins if the third parameter is True, otherwise -- the first wins. Equivalent Python: -- --
--   def mergeFromSeq2(a, seq2, override):
--     for key, value in seq2:
--       if override or key not in a:
--         a[key] = value
--   
mergeFromSeq2 :: Object seq2 => Dictionary -> seq2 -> Bool -> IO () instance CPython.Internal.Concrete CPython.Internal.Dictionary module CPython.Types.Exception data Exception exceptionType :: Exception -> SomeObject exceptionValue :: Exception -> SomeObject exceptionTraceback :: Exception -> Maybe SomeObject module CPython.Types.Float data Float floatType :: Type toFloat :: Double -> IO Float fromFloat :: Float -> IO Double instance CPython.Internal.Object CPython.Types.Float.Float instance CPython.Internal.Concrete CPython.Types.Float.Float module CPython.Types.Function data Function -- | Return a new function associated with the given code object. The -- second parameter will be used as the globals accessible to the -- function. -- -- The function's docstring, name, and module are -- retrieved from the code object. The parameter defaults and closure are -- set to Nothing. functionType :: Type new :: Code -> Dictionary -> IO Function -- | Return the code object associated with a function. getCode :: Function -> IO Code -- | Return the globals dictionary associated with a function. getGlobals :: Function -> IO Dictionary -- | Return the module attribute of a function. This is -- normally a Unicode containing the module name, but can be set -- to any other object by Python code. getModule :: Function -> IO SomeObject -- | Return the default parameter values for a function. This can be a -- tuple or Nothing. getDefaults :: Function -> IO (Maybe Tuple) -- | Set the default values for a function. setDefaults :: Function -> Maybe Tuple -> IO () -- | Return the closure associated with a function. This can be -- Nothing, or a tuple of Cells. getClosure :: Function -> IO (Maybe Tuple) -- | Set the closure associated with a function. The tuple should contain -- Cells. setClosure :: Function -> Maybe Tuple -> IO () -- | Return the annotations for a function. This can be a mutable -- dictionary, or Nothing. getAnnotations :: Function -> IO (Maybe Dictionary) -- | Set the annotations for a function object. setAnnotations :: Function -> Maybe Dictionary -> IO () instance CPython.Internal.Object CPython.Types.Function.Function instance CPython.Internal.Concrete CPython.Types.Function.Function module CPython.Types.InstanceMethod data InstanceMethod instanceMethodType :: Type new :: Object func => func -> IO InstanceMethod function :: InstanceMethod -> IO SomeObject instance CPython.Internal.Object CPython.Types.InstanceMethod.InstanceMethod instance CPython.Internal.Concrete CPython.Types.InstanceMethod.InstanceMethod module CPython.Types.Iterator data SequenceIterator sequenceIteratorType :: Type -- | Return an Iterator that works with a general sequence object, -- seq. The iteration ends when the sequence raises -- IndexError for the subscripting operation. sequenceIteratorNew :: Sequence seq => seq -> IO SequenceIterator data CallableIterator callableIteratorType :: Type -- | Return a new Iterator. The first parameter, callable, -- can be any Python callable object that can be called with no -- parameters; each call to it should return the next item in the -- iteration. When callable returns a value equal to -- sentinel, the iteration will be terminated. callableIteratorNew :: (Object callable, Object sentinel) => callable -> sentinel -> IO CallableIterator instance CPython.Internal.Iterator CPython.Types.Iterator.CallableIterator instance CPython.Internal.Object CPython.Types.Iterator.CallableIterator instance CPython.Internal.Concrete CPython.Types.Iterator.CallableIterator instance CPython.Internal.Iterator CPython.Types.Iterator.SequenceIterator instance CPython.Internal.Object CPython.Types.Iterator.SequenceIterator instance CPython.Internal.Concrete CPython.Types.Iterator.SequenceIterator module CPython.Types.Method data Method methodType :: Type new :: (Object func, Object self) => func -> self -> IO Method function :: Method -> IO SomeObject self :: Method -> IO SomeObject instance CPython.Internal.Object CPython.Types.Method.Method instance CPython.Internal.Concrete CPython.Types.Method.Method module CPython.Types.Slice data Slice -- | Return a new slice object with the given values. The start, -- stop, and step parameters are used as the values of the -- slice object attributes of the same names. Any of the values may be -- Nothing, in which case None will be used for the -- corresponding attribute. sliceType :: Type new :: (Object start, Object stop, Object step) => Maybe start -> Maybe stop -> Maybe step -> IO Slice -- | Retrieve the start, stop, step, and slice length from a Slice, -- assuming a sequence of the given length. getIndices :: Slice -> Integer -> IO (Integer, Integer, Integer, Integer) instance CPython.Internal.Object CPython.Types.Slice.Slice instance CPython.Internal.Concrete CPython.Types.Slice.Slice module CPython.Types.Tuple data Tuple tupleType :: Type toTuple :: [SomeObject] -> IO Tuple -- | Convert any object implementing the iterator protocol to a -- Tuple. iterableToTuple :: Object iter => iter -> IO Tuple fromTuple :: Tuple -> IO [SomeObject] length :: Tuple -> IO Integer -- | Return the object at a given index from a tuple, or throws -- IndexError if the index is out of bounds. getItem :: Tuple -> Integer -> IO SomeObject -- | Take a slice of a tuple from low to high, and return it -- as a new tuple. getSlice :: Tuple -> Integer -> Integer -> IO Tuple setItem :: Object o => Tuple -> Integer -> o -> IO () instance CPython.Internal.Concrete CPython.Internal.Tuple -- | Any functionality not listed below is best accessed using the either -- the Object protocol (including callMethod, -- richCompare, hash, repr, isTrue, -- and getIter) or the Number protocol (including -- and, subtract, or, xor, -- inPlaceAnd, inPlaceSubtract, inPlaceOr, and -- inPlaceXor). module CPython.Types.Set class Object a => AnySet a data Set data FrozenSet setType :: Type frozenSetType :: Type toSet :: [SomeObject] -> IO Set toFrozenSet :: [SomeObject] -> IO FrozenSet -- | Return a new Set from the contents of an iterable -- Object. The object may be Nothing to create an empty -- set. Throws a TypeError if the object is not iterable. iterableToSet :: Object obj => obj -> IO Set -- | Return a new FrozenSet from the contents of an iterable -- Object. The object may be Nothing to create an empty -- frozen set. Throws a TypeError if the object is not iterable. iterableToFrozenSet :: Object obj => obj -> IO FrozenSet fromSet :: AnySet set => set -> IO [SomeObject] -- | Return the size of a Set or FrozenSet. size :: AnySet set => set -> IO Integer -- | Return True if found, False if not found. Unlike the -- Python contains() method, this computation does not -- automatically convert unhashable Sets into temporary -- FrozenSets. Throws a TypeError if the key is -- unhashable. contains :: (AnySet set, Object key) => set -> key -> IO Bool -- | Add key to a Set. Also works with FrozenSet (like -- setItem it can be used to fill-in the values of brand new -- FrozenSets before they are exposed to other code). Throws a -- TypeError if the key is unhashable. Throws a -- MemoryError if there is no room to grow. add :: (AnySet set, Object key) => set -> key -> IO () -- | Return True if found and removed, False if not found (no -- action taken). Does not throw KeyError for missing keys. -- Throws a TypeError if key is unhashable. Unlike the -- Python discard() method, this computation does not -- automatically convert unhashable sets into temporary -- FrozenSets. discard :: Object key => Set -> key -> IO Bool -- | Return an arbitrary object in the set, and removes the object from the -- set. Throws KeyError if the set is empty. pop :: Set -> IO SomeObject -- | Remove all elements from a set. clear :: Set -> IO () instance CPython.Internal.Object CPython.Types.Set.FrozenSet instance CPython.Internal.Concrete CPython.Types.Set.FrozenSet instance CPython.Types.Set.AnySet CPython.Types.Set.FrozenSet instance CPython.Internal.Object CPython.Types.Set.Set instance CPython.Internal.Concrete CPython.Types.Set.Set instance CPython.Types.Set.AnySet CPython.Types.Set.Set module CPython.Types.List data List listType :: Type toList :: [SomeObject] -> IO List -- | Convert any object implementing the iterator protocol to a -- List. iterableToList :: Object iter => iter -> IO List fromList :: List -> IO [SomeObject] length :: List -> IO Integer -- | Returns the object at a given position in the list. The position must -- be positive; indexing from the end of the list is not supported. If -- the position is out of bounds, throws an IndexError -- exception. getItem :: List -> Integer -> IO SomeObject -- | Set the item at a given index. setItem :: Object o => List -> Integer -> o -> IO () -- | Inserts item into the list in front of the given index. Throws -- an exception if unsuccessful. Analogous to list.insert(index, -- item). insert :: Object item => List -> Integer -> item -> IO () -- | Append item to the end of th list. Throws an exception if -- unsuccessful. Analogous to list.append(item). append :: Object item => List -> item -> IO () -- | Return a list of the objects in list containing the objects between -- the given indexes. Throws an exception if unsuccessful. Analogous to -- list[low:high]. Negative indices, as when slicing from -- Python, are not supported. getSlice :: List -> Integer -> Integer -> IO List -- | Sets the slice of a list between low and high to the -- contents of a replacement list. Analogous to list[low:high] = -- replacement. The replacement may be Nothing, indicating -- the assignment of an empty list (slice deletion). Negative indices, as -- when slicing from Python, are not supported. setSlice :: List -> Integer -> Integer -> Maybe List -> IO () -- | Sort the items of a list in place. This is equivalent to -- list.sort(). sort :: List -> IO () -- | Reverses the items of a list in place. This is equivalent to -- list.reverse(). reverse :: List -> IO () -- | Return a new Tuple containing the contents of a list; -- equivalent to tuple(list). toTuple :: List -> IO Tuple instance CPython.Internal.Concrete CPython.Internal.List module CPython.Types.Type data Type typeType :: Type isSubtype :: Type -> Type -> IO Bool instance CPython.Internal.Concrete CPython.Internal.Type module CPython.Types.Unicode data Unicode type Encoding = Text data ErrorHandling Strict :: ErrorHandling Replace :: ErrorHandling Ignore :: ErrorHandling unicodeType :: Type toUnicode :: Text -> IO Unicode fromUnicode :: Unicode -> IO Text length :: Unicode -> IO Integer -- | Coerce an encoded object obj to an Unicode object. -- -- Bytes and other char buffer compatible objects are decoded -- according to the given encoding and error handling mode. -- -- All other objects, including Unicode objects, cause a -- TypeError to be thrown. fromEncodedObject :: Object obj => obj -> Encoding -> ErrorHandling -> IO Unicode -- | Shortcut for fromEncodedObject "utf-8" Strict fromObject :: Object obj => obj -> IO Unicode -- | Encode a Unicode object and return the result as Bytes -- object. The encoding and error mode have the same meaning as the -- parameters of the the str.encode() method. The codec to be -- used is looked up using the Python codec registry. encode :: Unicode -> Encoding -> ErrorHandling -> IO Bytes -- | Create a Unicode object by decoding a Bytes object. The -- encoding and error mode have the same meaning as the parameters of the -- the str.encode() method. The codec to be used is looked up -- using the Python codec registry. decode :: Bytes -> Encoding -> ErrorHandling -> IO Unicode append :: Unicode -> Unicode -> IO Unicode -- | Split a string giving a List of Unicode objects. If the -- separator is Nothing, splitting will be done at all whitespace -- substrings. Otherwise, splits occur at the given separator. Separators -- are not included in the resulting list. split :: Unicode -> Maybe Unicode -> Maybe Integer -> IO List -- | Split a Unicode string at line breaks, returning a list of -- Unicode strings. CRLF is considered to be one line break. If -- the second parameter is False, the line break characters are -- not included in the resulting strings. splitLines :: Unicode -> Bool -> IO List -- | Translate a string by applying a character mapping table to it. -- -- The mapping table must map Unicode ordinal integers to Unicode ordinal -- integers or None (causing deletion of the character). -- -- Mapping tables need only provide the getitem() -- interface; dictionaries and sequences work well. Unmapped character -- ordinals (ones which cause a LookupError) are left untouched -- and are copied as-is. -- -- The error mode has the usual meaning for codecs. translate :: Object table => Unicode -> table -> ErrorHandling -> IO Unicode -- | Join a sequence of strings using the given separator. join :: Sequence seq => Unicode -> seq -> IO Unicode data MatchDirection Prefix :: MatchDirection Suffix :: MatchDirection -- | Return True if the substring matches -- string*[*start:end] at the given tail end (either a -- Prefix or Suffix match), False otherwise. tailMatch :: Unicode -> Unicode -> Integer -> Integer -> MatchDirection -> IO Bool data FindDirection Forwards :: FindDirection Backwards :: FindDirection -- | Return the first position of the substring in -- string*[*start:end] using the given direction. The return -- value is the index of the first match; a value of Nothing -- indicates that no match was found. find :: Unicode -> Unicode -> Integer -> Integer -> FindDirection -> IO (Maybe Integer) -- | Return the number of non-overlapping occurrences of the substring in -- string[start:end]. count :: Unicode -> Unicode -> Integer -> Integer -> IO Integer -- | Replace occurrences of the substring with a given replacement. If the -- maximum count is Nothing, replace all occurences. replace :: Unicode -> Unicode -> Unicode -> Maybe Integer -> IO Unicode -- | Return a new Unicode object from the given format and args; -- this is analogous to format % args. format :: Unicode -> Tuple -> IO Unicode -- | Check whether element is contained in a string. -- -- element has to coerce to a one element string. contains :: Object element => Unicode -> element -> IO Bool instance GHC.Classes.Eq CPython.Types.Unicode.ErrorHandling instance GHC.Show.Show CPython.Types.Unicode.ErrorHandling instance GHC.Classes.Eq CPython.Types.Unicode.MatchDirection instance GHC.Show.Show CPython.Types.Unicode.MatchDirection instance GHC.Classes.Eq CPython.Types.Unicode.FindDirection instance GHC.Show.Show CPython.Types.Unicode.FindDirection instance CPython.Internal.Object CPython.Types.Unicode.Unicode instance CPython.Internal.Concrete CPython.Types.Unicode.Unicode module CPython.Protocols.Sequence class Object a => Sequence a toSequence :: Sequence a => a -> SomeSequence data SomeSequence -- | Attempt to convert an object to a generic Sequence. If the -- object does not implement the sequence protocol, returns -- Nothing. castToSequence :: Object a => a -> IO (Maybe SomeSequence) length :: Sequence self => self -> IO Integer append :: (Sequence a, Sequence b) => a -> b -> IO SomeSequence repeat :: Sequence a => a -> Integer -> IO a inPlaceAppend :: (Sequence a, Sequence b) => a -> b -> IO SomeSequence inPlaceRepeat :: Sequence a => a -> Integer -> IO a getItem :: Sequence self => self -> Integer -> IO SomeObject setItem :: (Sequence self, Object v) => self -> Integer -> v -> IO () deleteItem :: Sequence self => self -> Integer -> IO () getSlice :: Sequence self => self -> Integer -> Integer -> IO SomeObject setSlice :: (Sequence self, Object v) => self -> Integer -> Integer -> v -> IO () deleteSlice :: Sequence self => self -> Integer -> Integer -> IO () count :: (Sequence self, Object v) => self -> v -> IO Integer contains :: (Sequence self, Object v) => self -> v -> IO Bool -- | Return the first index i for which self[i] == v. This -- is equivalent to the Python expression self.index(v). index :: (Sequence self, Object v) => self -> v -> IO Integer -- | Return a list object with the same contents as the arbitrary sequence -- seq. The returned list is guaranteed to be new. toList :: Sequence seq => seq -> IO List -- | Return a tuple object with the same contents as the arbitrary sequence -- seq. If seq is already a tuple, it is re-used rather -- than copied. toTuple :: Sequence seq => seq -> IO Tuple -- | Returns the sequence seq as a tuple, unless it is already a -- tuple or list, in which case seq is returned. If an error -- occurs, throws TypeError with the given text as the exception -- text. fast :: Sequence seq => seq -> Text -> IO SomeSequence instance CPython.Internal.Sequence CPython.Types.ByteArray.ByteArray instance CPython.Internal.Sequence CPython.Types.Bytes.Bytes instance CPython.Internal.Sequence CPython.Internal.List instance CPython.Internal.Sequence CPython.Internal.Tuple instance CPython.Internal.Sequence CPython.Types.Unicode.Unicode module CPython.Protocols.Object class Object a class Object a => Concrete a data SomeObject -- | Returns a Type object corresponding to the object type of -- self. On failure, throws SystemError. This is -- equivalent to the Python expression type(o). getType :: Object self => self -> IO Type -- | Returns True if inst is an instance of the class -- cls or a subclass of cls, or False if not. On -- error, throws an exception. If cls is a type object rather than -- a class object, isInstance returns True if inst -- is of type cls. If cls is a tuple, the check will be -- done against every entry in cls. The result will be True -- when at least one of the checks returns True, otherwise it will -- be False. If inst is not a class instance and cls -- is neither a type object, nor a class object, nor a tuple, inst -- must have a class attribute ߞ the class relationship -- of the value of that attribute with cls will be used to -- determine the result of this function. -- -- Subclass determination is done in a fairly straightforward way, but -- includes a wrinkle that implementors of extensions to the class system -- may want to be aware of. If A and B are class objects, B is a subclass -- of A if it inherits from A either directly or indirectly. If either is -- not a class object, a more general mechanism is used to determine the -- class relationship of the two objects. When testing if B is a subclass -- of A, if A is B, isSubclass returns True. If A and B are -- different objects, Bߢs bases attribute is searched in -- a depth-first fashion for A ߞ the presence of the -- bases attribute is considered sufficient for this -- determination. isInstance :: (Object self, Object cls) => self -> cls -> IO Bool -- | Returns True if the class derived is identical to or -- derived from the class cls, otherwise returns False. In -- case of an error, throws an exception. If cls is a tuple, the -- check will be done against every entry in cls. The result will -- be True when at least one of the checks returns True, -- otherwise it will be False. If either derived or -- cls is not an actual class object (or tuple), this function -- uses the generic algorithm described above. isSubclass :: (Object derived, Object cls) => derived -> cls -> IO Bool toObject :: Object a => a -> SomeObject -- | Attempt to cast an object to some concrete class. If the object isn't -- an instance of the class or subclass, returns Nothing. cast :: (Object a, Concrete b) => a -> IO (Maybe b) -- | Returns True if self has an attribute with the given -- name, and False otherwise. This is equivalent to the Python -- expression hasattr(self, name) hasAttribute :: Object self => self -> Unicode -> IO Bool -- | Retrieve an attribute with the given name from object self. -- Returns the attribute value on success, and throws an exception on -- failure. This is the equivalent of the Python expression -- self.name. getAttribute :: Object self => self -> Unicode -> IO SomeObject -- | Set the value of the attribute with the given name, for object -- self, to the value v. THrows an exception on failure. -- This is the equivalent of the Python statement self.name = v. setAttribute :: (Object self, Object v) => self -> Unicode -> v -> IO () -- | Delete an attribute with the given name, for object self. -- Throws an exception on failure. This is the equivalent of the Python -- statement del self.name. deleteAttribute :: Object self => self -> Unicode -> IO () -- | Print repr(self) to a handle. print :: Object self => self -> Handle -> IO () -- | Compute a string representation of object self, or throw an -- exception on failure. This is the equivalent of the Python expression -- repr(self). repr :: Object self => self -> IO Unicode ascii :: Object self => self -> IO Unicode -- | Compute a string representation of object self, or throw an -- exception on failure. This is the equivalent of the Python expression -- str(self). string :: Object self => self -> IO Unicode -- | Compute a bytes representation of object self, or throw an -- exception on failure. This is equivalent to the Python expression -- bytes(self). bytes :: Object self => self -> IO Bytes -- | Determine if the object self is callable. callable :: Object self => self -> IO Bool -- | Call a callable Python object self, with arguments given by the -- tuple and named arguments given by the dictionary. Returns the result -- of the call on success, or throws an exception on failure. This is the -- equivalent of the Python expression self(*args, **kw). call :: Object self => self -> Tuple -> Dictionary -> IO SomeObject -- | Call a callable Python object self, with arguments given by the -- list. callArgs :: Object self => self -> [SomeObject] -> IO SomeObject -- | Call the named method of object self, with arguments given by -- the tuple and named arguments given by the dictionary. Returns the -- result of the call on success, or throws an exception on failure. This -- is the equivalent of the Python expression self.method(args). callMethod :: Object self => self -> Text -> Tuple -> Dictionary -> IO SomeObject -- | Call the named method of object self, with arguments given by -- the list. Returns the result of the call on success, or throws an -- exception on failure. This is the equivalent of the Python expression -- self.method(args). callMethodArgs :: Object self => self -> Text -> [SomeObject] -> IO SomeObject data Comparison LT :: Comparison LE :: Comparison EQ :: Comparison NE :: Comparison GT :: Comparison GE :: Comparison -- | Compare the values of a and b using the specified -- comparison. If an exception is raised, throws an exception. richCompare :: (Object a, Object b) => a -> b -> Comparison -> IO Bool -- | Returns True if the object self is considered to be -- true, and False otherwise. This is equivalent to the Python -- expression not not self. On failure, throws an exception. toBool :: Object self => self -> IO Bool -- | Compute and return the hash value of an object self. On -- failure, throws an exception. This is the equivalent of the Python -- expression hash(self). hash :: Object self => self -> IO Integer -- | This is equivalent to the Python expression dir(self), -- returning a (possibly empty) list of strings appropriate for the -- object argument, or throws an exception if there was an error. dir :: Object self => self -> IO List -- | This is equivalent to the Python expression iter(self). It -- returns a new iterator for the object argument, or the object itself -- if the object is already an iterator. Throws TypeError if the -- object cannot be iterated. getIterator :: Object self => self -> IO SomeObject instance GHC.Show.Show CPython.Protocols.Object.Comparison module CPython.Types.Integer data Integer integerType :: Type toInteger :: Integer -> IO Integer fromInteger :: Integer -> IO Integer instance CPython.Internal.Object CPython.Types.Integer.Integer instance CPython.Internal.Concrete CPython.Types.Integer.Integer module CPython.Types.Module data Module -- | Return a new module object with the name attribute -- set. Only the module’s doc and name -- attributes are filled in; the caller is responsible for providing a -- file attribute. moduleType :: Type new :: Text -> IO Module -- | Return the dictionary object that implements a module’s namespace; -- this object is the same as the dict attribute of the -- module. This computation never fails. It is recommended extensions use -- other computations rather than directly manipulate a module’s -- dict. getDictionary :: Module -> IO Dictionary -- | Returns a module’s name value. If the module does not -- provide one, or if it is not a string, throws SystemError. getName :: Module -> IO Text -- | Returns the name of the file from which a module was loaded using the -- module’s file attribute. If this is not defined, or if -- it is not a string, throws SystemError. getFilename :: Module -> IO Text -- | Add an object to a module with the given name. This is a convenience -- computation which can be used from the module’s initialization -- computation. addObject :: Object value => Module -> Text -> value -> IO () -- | Add an integer constant to a module. This convenience computation can -- be used from the module’s initialization computation. addIntegerConstant :: Module -> Text -> Integer -> IO () -- | Add a string constant to a module. This convenience computation can be -- used from the module’s initialization computation. addTextConstant :: Module -> Text -> Text -> IO () -- | This is a higher-level interface that calls the current “import hook” -- (with an explicit level of 0, meaning absolute import). It -- invokes the import() computation from the -- builtins of the current globals. This means that the -- import is done using whatever import hooks are installed in the -- current environment. -- -- This computation always uses absolute imports. importModule :: Text -> IO Module -- | Reload a module. If an error occurs, an exception is thrown and the -- old module still exists. reload :: Module -> IO Module instance CPython.Internal.Object CPython.Types.Module.Module instance CPython.Internal.Concrete CPython.Types.Module.Module module CPython.Protocols.Number class Object a => Number a toNumber :: Number a => a -> SomeNumber data SomeNumber castToNumber :: Object a => a -> IO (Maybe SomeNumber) add :: (Number a, Number b) => a -> b -> IO SomeNumber subtract :: (Number a, Number b) => a -> b -> IO SomeNumber multiply :: (Number a, Number b) => a -> b -> IO SomeNumber floorDivide :: (Number a, Number b) => a -> b -> IO SomeNumber trueDivide :: (Number a, Number b) => a -> b -> IO SomeNumber remainder :: (Number a, Number b) => a -> b -> IO SomeNumber divmod :: (Number a, Number b) => a -> b -> IO SomeNumber power :: (Number a, Number b, Number c) => a -> b -> Maybe c -> IO SomeNumber negative :: Number a => a -> IO SomeNumber positive :: Number a => a -> IO SomeNumber absolute :: Number a => a -> IO SomeNumber invert :: Number a => a -> IO SomeNumber shiftL :: (Number a, Number b) => a -> b -> IO SomeNumber shiftR :: (Number a, Number b) => a -> b -> IO SomeNumber and :: (Number a, Number b) => a -> b -> IO SomeNumber xor :: (Number a, Number b) => a -> b -> IO SomeNumber or :: (Number a, Number b) => a -> b -> IO SomeNumber inPlaceAdd :: (Number a, Number b) => a -> b -> IO SomeNumber inPlaceSubtract :: (Number a, Number b) => a -> b -> IO SomeNumber inPlaceMultiply :: (Number a, Number b) => a -> b -> IO SomeNumber inPlaceFloorDivide :: (Number a, Number b) => a -> b -> IO SomeNumber inPlaceTrueDivide :: (Number a, Number b) => a -> b -> IO SomeNumber inPlaceRemainder :: (Number a, Number b) => a -> b -> IO SomeNumber inPlacePower :: (Number a, Number b, Number c) => a -> b -> Maybe c -> IO SomeNumber inPlaceShiftL :: (Number a, Number b) => a -> b -> IO SomeNumber inPlaceShiftR :: (Number a, Number b) => a -> b -> IO SomeNumber inPlaceAnd :: (Number a, Number b) => a -> b -> IO SomeNumber inPlaceXor :: (Number a, Number b) => a -> b -> IO SomeNumber inPlaceOr :: (Number a, Number b) => a -> b -> IO SomeNumber toInteger :: Number a => a -> IO Integer toFloat :: Number a => a -> IO Float toBase :: Number a => a -> Integer -> IO Unicode instance CPython.Internal.Object CPython.Protocols.Number.SomeNumber instance CPython.Protocols.Number.Number CPython.Protocols.Number.SomeNumber instance CPython.Protocols.Number.Number CPython.Types.Integer.Integer instance CPython.Protocols.Number.Number CPython.Types.Float.Float instance CPython.Protocols.Number.Number CPython.Types.Complex.Complex instance CPython.Protocols.Number.Number CPython.Types.Set.Set instance CPython.Protocols.Number.Number CPython.Types.Set.FrozenSet module CPython.Types.WeakReference data Reference data Proxy -- | Return a weak reference for the object. This will always return a new -- reference, but is not guaranteed to create a new object; an existing -- reference object may be returned. The second parameter, -- callback, can be a callable object that receives notification -- when obj is garbage collected; it should accept a single -- parameter, which will be the weak reference object itself. If ob is -- not a weakly-referencable object, or if callback is not -- callable, this will throw a TypeError. newReference :: (Object obj, Object callback) => obj -> Maybe callback -> IO Reference -- | Return a weak reference proxy for the object. This will always return -- a new reference, but is not guaranteed to create a new object; an -- existing proxy may be returned. The second parameter, callback, -- can be a callable object that receives notification when obj is -- garbage collected; it should accept a single parameter, which will be -- the weak reference object itself. If ob is not a weakly-referencable -- object, or if callback is not callable, this will throw a -- TypeError. newProxy :: (Object obj, Object callback) => obj -> Maybe callback -> IO Proxy -- | Return the referenced object from a weak reference. If the referent is -- no longer live, returns None. getObject :: Reference -> IO SomeObject instance CPython.Internal.Object CPython.Types.WeakReference.Proxy instance CPython.Internal.Object CPython.Types.WeakReference.Reference module CPython.Types data ByteArray data Bytes data Capsule data Cell data Code data Complex data Dictionary data Exception data Float data Function data InstanceMethod data Integer data SequenceIterator data CallableIterator data List data Method data Module class Object a => AnySet a data Set data FrozenSet data Slice data Tuple data Type data Unicode data Reference data Proxy byteArrayType :: Type bytesType :: Type capsuleType :: Type cellType :: Type codeType :: Type complexType :: Type dictionaryType :: Type floatType :: Type -- | Return a new function associated with the given code object. The -- second parameter will be used as the globals accessible to the -- function. -- -- The function's docstring, name, and module are -- retrieved from the code object. The parameter defaults and closure are -- set to Nothing. functionType :: Type instanceMethodType :: Type integerType :: Type sequenceIteratorType :: Type callableIteratorType :: Type listType :: Type methodType :: Type -- | Return a new module object with the name attribute -- set. Only the module’s doc and name -- attributes are filled in; the caller is responsible for providing a -- file attribute. moduleType :: Type setType :: Type frozenSetType :: Type -- | Return a new slice object with the given values. The start, -- stop, and step parameters are used as the values of the -- slice object attributes of the same names. Any of the values may be -- Nothing, in which case None will be used for the -- corresponding attribute. sliceType :: Type tupleType :: Type typeType :: Type unicodeType :: Type toByteArray :: ByteString -> IO ByteArray fromByteArray :: ByteArray -> IO ByteString toBytes :: ByteString -> IO Bytes fromBytes :: Bytes -> IO ByteString toComplex :: Complex Double -> IO Complex fromComplex :: Complex -> IO (Complex Double) toFloat :: Double -> IO Float fromFloat :: Float -> IO Double toInteger :: Integer -> IO Integer fromInteger :: Integer -> IO Integer toList :: [SomeObject] -> IO List -- | Convert any object implementing the iterator protocol to a -- List. iterableToList :: Object iter => iter -> IO List fromList :: List -> IO [SomeObject] toSet :: [SomeObject] -> IO Set toFrozenSet :: [SomeObject] -> IO FrozenSet -- | Return a new Set from the contents of an iterable -- Object. The object may be Nothing to create an empty -- set. Throws a TypeError if the object is not iterable. iterableToSet :: Object obj => obj -> IO Set -- | Return a new FrozenSet from the contents of an iterable -- Object. The object may be Nothing to create an empty -- frozen set. Throws a TypeError if the object is not iterable. iterableToFrozenSet :: Object obj => obj -> IO FrozenSet fromSet :: AnySet set => set -> IO [SomeObject] toTuple :: [SomeObject] -> IO Tuple -- | Convert any object implementing the iterator protocol to a -- Tuple. iterableToTuple :: Object iter => iter -> IO Tuple fromTuple :: Tuple -> IO [SomeObject] toUnicode :: Text -> IO Unicode fromUnicode :: Unicode -> IO Text module CPython.Simple.Instances -- | ToPy instances indicate that a type can be marshalled from -- Haskell to Python automatically -- -- For example, ToPy Integer indicates that we know how to take -- a Haskell Integer and convert it into a Python int -- object class ToPy a -- | Takes some Haskell type, and converts it to a Python object by going -- over FFI -- -- Generally you'll only need to call toPy manually on some type -- when writing your own ToPy instances for another type toPy :: ToPy a => a -> IO SomeObject -- | FromPy instances indicate that a type can be marshalled from -- Python to Haskell automatically -- -- For example, FromPy Integer indicates that we know how to -- take some Python object and convert it into a Haskell Integer. If the -- Python object is int, then we can cast properly. Failed casts -- throw a PyCastException class FromPy a -- | Takes some Python object, and converts it to the corresponding Haskell -- type by going over FFI. Might throw a PyCastException -- -- Generally you'll only need to call fromPy manually on some type -- when writing your own FromPy instances for another type fromPy :: FromPy a => SomeObject -> IO a -- | An exception representing a failed cast from a Python object to -- Haskell value, usually because the expected type of the Python object -- was not correct. -- -- Carries a String which represents the name of the expected -- Haskell type which caused a failed cast. If using easyFromPy, -- this String is found with typeRep data PyCastException PyCastException :: String -> PyCastException -- | Helper that lets you convert a Haskell value to a Python object by -- providing both a Python conversion function (from the Haskell type, -- over FFI, to some Python Object) as well as the Haskell value -- -- Lets you define toPy with just a Python conversion function easyToPy :: Object p => (h -> IO p) -> h -> IO SomeObject -- | Helper that takes a conversion function and a Python object, and casts -- the Python object into a Haskell value. -- -- Lets you define fromPy with just a Python conversion function -- -- We use Proxy to infer the type name for use in case of a failed -- cast. In the context of defining an instance, this type will be -- inferrable, so you can just provide a Proxy value easyFromPy :: (Concrete p, Typeable h) => (p -> IO h) -> Proxy h -> SomeObject -> IO h instance GHC.Show.Show CPython.Simple.Instances.PyCastException instance GHC.Exception.Type.Exception CPython.Simple.Instances.PyCastException instance CPython.Simple.Instances.FromPy GHC.Types.Bool instance CPython.Simple.Instances.FromPy GHC.Num.Integer.Integer instance CPython.Simple.Instances.FromPy GHC.Types.Double instance CPython.Simple.Instances.FromPy Data.Text.Internal.Text instance CPython.Simple.Instances.FromPy GHC.Types.Char instance CPython.Simple.Instances.FromPy GHC.Base.String instance (CPython.Simple.Instances.FromPy a, CPython.Simple.Instances.FromPy b) => CPython.Simple.Instances.FromPy (a, b) instance (CPython.Simple.Instances.FromPy a, CPython.Simple.Instances.FromPy b, CPython.Simple.Instances.FromPy c) => CPython.Simple.Instances.FromPy (a, b, c) instance (CPython.Simple.Instances.FromPy a, CPython.Simple.Instances.FromPy b, CPython.Simple.Instances.FromPy c, CPython.Simple.Instances.FromPy d) => CPython.Simple.Instances.FromPy (a, b, c, d) instance CPython.Simple.Instances.FromPy a => CPython.Simple.Instances.FromPy (GHC.Maybe.Maybe a) instance CPython.Simple.Instances.FromPy a => CPython.Simple.Instances.FromPy [a] instance CPython.Simple.Instances.FromPy () instance CPython.Simple.Instances.ToPy GHC.Types.Bool instance CPython.Simple.Instances.ToPy GHC.Num.Integer.Integer instance CPython.Simple.Instances.ToPy GHC.Types.Double instance CPython.Simple.Instances.ToPy Data.Text.Internal.Text instance CPython.Simple.Instances.ToPy GHC.Types.Char instance CPython.Simple.Instances.ToPy GHC.Base.String instance (CPython.Simple.Instances.ToPy a, CPython.Simple.Instances.ToPy b) => CPython.Simple.Instances.ToPy (a, b) instance (CPython.Simple.Instances.ToPy a, CPython.Simple.Instances.ToPy b, CPython.Simple.Instances.ToPy c) => CPython.Simple.Instances.ToPy (a, b, c) instance (CPython.Simple.Instances.ToPy a, CPython.Simple.Instances.ToPy b, CPython.Simple.Instances.ToPy c, CPython.Simple.Instances.ToPy d) => CPython.Simple.Instances.ToPy (a, b, c, d) instance CPython.Simple.Instances.ToPy a => CPython.Simple.Instances.ToPy (GHC.Maybe.Maybe a) instance CPython.Simple.Instances.ToPy a => CPython.Simple.Instances.ToPy [a] module CPython.Simple -- | Builds a Python argument from any Haskell type with a ToPy -- instance arg :: ToPy a => a -> Arg -- | FromPy instances indicate that a type can be marshalled from -- Python to Haskell automatically -- -- For example, FromPy Integer indicates that we know how to -- take some Python object and convert it into a Haskell Integer. If the -- Python object is int, then we can cast properly. Failed casts -- throw a PyCastException class FromPy a -- | Takes some Python object, and converts it to the corresponding Haskell -- type by going over FFI. Might throw a PyCastException -- -- Generally you'll only need to call fromPy manually on some type -- when writing your own FromPy instances for another type fromPy :: FromPy a => SomeObject -> IO a -- | An exception representing a failed cast from a Python object to -- Haskell value, usually because the expected type of the Python object -- was not correct. -- -- Carries a String which represents the name of the expected -- Haskell type which caused a failed cast. If using easyFromPy, -- this String is found with typeRep data PyCastException PyCastException :: String -> PyCastException -- | ToPy instances indicate that a type can be marshalled from -- Haskell to Python automatically -- -- For example, ToPy Integer indicates that we know how to take -- a Haskell Integer and convert it into a Python int -- object class ToPy a -- | Takes some Haskell type, and converts it to a Python object by going -- over FFI -- -- Generally you'll only need to call toPy manually on some type -- when writing your own ToPy instances for another type toPy :: ToPy a => a -> IO SomeObject -- | The most common use case of Simple is calling some Python -- function -- -- For example, if we wanted to wrap Python's random.randint(low, -- high), we could write this: -- --
--   randint :: Integer -> Integer -> IO Integer
--   randint low high =
--     call "random" "randint" [arg low, arg high] []
--   
-- -- Because of the FromPy instance in call's type signature, -- we can infer what to do to convert a Python value back into Haskell, -- if given the type. In this example using random.uniform, -- although we use a similar definition as for randint, we -- correct cast to Double instead of Integer -- --
--   uniform :: Integer -> Integer -> IO Double
--   uniform low high =
--     call "random" "uniform" [arg low, arg high] []
--   
-- -- We can also use the TypeApplications language extension to -- tell call what type to use, if needed -- --
--   call @Double "random" "uniform" [arg low, arg high] []
--   
-- -- Calling a function with mixed positional and keyword arguments is also -- fairly straightforward. -- -- The example is equivalent to calling pyautogui.moveTo(x, y, -- duration=seconds) -- --
--   moveToDuration :: Integer -> Integer -> Double -> IO ()
--   moveToDuration x y seconds =
--     call "pyautogui" "moveTo" [arg x, arg y] [("duration", arg seconds)]
--   
call :: FromPy a => Text -> Text -> [Arg] -> [(Text, Arg)] -> IO a -- | Helper that takes a conversion function and a Python object, and casts -- the Python object into a Haskell value. -- -- Lets you define fromPy with just a Python conversion function -- -- We use Proxy to infer the type name for use in case of a failed -- cast. In the context of defining an instance, this type will be -- inferrable, so you can just provide a Proxy value easyFromPy :: (Concrete p, Typeable h) => (p -> IO h) -> Proxy h -> SomeObject -> IO h -- | Helper that lets you convert a Haskell value to a Python object by -- providing both a Python conversion function (from the Haskell type, -- over FFI, to some Python Object) as well as the Haskell value -- -- Lets you define toPy with just a Python conversion function easyToPy :: Object p => (h -> IO p) -> h -> IO SomeObject -- | Get the value of an attribute of some Python module -- -- This example is equivalent to getting random.BPF in Python -- --
--   getBpf :: IO Integer
--   getBpf = getAttribute "random" "BPF"
--   
getAttribute :: FromPy a => Text -> Text -> IO a -- | Given a Python module name as text, imports it as a Module -- -- Throws an exception if e.g. the module name was misspelled, or isn't -- installed importModule :: Text -> IO Module -- | Kicks off talking to Python, and will need to be called before using -- other functions initialize :: IO () -- | Set the value of an attribute of some Python module -- -- This example is equivalent to setting random.BPF = n in -- Python -- --
--   setBpf :: Integer -> IO ()
--   setBpf n = setAttribute "random" "BPF" n
--   
setAttribute :: ToPy a => Text -> Text -> a -> IO () instance CPython.Simple.Instances.ToPy CPython.Simple.Arg