neulab/docprompting-conala huggingface dataset:
pop_all()  
Transfers the callback stack to a fresh ExitStack instance and returns it. No callbacks are invoked by this operation - instead, they will now be invoked when the new stack is closed (either explicitly or implicitly at the end of a with statement). For example, a group of files can be opened as an “all or nothing” operation as follows: with ExitStack() as stack:
    files = [stack.enter_context(open(fname)) for fname in filenames]
    # Hold onto the close method, but don't call it yet.
    close_files = stack.pop_all().close
    # If opening any file fails, all previously opened files will be
    # closed automatically. If all files are opened successfully,
    # they will remain open even after the with statement ends.
    # close_files() can then be invoked explicitly to close them all.
push(exit)  
Adds a context manager’s __exit__() method to the callback stack. As __enter__ is not invoked, this method can be used to cover part of an __enter__() implementation with a context manager’s own __exit__() method. If passed an object that is not a context manager, this method assumes it is a callback with the same signature as a context manager’s __exit__() method and adds it directly to the callback stack. By returning true values, these callbacks can suppress exceptions the same way context manager __exit__() methods can. The passed in object is returned from the function, allowing this method to be used as a function decorator.
contextlib.nullcontext(enter_result=None)  
Return a context manager that returns enter_result from __enter__, but otherwise does nothing. It is intended to be used as a stand-in for an optional context manager, for example: def myfunction(arg, ignore_exceptions=False):
    if ignore_exceptions:
        # Use suppress to ignore all exceptions.
        cm = contextlib.suppress(Exception)
    else:
        # Do not ignore any exceptions, cm has no effect.
        cm = contextlib.nullcontext()
    with cm:
        # Do something
 An example using enter_result: def process_file(file_or_path):
    if isinstance(file_or_path, str):
        # If string, open file
        cm = open(file_or_path)
    else:
        # Caller is responsible for closing file
        cm = nullcontext(file_or_path)

    with cm as file:
        # Perform processing on the file
  New in version 3.7.
contextlib.redirect_stderr(new_target)  
Similar to redirect_stdout() but redirecting sys.stderr to another file or file-like object. This context manager is reentrant.  New in version 3.5.
contextlib.redirect_stdout(new_target)  
Context manager for temporarily redirecting sys.stdout to another file or file-like object. This tool adds flexibility to existing functions or classes whose output is hardwired to stdout. For example, the output of help() normally is sent to sys.stdout. You can capture that output in a string by redirecting the output to an io.StringIO object: f = io.StringIO()
with redirect_stdout(f):
    help(pow)
s = f.getvalue()
 To send the output of help() to a file on disk, redirect the output to a regular file: with open('help.txt', 'w') as f:
    with redirect_stdout(f):
        help(pow)
 To send the output of help() to sys.stderr: with redirect_stdout(sys.stderr):
    help(pow)
 Note that the global side effect on sys.stdout means that this context manager is not suitable for use in library code and most threaded applications. It also has no effect on the output of subprocesses. However, it is still a useful approach for many utility scripts. This context manager is reentrant.  New in version 3.4.
contextlib.suppress(*exceptions)  
Return a context manager that suppresses any of the specified exceptions if they occur in the body of a with statement and then resumes execution with the first statement following the end of the with statement. As with any other mechanism that completely suppresses exceptions, this context manager should be used only to cover very specific errors where silently continuing with program execution is known to be the right thing to do. For example: from contextlib import suppress

with suppress(FileNotFoundError):
    os.remove('somefile.tmp')

with suppress(FileNotFoundError):
    os.remove('someotherfile.tmp')
 This code is equivalent to: try:
    os.remove('somefile.tmp')
except FileNotFoundError:
    pass

try:
    os.remove('someotherfile.tmp')
except FileNotFoundError:
    pass
 This context manager is reentrant.  New in version 3.4.
contextmanager.__enter__()  
Enter the runtime context and return either this object or another object related to the runtime context. The value returned by this method is bound to the identifier in the as clause of with statements using this context manager. An example of a context manager that returns itself is a file object. File objects return themselves from __enter__() to allow open() to be used as the context expression in a with statement. An example of a context manager that returns a related object is the one returned by decimal.localcontext(). These managers set the active decimal context to a copy of the original decimal context and then return the copy. This allows changes to be made to the current decimal context in the body of the with statement without affecting code outside the with statement.
contextmanager.__exit__(exc_type, exc_val, exc_tb)  
Exit the runtime context and return a Boolean flag indicating if any exception that occurred should be suppressed. If an exception occurred while executing the body of the with statement, the arguments contain the exception type, value and traceback information. Otherwise, all three arguments are None. Returning a true value from this method will cause the with statement to suppress the exception and continue execution with the statement immediately following the with statement. Otherwise the exception continues propagating after this method has finished executing. Exceptions that occur during execution of this method will replace any exception that occurred in the body of the with statement. The exception passed in should never be reraised explicitly - instead, this method should return a false value to indicate that the method completed successfully and does not want to suppress the raised exception. This allows context management code to easily detect whether or not an __exit__() method has actually failed.
class contextvars.Context  
A mapping of ContextVars to their values. Context() creates an empty context with no values in it. To get a copy of the current context use the copy_context() function. Context implements the collections.abc.Mapping interface.  
run(callable, *args, **kwargs)  
Execute callable(*args, **kwargs) code in the context object the run method is called on. Return the result of the execution or propagate an exception if one occurred. Any changes to any context variables that callable makes will be contained in the context object: var = ContextVar('var')
var.set('spam')

def main():
    # 'var' was set to 'spam' before
    # calling 'copy_context()' and 'ctx.run(main)', so:
    # var.get() == ctx[var] == 'spam'

    var.set('ham')

    # Now, after setting 'var' to 'ham':
    # var.get() == ctx[var] == 'ham'

ctx = copy_context()

# Any changes that the 'main' function makes to 'var'
# will be contained in 'ctx'.
ctx.run(main)

# The 'main()' function was run in the 'ctx' context,
# so changes to 'var' are contained in it:
# ctx[var] == 'ham'

# However, outside of 'ctx', 'var' is still set to 'spam':
# var.get() == 'spam'
 The method raises a RuntimeError when called on the same context object from more than one OS thread, or when called recursively. 
  
copy()  
Return a shallow copy of the context object. 
  
var in context  
Return True if the context has a value for var set; return False otherwise. 
  
context[var]  
Return the value of the var ContextVar variable. If the variable is not set in the context object, a KeyError is raised. 
  
get(var[, default])  
Return the value for var if var has the value in the context object. Return default otherwise. If default is not given, return None. 
  
iter(context)  
Return an iterator over the variables stored in the context object. 
  
len(proxy)  
Return the number of variables set in the context object. 
  
keys()  
Return a list of all variables in the context object. 
  
values()  
Return a list of all variables’ values in the context object. 
  
items()  
Return a list of 2-tuples containing all variables and their values in the context object.
get(var[, default])  
Return the value for var if var has the value in the context object. Return default otherwise. If default is not given, return None.
items()  
Return a list of 2-tuples containing all variables and their values in the context object.
run(callable, *args, **kwargs)  
Execute callable(*args, **kwargs) code in the context object the run method is called on. Return the result of the execution or propagate an exception if one occurred. Any changes to any context variables that callable makes will be contained in the context object: var = ContextVar('var')
var.set('spam')

def main():
    # 'var' was set to 'spam' before
    # calling 'copy_context()' and 'ctx.run(main)', so:
    # var.get() == ctx[var] == 'spam'

    var.set('ham')

    # Now, after setting 'var' to 'ham':
    # var.get() == ctx[var] == 'ham'

ctx = copy_context()

# Any changes that the 'main' function makes to 'var'
# will be contained in 'ctx'.
ctx.run(main)

# The 'main()' function was run in the 'ctx' context,
# so changes to 'var' are contained in it:
# ctx[var] == 'ham'

# However, outside of 'ctx', 'var' is still set to 'spam':
# var.get() == 'spam'
 The method raises a RuntimeError when called on the same context object from more than one OS thread, or when called recursively.
class contextvars.ContextVar(name[, *, default])  
This class is used to declare a new Context Variable, e.g.: var: ContextVar[int] = ContextVar('var', default=42)
 The required name parameter is used for introspection and debug purposes. The optional keyword-only default parameter is returned by ContextVar.get() when no value for the variable is found in the current context. Important: Context Variables should be created at the top module level and never in closures. Context objects hold strong references to context variables which prevents context variables from being properly garbage collected.  
name  
The name of the variable. This is a read-only property.  New in version 3.7.1.  
  
get([default])  
Return a value for the context variable for the current context. If there is no value for the variable in the current context, the method will:  return the value of the default argument of the method, if provided; or return the default value for the context variable, if it was created with one; or raise a LookupError.  
  
set(value)  
Call to set a new value for the context variable in the current context. The required value argument is the new value for the context variable. Returns a Token object that can be used to restore the variable to its previous value via the ContextVar.reset() method. 
  
reset(token)  
Reset the context variable to the value it had before the ContextVar.set() that created the token was used. For example: var = ContextVar('var')

token = var.set('new value')
# code that uses 'var'; var.get() returns 'new value'.
var.reset(token)

# After the reset call the var has no value again, so
# var.get() would raise a LookupError.
get([default])  
Return a value for the context variable for the current context. If there is no value for the variable in the current context, the method will:  return the value of the default argument of the method, if provided; or return the default value for the context variable, if it was created with one; or raise a LookupError.
name  
The name of the variable. This is a read-only property.  New in version 3.7.1.
reset(token)  
Reset the context variable to the value it had before the ContextVar.set() that created the token was used. For example: var = ContextVar('var')

token = var.set('new value')
# code that uses 'var'; var.get() returns 'new value'.
var.reset(token)

# After the reset call the var has no value again, so
# var.get() would raise a LookupError.
set(value)  
Call to set a new value for the context variable in the current context. The required value argument is the new value for the context variable. Returns a Token object that can be used to restore the variable to its previous value via the ContextVar.reset() method.
class contextvars.Token  
Token objects are returned by the ContextVar.set() method. They can be passed to the ContextVar.reset() method to revert the value of the variable to what it was before the corresponding set.  
Token.var  
A read-only property. Points to the ContextVar object that created the token. 
  
Token.old_value  
A read-only property. Set to the value the variable had before the ContextVar.set() method call that created the token. It points to Token.MISSING is the variable was not set before the call. 
  
Token.MISSING  
A marker object used by Token.old_value.
Token.old_value  
A read-only property. Set to the value the variable had before the ContextVar.set() method call that created the token. It points to Token.MISSING is the variable was not set before the call.
Token.var  
A read-only property. Points to the ContextVar object that created the token.
contextvars.copy_context()  
Returns a copy of the current Context object. The following snippet gets a copy of the current context and prints all variables and their values that are set in it: ctx: Context = copy_context()
print(list(ctx.items()))
 The function has an O(1) complexity, i.e. works equally fast for contexts with a few context variables and for contexts that have a lot of them.
copy — Shallow and deep copy operations Source code: Lib/copy.py Assignment statements in Python do not copy objects, they create bindings between a target and an object. For collections that are mutable or contain mutable items, a copy is sometimes needed so one can change one copy without changing the other. This module provides generic shallow and deep copy operations (explained below). Interface summary:  
copy.copy(x)  
Return a shallow copy of x. 
  
copy.deepcopy(x[, memo])  
Return a deep copy of x. 
  
exception copy.Error  
Raised for module specific errors. 
 The difference between shallow and deep copying is only relevant for compound objects (objects that contain other objects, like lists or class instances):  A shallow copy constructs a new compound object and then (to the extent possible) inserts references into it to the objects found in the original. A deep copy constructs a new compound object and then, recursively, inserts copies into it of the objects found in the original.  Two problems often exist with deep copy operations that don’t exist with shallow copy operations:  Recursive objects (compound objects that, directly or indirectly, contain a reference to themselves) may cause a recursive loop. Because deep copy copies everything it may copy too much, such as data which is intended to be shared between copies.  The deepcopy() function avoids these problems by:  keeping a memo dictionary of objects already copied during the current copying pass; and letting user-defined classes override the copying operation or the set of components copied.  This module does not copy types like module, method, stack trace, stack frame, file, socket, window, array, or any similar types. It does “copy” functions and classes (shallow and deeply), by returning the original object unchanged; this is compatible with the way these are treated by the pickle module. Shallow copies of dictionaries can be made using dict.copy(), and of lists by assigning a slice of the entire list, for example, copied_list = original_list[:]. Classes can use the same interfaces to control copying that they use to control pickling. See the description of module pickle for information on these methods. In fact, the copy module uses the registered pickle functions from the copyreg module. In order for a class to define its own copy implementation, it can define special methods __copy__() and __deepcopy__(). The former is called to implement the shallow copy operation; no additional arguments are passed. The latter is called to implement the deep copy operation; it is passed one argument, the memo dictionary. If the __deepcopy__() implementation needs to make a deep copy of a component, it should call the deepcopy() function with the component as first argument and the memo dictionary as second argument.  See also  
Module pickle


Discussion of the special methods used to support object state retrieval and restoration.
copyreg — Register pickle support functions Source code: Lib/copyreg.py The copyreg module offers a way to define functions used while pickling specific objects. The pickle and copy modules use those functions when pickling/copying those objects. The module provides configuration information about object constructors which are not classes. Such constructors may be factory functions or class instances.  
copyreg.constructor(object)  
Declares object to be a valid constructor. If object is not callable (and hence not valid as a constructor), raises TypeError. 
  
copyreg.pickle(type, function, constructor=None)  
Declares that function should be used as a “reduction” function for objects of type type. function should return either a string or a tuple containing two or three elements. The optional constructor parameter, if provided, is a callable object which can be used to reconstruct the object when called with the tuple of arguments returned by function at pickling time. TypeError will be raised if object is a class or constructor is not callable. See the pickle module for more details on the interface expected of function and constructor. Note that the dispatch_table attribute of a pickler object or subclass of pickle.Pickler can also be used for declaring reduction functions. 
 Example The example below would like to show how to register a pickle function and how it will be used: >>> import copyreg, copy, pickle
>>> class C:
...     def __init__(self, a):
...         self.a = a
...
>>> def pickle_c(c):
...     print("pickling a C instance...")
...     return C, (c.a,)
...
>>> copyreg.pickle(C, pickle_c)
>>> c = C(1)
>>> d = copy.copy(c)  
pickling a C instance...
>>> p = pickle.dumps(c)  
pickling a C instance...
copyreg.constructor(object)  
Declares object to be a valid constructor. If object is not callable (and hence not valid as a constructor), raises TypeError.
copyreg.pickle(type, function, constructor=None)  
Declares that function should be used as a “reduction” function for objects of type type. function should return either a string or a tuple containing two or three elements. The optional constructor parameter, if provided, is a callable object which can be used to reconstruct the object when called with the tuple of arguments returned by function at pickling time. TypeError will be raised if object is a class or constructor is not callable. See the pickle module for more details on the interface expected of function and constructor. Note that the dispatch_table attribute of a pickler object or subclass of pickle.Pickler can also be used for declaring reduction functions.
copyright  
credits  
Objects that when printed or called, print the text of copyright or credits, respectively.
crypt.crypt(word, salt=None)  
word will usually be a user’s password as typed at a prompt or in a graphical interface. The optional salt is either a string as returned from mksalt(), one of the crypt.METHOD_* values (though not all may be available on all platforms), or a full encrypted password including salt, as returned by this function. If salt is not provided, the strongest method will be used (as returned by methods()). Checking a password is usually done by passing the plain-text password as word and the full results of a previous crypt() call, which should be the same as the results of this call. salt (either a random 2 or 16 character string, possibly prefixed with $digit$ to indicate the method) which will be used to perturb the encryption algorithm. The characters in salt must be in the set [./a-zA-Z0-9], with the exception of Modular Crypt Format which prefixes a $digit$. Returns the hashed password as a string, which will be composed of characters from the same alphabet as the salt. Since a few crypt(3) extensions allow different values, with different sizes in the salt, it is recommended to use the full crypted password as salt when checking for a password.  Changed in version 3.3: Accept crypt.METHOD_* values in addition to strings for salt.
crypt.methods  
A list of available password hashing algorithms, as crypt.METHOD_* objects. This list is sorted from strongest to weakest.
crypt.METHOD_BLOWFISH  
Another Modular Crypt Format method with 22 character salt and 31 character hash based on the Blowfish cipher.  New in version 3.7.
crypt.METHOD_CRYPT  
The traditional method with a 2 character salt and 13 characters of hash. This is the weakest method.
crypt.METHOD_MD5  
Another Modular Crypt Format method with 8 character salt and 22 character hash based on the MD5 hash function.
crypt.METHOD_SHA256  
Another Modular Crypt Format method with 16 character salt and 43 character hash based on the SHA-256 hash function.
crypt.METHOD_SHA512  
A Modular Crypt Format method with 16 character salt and 86 character hash based on the SHA-512 hash function. This is the strongest method.
crypt.mksalt(method=None, *, rounds=None)  
Return a randomly generated salt of the specified method. If no method is given, the strongest method available as returned by methods() is used. The return value is a string suitable for passing as the salt argument to crypt(). rounds specifies the number of rounds for METHOD_SHA256, METHOD_SHA512 and METHOD_BLOWFISH. For METHOD_SHA256 and METHOD_SHA512 it must be an integer between 1000 and 999_999_999, the default is 5000. For METHOD_BLOWFISH it must be a power of two between 16 (24) and 2_147_483_648 (231), the default is 4096 (212).  New in version 3.3.   Changed in version 3.7: Added the rounds parameter.
csvreader.dialect  
A read-only description of the dialect in use by the parser.
csvreader.fieldnames  
If not passed as a parameter when creating the object, this attribute is initialized upon first access or when the first record is read from the file.
csvreader.line_num  
The number of lines read from the source iterator. This is not the same as the number of records returned, as records can span multiple lines.
csvreader.__next__()  
Return the next row of the reader’s iterable object as a list (if the object was returned from reader()) or a dict (if it is a DictReader instance), parsed according to the current dialect. Usually you should call this as next(reader).
csvwriter.writerow(row)  
Write the row parameter to the writer’s file object, formatted according to the current dialect. Return the return value of the call to the write method of the underlying file object.  Changed in version 3.5: Added support of arbitrary iterables.
csvwriter.writerows(rows)  
Write all elements in rows (an iterable of row objects as described above) to the writer’s file object, formatted according to the current dialect.
class csv.Dialect  
The Dialect class is a container class relied on primarily for its attributes, which are used to define the parameters for a specific reader or writer instance.
Dialect.delimiter  
A one-character string used to separate fields. It defaults to ','.
Dialect.doublequote  
Controls how instances of quotechar appearing inside a field should themselves be quoted. When True, the character is doubled. When False, the escapechar is used as a prefix to the quotechar. It defaults to True. On output, if doublequote is False and no escapechar is set, Error is raised if a quotechar is found in a field.
Dialect.escapechar  
A one-character string used by the writer to escape the delimiter if quoting is set to QUOTE_NONE and the quotechar if doublequote is False. On reading, the escapechar removes any special meaning from the following character. It defaults to None, which disables escaping.