stubber.rst.rst_utils

Tries to determine the return type by parsing the docstring and the function signature
  • if the signature contains a return type –> <something> then that is returned

  • check a lookup dictionary of type overrides,

    if the functionnae is listed, then use the override

  • use re to find phrases such as:
    • ‘Returns ….. ‘

    • ‘Gets ….. ‘

  • docstring is joined without newlines to simplify parsing

  • then parses the docstring to find references to known types and give then a rating though a hand coded model ()

  • builds a list return type candidates

  • selects the highest ranking candidate

  • the default Type is ‘Any’

to do:

  • regex :
    • ‘With no arguments the frequency in Hz is returned.’

    • ‘Get or set’ –> indicates overloaded/optional return Union[None|…]

    • add regex for ‘Query’ ` Otherwise, query current state if no argument is provided. `

  • regex :
    • ‘With no arguments the frequency in Hz is returned.’

    • ‘Get or set’ –> indicates overloaded/optional return Union[None|…]

    • add regex for ‘Query’ ` Otherwise, query current state if no argument is provided. `

  • try if an Azure Machine Learning works as well

    https://docs.microsoft.com/en-us/azure/machine-learning/quickstart-create-resources

Module Contents

Functions

simple_candidates(type, match_string, keywords[, ...])

find and rate possible types and confidence weighting for simple types.

compound_candidates(type, match_string, keywords[, ...])

find and rate possible types and confidence weighting for compound types that can have a subscription.

object_candidates(match_string[, rate, exclude])

find and rate possible types and confidence weighting for Object types.

distill_return(→ List[Dict])

Find return type and confidence.

return_type_from_context(*, docstring, signature, module)

_type_from_context(*, docstring, signature, module[, ...])

Determine the return type of a function or method based on:

Attributes

TYPING_IMPORT

stubber.rst.rst_utils.TYPING_IMPORT: List[str] = ['from __future__ import annotations', 'from typing import IO, Any, Callable, Coroutine, Dict,...
stubber.rst.rst_utils.simple_candidates(type: str, match_string: str, keywords: List[str], rate: float = 0.5, exclude: List[str] | None = None)

find and rate possible types and confidence weighting for simple types. Case sensitive

Parameters:
  • type (str) –

  • match_string (str) –

  • keywords (List[str]) –

  • rate (float) –

  • exclude (Optional[List[str]]) –

stubber.rst.rst_utils.compound_candidates(type: str, match_string: str, keywords: List[str], rate: float = 0.85, exclude: List[str] | None = None)

find and rate possible types and confidence weighting for compound types that can have a subscription. Case sensitive

Parameters:
  • type (str) –

  • match_string (str) –

  • keywords (List[str]) –

  • rate (float) –

  • exclude (Optional[List[str]]) –

stubber.rst.rst_utils.object_candidates(match_string: str, rate: float = 0.81, exclude: List[str] | None = None)

find and rate possible types and confidence weighting for Object types. Case sensitive Exclude defaults to [“IRQ”]

Parameters:
  • match_string (str) –

  • rate (float) –

  • exclude (Optional[List[str]]) –

stubber.rst.rst_utils.distill_return(return_text: str) List[Dict]

Find return type and confidence. Returns a list of possible types and confidence weighting. {

type :str # the return type confidence: float # the confidence between 0.0 and 1 match: Optional[str] # for debugging : the reason the match was made

}

Parameters:

return_text (str) –

Return type:

List[Dict]

stubber.rst.rst_utils.return_type_from_context(*, docstring: str | List[str], signature: str, module: str, literal: bool = False)
Parameters:
  • docstring (Union[str, List[str]]) –

  • signature (str) –

  • module (str) –

  • literal (bool) –

stubber.rst.rst_utils._type_from_context(*, docstring: str | List[str], signature: str, module: str, literal: bool = False)
Determine the return type of a function or method based on:
  • the function signature

  • the terminology used in the docstring

Logic: - if the signature contains a return type –> <something> then that is returned - use re to find phrases such as:

  • ‘Returns ….. ‘

  • ‘Gets ….. ‘

  • docstring is joined without newlines to simplify parsing

  • then parses the docstring to find references to known types and give then a rating though a hand coded model ()

  • builds a list return type candidates

  • selects the highest ranking candidate

  • the default Type is ‘Any’

Parameters:
  • docstring (Union[str, List[str]]) –

  • signature (str) –

  • module (str) –

  • literal (bool) –