output
stringlengths
1
928k
instruction
stringlengths
7
928k
system
stringlengths
0
104k
get list of files in a pull request
Given the following Python 3 function, write the documentation def get_pull_request_files(project, num, auth=False): url = "https://api.github.com/repos/{project}/pulls/{num}/files".format(project=project, num=num) if auth: header = make_auth_header() else: header = None return get_paged...
You are a Python code analyst, evaluating scripts for potential improvements.
def get_paged_request(url, headers=None, **params): """get a full list, handling APIv3's paging""" results = [] params.setdefault("per_page", 100) while True: if '?' in url: params = None print("fetching %s" % url, file=sys.stderr) else: print("fetchin...
Write a Python 3 function that can get a full list handling APIv3 s paging
As a python code expert, you are capable of creating scripts from specifications.
def get_pulls_list(project, auth=False, **params): """get pull request list""" params.setdefault("state", "closed") url = "https://api.github.com/repos/{project}/pulls".format(project=project) if auth: headers = make_auth_header() else: headers = None pages = get_paged_request(ur...
Can you write a function in Python 3 where it gets pull request list
As a python code expert, you are capable of creating scripts from specifications.
Encode a dictionary of fields using the multipart - form - data mime format.
Here you have a function in Python 3, explain what it does def encode_multipart_formdata(fields, boundary=None): # copy requests imports in here: from io import BytesIO from requests.packages.urllib3.filepost import ( choose_boundary, six, writer, b, get_content_type ) body = BytesIO() i...
You are a Python code architect, reviewing and designing scalable and efficient code
def post_download(project, filename, name=None, description=""): """Upload a file to the GitHub downloads area""" if name is None: name = os.path.basename(filename) with open(filename, 'rb') as f: filedata = f.read() url = "https://api.github.com/repos/{project}/downloads".format(projec...
Implement a Python 3 function for uploading a file to the GitHub downloads area
As a Python code composer, you craft elegant and concise scripts.
def is_executable_file(path): """Checks that path is an executable regular file (or a symlink to a file). This is roughly ``os.path isfile(path) and os.access(path, os.X_OK)``, but on some platforms :func:`os.access` gives us the wrong answer, so this checks permission bits directly. Note ----...
Write a Python 3 script for checking that the given path is an executable regular file or a symlink to a file.
As a python code expert, you are capable of creating scripts from specifications.
def build_matlab(static=False): """build the messenger mex for MATLAB static : bool Determines if the zmq library has been statically linked. If so, it will append the command line option -DZMQ_STATIC when compiling the mex so it matches libzmq. """ cfg = get_config() # To d...
Write a Python 3 function for building the messenger mex for MATLAB
As a Python code composer, you craft elegant and concise scripts.
def add_method(function, klass, name=None): '''Add an existing function to a class as a method. Note: Consider using the extend decorator as a more readable alternative to using this function directly. Args: function: The function to be added to the class klass. klass: Th...
Can you implement a function in Python 3 that adds an existing function to a class as a method.
You are a Python code analyst, evaluating scripts for potential improvements.
A function decorator for extending an existing class. Use as a decorator for functions to add to an existing class.
Here you have a function in Python 3, explain what it does def extend(klass, name=None): '''A function decorator for extending an existing class. Use as a decorator for functions to add to an existing class. Args: klass: The class to be decorated. name: The name the new method is ...
You are a Python code generator, capable of creating scripts from specifications.
def select( self, selector): '''Transforms each element of a sequence into a new form. Each element of the source is transformed through a selector function to produce a corresponding element in teh result sequence. If the selector is identity the method will re...
Can you write a function in Python 3 where it transforms each element of a sequence into a new form.
You are a Python code generator, capable of creating scripts from specifications.
Returns a new sequence where each element of a source sequence is transformed into a new form incorporating the index of the element.
Can you generate the documentation for the following Python 3 function def select_with_index( self, selector=IndexedElement, transform=identity): '''Transforms each element of a sequence into a new form, incorporating the index of the element. Each element is...
You are a Python code generator, capable of creating scripts from specifications.
def select_with_correspondence( self, selector, result_selector=KeyedElement): '''Apply a callable to each element in an input sequence, generating a new sequence of 2-tuples where the first element is the input value and the second is the transformed input va...
Can you create a Python 3 function that applies a callable to each element in an input sequence generating a new sequence of 2 - tuples where the first element is the input value and the second is the transformed input value.
As a python code expert, you are capable of creating scripts from specifications.
def select_many( self, collection_selector=identity, result_selector=identity): '''Projects each element of a sequence to an intermediate new sequence, flattens the resulting sequences into one sequence and optionally transforms the flattened sequence using a ...
Can you create a Python 3 function that returns a new Queryable over the elements of the source sequence that are contained in the result sequence.
As a Python code analyst, you investigate and solve complex coding mysteries
def select_many_with_index( self, collection_selector=IndexedElement, result_selector=lambda source_element, collection_element: collection_element): '''Projects each element of a sequence to an intermediate new sequence, incorporati...
Can you create a Python 3 function that projects each element of a sequence to an intermediate new sequence and concatenates the resulting sequence into one sequence and optionally transforms the flattened intermediate sequence into one sequence.
As a Python code translator, you convert algorithms and pseudocode into Python.
def select_many_with_correspondence( self, collection_selector=identity, result_selector=KeyedElement): '''Projects each element of a sequence to an intermediate new sequence, and flattens the resulting sequence, into one sequence and uses a selector function ...
Write a Python 3 function that can project each element of a sequence to an intermediate new sequence and flattens the resulting sequence into one sequence and uses a selector function to incorporate each corresponding source for each item in the result sequence.
As a Python code translator, you convert algorithms and pseudocode into Python.
def group_by(self, key_selector=identity, element_selector=identity, result_selector=lambda key, grouping: grouping): '''Groups the elements according to the value of a key extracted by a selector function. Note: This method has different behaviour to itertools...
How would you code a function in Python 3 to group the elements of the source sequence according to the value of a key extracted by a selector function.
You are a Python code analyst, evaluating scripts for potential improvements.
Returns a new Queryable with the elements from which the predicate returns True.
Explain what the following Python 3 code does def where(self, predicate): '''Filters elements according to whether they match a predicate. Note: This method uses deferred execution. Args: predicate: A unary function which is applied to each element in the source seq...
As a Python code translator, you convert algorithms and pseudocode into Python.
Returns a new Queryable object containing only the elements of the given classinfo.
Can you generate a brief explanation for the following Python 3 code def of_type(self, classinfo): '''Filters elements according to whether they are of a certain type. Note: This method uses deferred execution. Args: classinfo: If classinfo is neither a class object nor a type obje...
You are a Python code architect, reviewing and designing scalable and efficient code
Sorts the elements of the elements in ascending order.
Here you have a function in Python 3, explain what it does def order_by(self, key_selector=identity): '''Sorts by a key in ascending order. Introduces a primary sorting order to the sequence. Additional sort criteria should be specified by subsequent calls to then_by() and then_by_desce...
You are a Python code architect, reviewing and designing scalable and efficient code
Returns a specified number of elements from the start of a sequence.
Here you have a function in Python 3, explain what it does def take(self, count=1): '''Returns a specified number of elements from the start of a sequence. If the source sequence contains fewer elements than requested only the available elements will be returned and no exception will be raised....
As a Python code analyst, you investigate and solve complex coding mysteries
def take_while(self, predicate): '''Returns elements from the start while the predicate is True. Note: This method uses deferred execution. Args: predicate: A function returning True or False with which elements will be tested. Returns: A Querya...
How would you code a function in Python 3 to return the elements from the beginning of the source sequence for which the predicate returns True or False.
As a python code expert, you are capable of creating scripts from specifications.
Skip the first count contiguous elements of the source sequence.
Can you tell what is the following Python 3 function doing def skip(self, count=1): '''Skip the first count contiguous elements of the source sequence. If the source sequence contains fewer than count elements returns an empty sequence and does not raise an exception. Note: This method...
You are a Python code analyst, evaluating scripts for potential improvements.
Return a new Queryable with elements from the start for which a predicate returns True.
Given the following Python 3 function, write the documentation def skip_while(self, predicate): '''Omit elements from the start for which a predicate is True. Note: This method uses deferred execution. Args: predicate: A single argument predicate function. Returns: ...
As a Python code composer, you craft elegant and concise scripts.
def concat(self, second_iterable): '''Concatenates two sequences. Note: This method uses deferred execution. Args: second_iterable: The sequence to concatenate on to the sequence. Returns: A Queryable over the concatenated sequences. Raises: ...
Write a Python 3 script for concatenating two sequences. Note: This method uses deferred execution. Args: second_iterable: The sequence to concatenate on to the sequence. Returns: A Queryable over the concatenated sequences. Raises: ValueError: If the Queryable is closed(). TypeError: If second_iterable is not in fact ...
You are a Python code analyst, evaluating scripts for potential improvements.
Returns the sequence reversed.
Can you generate a brief explanation for the following Python 3 code def reverse(self): '''Returns the sequence reversed. Note: This method uses deferred execution, but the whole source sequence is consumed once execution commences. Returns: The source sequence in rever...
You are a Python code architect, reviewing and designing scalable and efficient code
def element_at(self, index): '''Return the element at ordinal index. Note: This method uses immediate execution. Args: index: The index of the element to be returned. Returns: The element at ordinal index in the source sequence. Raises: Val...
How would you code a function in Python 3 to return the element at the specified index in the source sequence.
As a Python code analyst, you investigate and solve complex coding mysteries
Return the number of elements in the sequence that satisfy the predicate.
Can you generate the documentation for the following Python 3 function def count(self, predicate=None): '''Return the number of elements (which match an optional predicate). Note: This method uses immediate execution. Args: predicate: An optional unary predicate function used to id...
You are a Python code analyst, evaluating scripts for potential improvements.
Determines if the source sequence contains any elements which satisfy the predicate.
Here you have a function in Python 3, explain what it does def any(self, predicate=None): '''Determine if the source sequence contains any elements which satisfy the predicate. Only enough of the sequence to satisfy the predicate once is consumed. Note: This method uses immediate execu...
As a Python code composer, you craft elegant and concise scripts.
Determine if all elements in the source sequence satisfy a condition.
Explain what the following Python 3 code does def all(self, predicate=bool): '''Determine if all elements in the source sequence satisfy a condition. All of the source sequence will be consumed. Note: This method uses immediate execution. Args: predicate (callable): An opt...
You are a Python code generator, capable of creating scripts from specifications.
def sum(self, selector=identity): '''Return the arithmetic sum of the values in the sequence.. All of the source sequence will be consumed. Note: This method uses immediate execution. Args: selector: An optional single argument function which will be used t...
Write a Python 3 script for returning the arithmetic sum of the values in the sequence.
As a Python code translator, you convert algorithms and pseudocode into Python.
Return the arithmetic mean of the values in the sequence.
Given the following Python 3 function, write the documentation def average(self, selector=identity): '''Return the arithmetic mean of the values in the sequence.. All of the source sequence will be consumed. Note: This method uses immediate execution. Args: selector: An op...
As a python code expert, you are capable of creating scripts from specifications.
Determines whether the sequence contains a particular value.
How would you explain what the following Python 3 function does def contains(self, value, equality_comparer=operator.eq): '''Determines whether the sequence contains a particular value. Execution is immediate. Depending on the type of the sequence, all or none of the sequence may be consumed by...
As a Python code composer, you craft elegant and concise scripts.
Returns a new sequence containing the supplied default value if the source sequence is empty.
Here you have a function in Python 3, explain what it does def default_if_empty(self, default): '''If the source sequence is empty return a single element sequence containing the supplied default value, otherwise return the source sequence unchanged. Note: This method uses deferred exec...
As a Python code analyst, you investigate and solve complex coding mysteries
Eliminate duplicate elements from a sequence.
Can you generate a brief explanation for the following Python 3 code def distinct(self, selector=identity): '''Eliminate duplicate elements from a sequence. Note: This method uses deferred execution. Args: selector: An optional single argument function the result of which ...
As a python code expert, you are capable of creating scripts from specifications.
Returns the elements which are not in the source sequence except the ones in the second_iterable.
Explain what the following Python 3 code does def difference(self, second_iterable, selector=identity): '''Returns those elements which are in the source sequence which are not in the second_iterable. This method is equivalent to the Except() LINQ operator, renamed to a valid Python ide...
As a Python code translator, you convert algorithms and pseudocode into Python.
def intersect(self, second_iterable, selector=identity): '''Returns those elements which are both in the source sequence and in the second_iterable. Note: This method uses deferred execution. Args: second_iterable: Elements are returned if they are also in the ...
Write a Python 3 script for returning those elements which are both in the source sequence and in the second_iterable.
As a Python code analyst, you investigate and solve complex coding mysteries
Returns the elements which are either in the source sequence or in the second_iterable or in both.
Here you have a function in Python 3, explain what it does def union(self, second_iterable, selector=identity): '''Returns those elements which are either in the source sequence or in the second_iterable, or in both. Note: This method uses deferred execution. Args: second_i...
You are a Python code generator, capable of creating scripts from specifications.
Perform an inner join with a second sequence using selected keys.
Explain what the following Python 3 code does def join(self, inner_iterable, outer_key_selector=identity, inner_key_selector=identity, result_selector=lambda outer, inner: (outer, inner)): '''Perform an inner join with a second sequence using selected keys. The order of elemen...
As a Python code composer, you craft elegant and concise scripts.
Match elements of two sequences using keys and group the results.
Can you tell what is the following Python 3 function doing def group_join(self, inner_iterable, outer_key_selector=identity, inner_key_selector=identity, result_selector=lambda outer, grouping: grouping): '''Match elements of two sequences using keys and group the results. The group_join()...
As a Python code analyst, you investigate and solve complex coding mysteries
Returns the first element in a sequence satisfying a predicate.
Given the following Python 3 function, write the documentation def first(self, predicate=None): '''The first element in a sequence (optionally satisfying a predicate). If the predicate is omitted or is None this query returns the first element in the sequence; otherwise, it returns the first el...
You are a Python code generator, capable of creating scripts from specifications.
Returns the first element of the sequence or a default.
Here you have a function in Python 3, explain what it does def first_or_default(self, default, predicate=None): '''The first element (optionally satisfying a predicate) or a default. If the predicate is omitted or is None this query returns the first element in the sequence; otherwise, it retur...
You are a Python code generator, capable of creating scripts from specifications.
def single(self, predicate=None): '''The only element (which satisfies a condition). If the predicate is omitted or is None this query returns the only element in the sequence; otherwise, it returns the only element in the sequence for which the predicate evaluates to True. Exceptions a...
Write a Python 3 script for returning the only element in the source sequence for which the predicate evaluates to True.
You are a Python code generator, capable of creating scripts from specifications.
def single_or_default(self, default, predicate=None): '''The only element (which satisfies a condition) or a default. If the predicate is omitted or is None this query returns the only element in the sequence; otherwise, it returns the only element in the sequence for which the predicat...
Create a Python 3 function to return the only element in the sequence or a default value if the predicate evaluates to True.
You are a Python code generator, capable of creating scripts from specifications.
def last(self, predicate=None): '''The last element in a sequence (optionally satisfying a predicate). If the predicate is omitted or is None this query returns the last element in the sequence; otherwise, it returns the last element in the sequence for which the predicate evaluates to ...
Create a Python 3 function for returning the last element in a sequence for which the predicate evaluates to True.
As a Python code translator, you convert algorithms and pseudocode into Python.
def aggregate(self, reducer, seed=default, result_selector=identity): '''Apply a function over a sequence to produce a single result. Apply a binary function cumulatively to the elements of the source sequence so as to reduce the iterable to a single value. Note: This method uses immed...
Create a Python 3 function for applying a function over a sequence to produce a single result.
You are a Python code generator, capable of creating scripts from specifications.
Convert the source sequence to a list.
How would you explain what the following Python 3 function does def to_list(self): '''Convert the source sequence to a list. Note: This method uses immediate execution. ''' if self.closed(): raise ValueError("Attempt to call to_list() on a closed Queryable.") # Mayb...
As a Python code composer, you craft elegant and concise scripts.
def to_tuple(self): '''Convert the source sequence to a tuple. Note: This method uses immediate execution. ''' if self.closed(): raise ValueError("Attempt to call to_tuple() on a closed Queryable.") if isinstance(self._iterable, tuple): return self._iter...
Create a Python 3 function to convert the source sequence to a tuple.
You are a Python code architect, reviewing and designing scalable and efficient code
Convert the source sequence to a set.
Here you have a function in Python 3, explain what it does def to_set(self): '''Convert the source sequence to a set. Note: This method uses immediate execution. Raises: ValueError: If duplicate keys are in the projected source sequence. ValueError: If the Queryable is ...
As a Python code analyst, you investigate and solve complex coding mysteries
def to_lookup(self, key_selector=identity, value_selector=identity): '''Returns a Lookup object, using the provided selector to generate a key for each item. Note: This method uses immediate execution. ''' if self.closed(): raise ValueError("Attempt to call to_lookup...
Implement a Python 3 function for returning a Lookup object using the provided selector to generate a key for each item.
As a Python code translator, you convert algorithms and pseudocode into Python.
Builds a dictionary from the source sequence.
Explain what the following Python 3 code does def to_dictionary(self, key_selector=identity, value_selector=identity): if self.closed(): raise ValueError("Attempt to call to_dictionary() on a closed Queryable.") if not is_callable(key_selector): raise TypeError("to_dictionary() ...
You are a Python code analyst, evaluating scripts for potential improvements.
def to_str(self, separator=''): '''Build a string from the source sequence. The elements of the query result will each coerced to a string and then the resulting strings concatenated to return a single string. This allows the natural processing of character sequences as strings. An ...
Write a Python 3 script for returning a string from the source sequence.
As a python code expert, you are capable of creating scripts from specifications.
def sequence_equal(self, second_iterable, equality_comparer=operator.eq): ''' Determine whether two sequences are equal by elementwise comparison. Sequence equality is defined as the two sequences being equal length and corresponding elements being equal as determined by the equality ...
Can you implement a function in Python 3 that determines whether two sequences are equal by elementwise comparison.
As a Python code translator, you convert algorithms and pseudocode into Python.
Log the query result consumption details to a logger.
Given the following Python 3 function, write the documentation def log(self, logger=None, label=None, eager=False): ''' Log query result consumption details to a logger. Args: logger: Any object which supports a debug() method which accepts a str, such as a Python st...
As a Python code analyst, you investigate and solve complex coding mysteries
Returns a new sequence where the n - th element of the source sequence is the sum of the cumulative application of the n - th element of the source sequence.
How would you explain what the following Python 3 function does def scan(self, func=operator.add): ''' An inclusive prefix sum which returns the cumulative application of the supplied function up to an including the current element. Args: func: An optional binary function w...
You are a Python code analyst, evaluating scripts for potential improvements.
Returns a new sequence where the first n - elements of the source sequence are the cumulative application of the function up to but excluding the current element.
Make a summary of the following Python 3 code def pre_scan(self, func=operator.add, seed=0): ''' An exclusive prefix sum which returns the cumulative application of the supplied function up to but excluding the current element. Args: func: An optional binary function which ...
As a Python code analyst, you investigate and solve complex coding mysteries
def then_by(self, key_selector=identity): '''Introduce subsequent ordering to the sequence with an optional key. The returned sequence will be sorted in ascending order by the selected key. Note: This method uses deferred execution. Args: key_selector: A unary func...
Implement a Python 3 function for introducing subsequent ordering to the sequence with an optional key.
You are a Python code analyst, evaluating scripts for potential improvements.
def to_dictionary( self, key_selector=lambda item: item.key, value_selector=list): """Build a dictionary from the source sequence. Args: key_selector: A unary callable to extract a key from each item. By default the key of the Grouping. ...
Write a Python 3 script for building a dictionary from the source sequence.
You are a Python code generator, capable of creating scripts from specifications.
def to_dictionary( self, key_selector=None, value_selector=None): """Build a dictionary from the source sequence. Args: key_selector: A unary callable to extract a key from each item or None. If None, the default key selector produces a si...
Implement a function in Python 3 to build a dictionary from the source sequence.
As a Python code analyst, you investigate and solve complex coding mysteries
def integers(start, count): '''Generates in sequence the integral numbers within a range. Note: This method uses deferred execution. Args: start: The first integer in the sequence. count: The number of sequential integers to generate. Returns: A Queryable over the sp...
Can you implement a function in Python 3 that returns a Queryable over the specified range of integers.
You are a Python code analyst, evaluating scripts for potential improvements.
Generate a sequence with one repeated value.
Can you tell what is the following Python 3 function doing def repeat(element, count): '''Generate a sequence with one repeated value. Note: This method uses deferred execution. Args: element: The value to be repeated. count: The number of times to repeat the value. Raises: ...
As a Python code analyst, you investigate and solve complex coding mysteries
Returns an iterator over partitions.
Can you generate a brief explanation for the following Python 3 code def geometric_partitions(iterable, floor=1, ceiling=32768): ''' Partition an iterable into chunks. Returns an iterator over partitions. ''' partition_size = floor run_length = multiprocessing.cpu_count() run_count = 0 ...
You are a Python code architect, reviewing and designing scalable and efficient code
def select(self, selector): '''Transforms each element of a sequence into a new form. Each element is transformed through a selector function to produce a value for each value in the source sequence. The generated sequence is lazily evaluated. Args: selector...
How would you implement a function in Python 3 that transforms each element of a sequence into a new form. Each element is transformed through a selector function to produce a new value for each value in the source sequence. Each element is transformed through a selector function to produce a new value for each value i...
As a python code expert, you are capable of creating scripts from specifications.
def select_with_index(self, selector): '''Transforms each element of a sequence into a new form, incorporating the index of the element. Each element is transformed through a selector function which accepts the element value and its zero-based index in the source sequence. The ...
Can you create a Python 3 function that transforms each element of a sequence into a new form incorporating the index of the element.
As a Python code translator, you convert algorithms and pseudocode into Python.
Projects each element of a sequence to an intermediate new sequence and optionally transforms the flattened sequence into one sequence and optionally returns the selected value.
Given the following Python 3 function, write the documentation def select_many(self, projector, selector=identity): '''Projects each element of a sequence to an intermediate new sequence, flattens the resulting sequence into one sequence and optionally transforms the flattened sequence using ...
You are a Python code analyst, evaluating scripts for potential improvements.
def select(self, selector): '''Transforms each element of a sequence into a new form. Each element is transformed through a selector function to produce a value for each value in the source sequence. The generated sequence is lazily evaluated. Args: selector...
Write a Python 3 script to transform each element of a sequence into a new form. Each element is transformed through a selector function to produce a new value for each value in the source sequence. Each element is transformed through a selector function to produce a new value for each value in the source sequence. The...
As a Python code composer, you craft elegant and concise scripts.
def make_selector(value): '''Create a selector callable from the supplied value. Args: value: If is a callable, then returned unchanged. If a string is used then create an attribute selector. If in an integer is used then create a key selector. Returns: A ...
Write a Python 3 function that can create a selector callable from the supplied value.
You are a Python code generator, capable of creating scripts from specifications.
def adc(self, other : 'BitVector', carry : Bit) -> tp.Tuple['BitVector', Bit]: """ add with carry returns a two element tuple of the form (result, carry) """ T = type(self) other = _coerce(T, other) carry = _coerce(T.unsized_t[1], carry) a = self.zext(1...
How would you implement a function in Python 3 that adds with carry returns a two element tuple of the form result carry + other
As a Python code translator, you convert algorithms and pseudocode into Python.
Take a path with $HOME variables and resolve it to full path.
Can you generate a brief explanation for the following Python 3 code def convert(self, value, *args, **kwargs): # pylint: disable=arguments-differ value = os.path.expanduser(value) return super(ExpandPath, self).convert(value, *args, **kwargs)
You are a Python code generator, capable of creating scripts from specifications.
Make a table from headers and rows.
Given the following Python 3 function, write the documentation def make_table(headers=None, rows=None): if callable(headers): headers = headers() if callable(rows): rows = rows() assert isinstance(headers, list) assert isinstance(rows, list) assert all(len(row) == len(headers) for ro...
As a Python code translator, you convert algorithms and pseudocode into Python.
Help text for a specific command
Can you tell what is the following Python 3 function doing def help(opts, bot, _): command = opts['<command>'] if command is None: return bot.help_text() if command not in bot.commands: return "%r is not a known command" % command return bot.commands[command].__doc__
As a python code expert, you are capable of creating scripts from specifications.
A decorator to convert a function to a command.
Given the following Python 3 function, write the documentation def command(cls, name=None): # adapted from https://github.com/docopt/docopt/blob/master/examples/interactive_example.py def decorator(func): @functools.wraps(func) def _cmd_wrapper(rest, *args, **kwargs): ...
As a Python code analyst, you investigate and solve complex coding mysteries
def help_text(cls): """Return a slack-formatted list of commands with their usage.""" docs = [cmd_func.__doc__ for cmd_func in cls.commands.values()] # Don't want to include 'usage: ' or explanation. usage_lines = [doc.partition('\n')[0] for doc in docs] terse_lines = [line[len(...
How would you implement a function in Python 3 that returns a slack - formatted list of commands with their usage.
You are a Python code generator, capable of creating scripts from specifications.
Run the bot blocking forever.
Explain what the following Python 3 code does def run_forever(self): res = self.slack.rtm.start() self.log.info("current channels: %s", ','.join(c['name'] for c in res.body['channels'] if c['is_member'])) self.id = res.body['self']['id'] ...
As a python code expert, you are capable of creating scripts from specifications.
Return the identifier used to address this bot in this message.
Can you generate a brief explanation for the following Python 3 code def _bot_identifier(self, message): text = message['text'] formatters = [ lambda identifier: "%s " % identifier, lambda identifier: "%s:" % identifier, ] my_identifiers = [formatter(identifier)...
As a Python code translator, you convert algorithms and pseudocode into Python.
def _handle_command_response(self, res, event): """Either send a message (choosing between rtm and postMessage) or ignore the response. :param event: a slacker event dict :param res: a string, a dict, or None. See the command docstring for what these represent. """ re...
How would you code a function in Python 3 to handle the response from a slacker command.
As a Python code translator, you convert algorithms and pseudocode into Python.
def _handle_long_response(self, res): """Splits messages that are too long into multiple events :param res: a slack response string or dict """ is_rtm_message = isinstance(res, basestring) is_api_message = isinstance(res, dict) if is_rtm_message: text = res ...
Can you create a Python 3 function that splits the slack response string or dict into multiple events
As a Python code translator, you convert algorithms and pseudocode into Python.
def _send_rtm_message(self, channel_id, text): """Send a Slack message to a channel over RTM. :param channel_id: a slack channel id. :param text: a slack message. Serverside formatting is done in a similar way to normal user message; see `Slack's docs <https://api.slack.com/...
How would you implement a function in Python 3 that sends a Slack message over RTM.
You are a Python code analyst, evaluating scripts for potential improvements.
Send a Slack message via the chat. postMessage api.
Make a summary of the following Python 3 code def _send_api_message(self, message): self.slack.chat.post_message(**message) self.log.debug("sent api message %r", message)
You are a Python code architect, reviewing and designing scalable and efficient code
def _validators(self): """Iterate across the complete set of child validators.""" for validator in self.__validators__.values(): yield validator if self.validators: for validator in self.validators: yield validator
Write a Python 3 script to iterate across the complete set of child validators.
As a Python code analyst, you investigate and solve complex coding mysteries
def make_user_agent(prefix=None): """Get a suitable user agent for identifying the CLI process.""" prefix = (prefix or platform.platform(terse=1)).strip().lower() return "cloudsmith-cli/%(prefix)s cli:%(version)s api:%(api_version)s" % { "version": get_cli_version(), "api_version": get_api_v...
How would you code a function in Python 3 to return a suitable user agent for identifying the CLI process.
As a Python code composer, you craft elegant and concise scripts.
Pretty print a table from headers and rows.
Given the following Python 3 function, write the documentation def pretty_print_table(headers, rows): table = make_table(headers=headers, rows=rows) pretty_print_table_instance(table)
You are a Python code architect, reviewing and designing scalable and efficient code
Tell the user when we re being rate limited.
Make a summary of the following Python 3 code def print_rate_limit_info(opts, rate_info, atexit=False): if not rate_info: return show_info = ( opts.always_show_rate_limit or atexit or rate_info.interval > opts.rate_limit_warning ) if not show_info: return c...
As a Python code composer, you craft elegant and concise scripts.
Prompt the user for confirmation for dangerous actions.
Can you generate a brief explanation for the following Python 3 code def confirm_operation(prompt, prefix=None, assume_yes=False, err=False): if assume_yes: return True prefix = prefix or click.style( "Are you %s certain you want to" % (click.style("absolutely", bold=True)) ) prompt = ...
You are a Python code analyst, evaluating scripts for potential improvements.
Ensure that login is not blank.
Can you generate a brief explanation for the following Python 3 code def validate_login(ctx, param, value): # pylint: disable=unused-argument value = value.strip() if not value: raise click.BadParameter("The value cannot be blank.", param=param) return value
As a python code expert, you are capable of creating scripts from specifications.
Create default config files.
Given the following Python 3 function, write the documentation def create_config_files(ctx, opts, api_key): # pylint: disable=unused-argument config_reader = opts.get_config_reader() creds_reader = opts.get_creds_reader() has_config = config_reader.has_default_file() has_creds = creds_reader.has_def...
As a Python code translator, you convert algorithms and pseudocode into Python.
Retrieve your API authentication token for the given login and password.
Can you tell what is the following Python 3 function doing def token(ctx, opts, login, password): click.echo( "Retrieving API token for %(login)s ... " % {"login": click.style(login, bold=True)}, nl=False, ) context_msg = "Failed to retrieve the API token!" with handle_api_excep...
You are a Python code generator, capable of creating scripts from specifications.
def status(ctx, opts, owner_repo_package): """ Get the synchronisation status for a package. - OWNER/REPO/PACKAGE: Specify the OWNER namespace (i.e. user or org), the REPO name where the package is stored, and the PACKAGE name (slug) of the package itself. All separated by a slash. Example: 'y...
Write a Python 3 script for getting the synchronisation status for a package.
As a Python code composer, you craft elegant and concise scripts.
def _process_arguments(self, args, kw): """Map positional to keyword arguments, identify invalid assignments, and return the result. This is likely generic enough to be useful as a standalone utility function, and goes to a fair amount of effort to ensure raised exceptions are as Python-like as possible. """...
Create a Python 3 function to map positional to keyword arguments identify invalid assignments and return the result.
As a Python code translator, you convert algorithms and pseudocode into Python.
def import_and_wrap_deprecated(module_name, module_dict, warn_import=True): """ Usage: import_and_wrap_deprecated('conda.common.connection', locals()) # looks for conda.common.connection.__all__ """ if warn_import: deprecated_import(module_name) from importlib import import_...
Implement a Python 3 function for importing and wrap deprecated methods in a module dict.
As a Python code translator, you convert algorithms and pseudocode into Python.
Deprecate a module by adding a proxy to the deprecated_attributes list.
Can you tell what is the following Python 3 function doing def deprecate_module_with_proxy(module_name, module_dict, deprecated_attributes=None): def _ModuleProxy(module, depr): """Return a wrapped object that warns about deprecated accesses""" # http://stackoverflow.com/a/922693/2127762 cla...
As a python code expert, you are capable of creating scripts from specifications.
Convert a foreign value to a native boolean.
Given the following Python 3 function, write the documentation def native(self, value, context=None): value = super().native(value, context) if self.none and (value is None): return None try: value = value.lower() except AttributeError: return bool(value) if value in self.truthy: retur...
As a python code expert, you are capable of creating scripts from specifications.
Convert a native value to a textual boolean.
Can you tell what is the following Python 3 function doing def foreign(self, value, context=None): if self.none and value is None: return '' try: value = self.native(value, context) except Concern: # The value might not be in the lists; bool() evaluate it instead. value = bool(value.strip() if s...
As a Python code composer, you craft elegant and concise scripts.
Get the root path for the application.
Make a summary of the following Python 3 code def get_root_path(): root_path = __file__ return os.path.dirname(os.path.realpath(root_path))
As a Python code translator, you convert algorithms and pseudocode into Python.
def read(path, root_path=None): """Read the specific file into a string in its entirety.""" try: root_path = root_path or get_root_path() real_path = os.path.realpath(os.path.join(root_path, path)) with open(real_path) as fp: return fp.read().strip() except IOError: ...
Can you implement a function in Python 3 that reads the specific file into a string in its entirety.
You are a Python code analyst, evaluating scripts for potential improvements.
Grok the readme turn it into whine ( rst )
Can you generate a brief explanation for the following Python 3 code def get_long_description(): root_path = get_root_path() readme_path = os.path.join(root_path, "README.md") try: import pypandoc return pypandoc.convert(readme_path, "rst").strip() except ImportError: return "C...
You are a Python code generator, capable of creating scripts from specifications.
Find a random vector in the tangent space of the n sphere
Can you tell what is the following Python 3 function doing def tan_rand(q, seed=9): # probably need a check in case we get a parallel vector rs = np.random.RandomState(seed) rvec = rs.rand(q.shape[0]) qd = np.cross(rvec, q) qd = qd / np.linalg.norm(qd) while np.dot(q, qd) > 1e-6: rvec ...
You are a Python code architect, reviewing and designing scalable and efficient code
r Perturb a vector randomly and return the perturbed version of the random vector.
Given the following Python 3 function, write the documentation def perturb_vec(q, cone_half_angle=2): rand_vec = tan_rand(q) cross_vector = attitude.unit_vector(np.cross(q, rand_vec)) s = np.random.uniform(0, 1, 1) r = np.random.uniform(0, 1, 1) h = np.cos(np.deg2rad(cone_half_angle)) phi = 2...
You are a Python code generator, capable of creating scripts from specifications.
Add common options for package actions.
Here you have a function in Python 3, explain what it does def common_package_action_options(f): @click.option( "-s", "--skip-errors", default=False, is_flag=True, help="Skip/ignore errors when copying packages.", ) @click.option( "-W", "--no-wait-for...
As a Python code composer, you craft elegant and concise scripts.
Add common CLI config options to commands.
Explain what the following Python 3 code does def common_cli_config_options(f): @click.option( "-C", "--config-file", envvar="CLOUDSMITH_CONFIG_FILE", type=click.Path(dir_okay=True, exists=True, writable=False, resolve_path=True), help="The path to your config.ini file.", ...
As a Python code composer, you craft elegant and concise scripts.
def common_cli_output_options(f): """Add common CLI output options to commands.""" @click.option( "-d", "--debug", default=False, is_flag=True, help="Produce debug output during processing.", ) @click.option( "-F", "--output-format", defau...
Can you create a Python 3 function that adds common CLI output options to commands.
As a python code expert, you are capable of creating scripts from specifications.