Skip to content

Instantly share code, notes, and snippets.

@ishanSrt
Last active June 9, 2018 13:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ishanSrt/b40bcfcf2b48c206439a8f2363877840 to your computer and use it in GitHub Desktop.
Save ishanSrt/b40bcfcf2b48c206439a8f2363877840 to your computer and use it in GitHub Desktop.
Description of the changes to the bears to add type annotations to check agains settings which can attain infinite set of values (Type 2), certain discrete values (Type 3) and which need config files (Type 4)

(all the names of the classes are debatable. This is just to form a general idea of the changes being made to the bears)

Each bear will have an extra class

class bear_annotations():
  class acceptable_values_type_3_setting():
    setting_name = [list of acceptable values]
  class config_file_names_type_4_setting():
    setting_name = [list of acceptable config files]
  class constraints_type_2_setting():
    class setting_name():
      min = val1
      max = val2
      range = (val3, val4)

Each bear run method will have a contracts type annotations applied to it

from contracts import contract, new_contract

class Mybear():
  new_contract('a', annotate_a)
  new_contract('b', annotate_b)
  @deprecate_settings()
  @contract(a='a', b='b')
  def run(a, b):
    pass

Now the functions annotate_a() and annotate_b can be defined and checks can be added based on their type of settings

These functions either return True or False based on the constraints (contracts can be again applied to these and be made mandatory) All the constraining values should be in the bear_annotations class for storing metadata.

Tests can be added by checking against invalid values and checking the raising of ContractNotRespected error

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment