Search is not available for this dataset
identifier
stringlengths
1
155
parameters
stringlengths
2
6.09k
docstring
stringlengths
11
63.4k
docstring_summary
stringlengths
0
63.4k
function
stringlengths
29
99.8k
function_tokens
list
start_point
list
end_point
list
language
stringclasses
1 value
docstring_language
stringlengths
2
7
docstring_language_predictions
stringlengths
18
23
is_langid_reliable
stringclasses
2 values
test_create_doorbell
(hass)
Test creation of a doorbell.
Test creation of a doorbell.
async def test_create_doorbell(hass): """Test creation of a doorbell.""" doorbell_one = await _mock_doorbell_from_fixture(hass, "get_doorbell.json") await _create_august_with_devices(hass, [doorbell_one]) binary_sensor_k98gidt45gul_name_motion = hass.states.get( "binary_sensor.k98gidt45gul_name...
[ "async", "def", "test_create_doorbell", "(", "hass", ")", ":", "doorbell_one", "=", "await", "_mock_doorbell_from_fixture", "(", "hass", ",", "\"get_doorbell.json\"", ")", "await", "_create_august_with_devices", "(", "hass", ",", "[", "doorbell_one", "]", ")", "bina...
[ 54, 0 ]
[ 74, 68 ]
python
en
['en', 'lb', 'en']
True
test_create_doorbell_offline
(hass)
Test creation of a doorbell that is offline.
Test creation of a doorbell that is offline.
async def test_create_doorbell_offline(hass): """Test creation of a doorbell that is offline.""" doorbell_one = await _mock_doorbell_from_fixture(hass, "get_doorbell.offline.json") await _create_august_with_devices(hass, [doorbell_one]) binary_sensor_tmt100_name_motion = hass.states.get( "binar...
[ "async", "def", "test_create_doorbell_offline", "(", "hass", ")", ":", "doorbell_one", "=", "await", "_mock_doorbell_from_fixture", "(", "hass", ",", "\"get_doorbell.offline.json\"", ")", "await", "_create_august_with_devices", "(", "hass", ",", "[", "doorbell_one", "]"...
[ 77, 0 ]
[ 91, 68 ]
python
en
['en', 'nl', 'en']
True
test_create_doorbell_with_motion
(hass)
Test creation of a doorbell.
Test creation of a doorbell.
async def test_create_doorbell_with_motion(hass): """Test creation of a doorbell.""" doorbell_one = await _mock_doorbell_from_fixture(hass, "get_doorbell.json") activities = await _mock_activities_from_fixture( hass, "get_activity.doorbell_motion.json" ) await _create_august_with_devices(has...
[ "async", "def", "test_create_doorbell_with_motion", "(", "hass", ")", ":", "doorbell_one", "=", "await", "_mock_doorbell_from_fixture", "(", "hass", ",", "\"get_doorbell.json\"", ")", "activities", "=", "await", "_mock_activities_from_fixture", "(", "hass", ",", "\"get_...
[ 94, 0 ]
[ 113, 66 ]
python
en
['en', 'lb', 'en']
True
test_doorbell_device_registry
(hass)
Test creation of a lock with doorsense and bridge ands up in the registry.
Test creation of a lock with doorsense and bridge ands up in the registry.
async def test_doorbell_device_registry(hass): """Test creation of a lock with doorsense and bridge ands up in the registry.""" doorbell_one = await _mock_doorbell_from_fixture(hass, "get_doorbell.offline.json") await _create_august_with_devices(hass, [doorbell_one]) device_registry = await hass.helper...
[ "async", "def", "test_doorbell_device_registry", "(", "hass", ")", ":", "doorbell_one", "=", "await", "_mock_doorbell_from_fixture", "(", "hass", ",", "\"get_doorbell.offline.json\"", ")", "await", "_create_august_with_devices", "(", "hass", ",", "[", "doorbell_one", "]...
[ 116, 0 ]
[ 129, 64 ]
python
en
['en', 'en', 'en']
True
validate_input
(hass: core.HomeAssistant, data)
Validate the user input allows us to connect. Data has the keys from DATA_SCHEMA with values provided by the user.
Validate the user input allows us to connect.
async def validate_input(hass: core.HomeAssistant, data): """Validate the user input allows us to connect. Data has the keys from DATA_SCHEMA with values provided by the user. """ client_session = aiohttp_client.async_get_clientsession(hass) account = Account(data["username"], data["password"]) ...
[ "async", "def", "validate_input", "(", "hass", ":", "core", ".", "HomeAssistant", ",", "data", ")", ":", "client_session", "=", "aiohttp_client", ".", "async_get_clientsession", "(", "hass", ")", "account", "=", "Account", "(", "data", "[", "\"username\"", "]"...
[ 25, 0 ]
[ 43, 38 ]
python
en
['en', 'en', 'en']
True
ConfigFlow.async_step_user
(self, user_input=None)
Handle the initial step.
Handle the initial step.
async def async_step_user(self, user_input=None): """Handle the initial step.""" errors = {} if user_input is not None: try: info = await validate_input(self.hass, user_input) except CannotConnect: errors["base"] = "cannot_connect" ...
[ "async", "def", "async_step_user", "(", "self", ",", "user_input", "=", "None", ")", ":", "errors", "=", "{", "}", "if", "user_input", "is", "not", "None", ":", "try", ":", "info", "=", "await", "validate_input", "(", "self", ".", "hass", ",", "user_in...
[ 52, 4 ]
[ 76, 9 ]
python
en
['en', 'en', 'en']
True
hello
()
prints hello, world
prints hello, world
def hello(): """ prints hello, world """ print("Hello, world!")
[ "def", "hello", "(", ")", ":", "print", "(", "\"Hello, world!\"", ")" ]
[ 41, 0 ]
[ 43, 26 ]
python
en
['en', 'sr', 'en']
True
areacircle
(radius)
Computes the area of a circle of the given radius
Computes the area of a circle of the given radius
def areacircle(radius): """ Computes the area of a circle of the given radius """ area = 3.14*radius**2 print("The area of a circle of radius",radius,"is", area)
[ "def", "areacircle", "(", "radius", ")", ":", "area", "=", "3.14", "*", "radius", "**", "2", "print", "(", "\"The area of a circle of radius\"", ",", "radius", ",", "\"is\"", ",", "area", ")" ]
[ 46, 0 ]
[ 49, 61 ]
python
en
['en', 'en', 'en']
True
fahrenheit_to_celsius
(temp)
Converts Fahrenheit temperature to Celsius. Formula is 5/9 of temp minus 32
Converts Fahrenheit temperature to Celsius. Formula is 5/9 of temp minus 32
def fahrenheit_to_celsius(temp): """ Converts Fahrenheit temperature to Celsius. Formula is 5/9 of temp minus 32 """ # Note that this line is not executed # end='' keeps print from starting a new line. newTemp = 5*(temp-32)/9 print("The Fahrenheit temperature",temp,"is equivalent to",newTem...
[ "def", "fahrenheit_to_celsius", "(", "temp", ")", ":", "# Note that this line is not executed", "# end='' keeps print from starting a new line.", "newTemp", "=", "5", "*", "(", "temp", "-", "32", ")", "/", "9", "print", "(", "\"The Fahrenheit temperature\"", ",", "temp"...
[ 99, 0 ]
[ 106, 29 ]
python
de
['de', 'la', 'it']
False
celsius_to_fahrenheit
(temp)
End solution
End solution
def celsius_to_fahrenheit(temp): #%% """ End solution """
[ "def", "celsius_to_fahrenheit", "(", "temp", ")", ":", "#%%" ]
[ 127, 0 ]
[ 136, 3 ]
python
en
['en', 'error', 'th']
False
name
()
Input first and last name, combine to one string and print
Input first and last name, combine to one string and print
def name(): """ Input first and last name, combine to one string and print """ fname = input("Enter your first name: ") lname = input("Enter your last name: ") fullname = fname + " " + lname print("Your name is:", fullname)
[ "def", "name", "(", ")", ":", "fname", "=", "input", "(", "\"Enter your first name: \"", ")", "lname", "=", "input", "(", "\"Enter your last name: \"", ")", "fullname", "=", "fname", "+", "\" \"", "+", "lname", "print", "(", "\"Your name is:\"", ",", "fullname...
[ 139, 0 ]
[ 145, 36 ]
python
en
['en', 'en', 'en']
True
name
()
Input first and last name, combine to one string and print Also, input the city and state and print.
Input first and last name, combine to one string and print Also, input the city and state and print.
def name(): """ Input first and last name, combine to one string and print Also, input the city and state and print.""" fname = input("Enter your first name: ") lname = input("Enter your last name: ") fullname = fname + " " + lname print("Your name is:", fullname)
[ "def", "name", "(", ")", ":", "fname", "=", "input", "(", "\"Enter your first name: \"", ")", "lname", "=", "input", "(", "\"Enter your last name: \"", ")", "fullname", "=", "fname", "+", "\" \"", "+", "lname", "print", "(", "\"Your name is:\"", ",", "fullname...
[ 171, 0 ]
[ 182, 36 ]
python
en
['en', 'en', 'en']
True
if_statement
()
Three slightly difference versions of if: if, if-else, if-elif-else
Three slightly difference versions of if: if, if-else, if-elif-else
def if_statement(): """ Three slightly difference versions of if: if, if-else, if-elif-else""" x = 5 y = 0 z = 0 if x > 0: print("x is positive") if y > 0: print("y is positive") else: print("y is not positive") # elif can be repeated as often as...
[ "def", "if_statement", "(", ")", ":", "x", "=", "5", "y", "=", "0", "z", "=", "0", "if", "x", ">", "0", ":", "print", "(", "\"x is positive\"", ")", "if", "y", ">", "0", ":", "print", "(", "\"y is positive\"", ")", "else", ":", "print", "(", "\...
[ 190, 0 ]
[ 209, 28 ]
python
en
['en', 'en', 'en']
True
area
(type_, x)
Computes the area of a square or circle. type_ must be the string "circle or the string "square" We use type_ here, because type is a Python keyword.
Computes the area of a square or circle. type_ must be the string "circle or the string "square" We use type_ here, because type is a Python keyword.
def area(type_, x): """ Computes the area of a square or circle. type_ must be the string "circle or the string "square" We use type_ here, because type is a Python keyword. """ if type_ == "circle": area = 3.14*x**2 print(area) elif type_ == "square": area = x**2 ...
[ "def", "area", "(", "type_", ",", "x", ")", ":", "if", "type_", "==", "\"circle\"", ":", "area", "=", "3.14", "*", "x", "**", "2", "print", "(", "area", ")", "elif", "type_", "==", "\"square\"", ":", "area", "=", "x", "**", "2", "print", "(", "...
[ 233, 0 ]
[ 244, 39 ]
python
en
['en', 'en', 'en']
True
absolutevalue
(num)
End solution
End solution
def absolutevalue(num): #%% """ End solution """
[ "def", "absolutevalue", "(", "num", ")", ":", "#%%" ]
[ 265, 0 ]
[ 274, 3 ]
python
en
['en', 'error', 'th']
False
fahrenheit_to_celsius1
()
BAD. Does not check input before using it. Input from keyboard, which is always a string and must often be converted to an int or float. Converts Fahrenheit temp to Celsius.
BAD. Does not check input before using it. Input from keyboard, which is always a string and must often be converted to an int or float. Converts Fahrenheit temp to Celsius.
def fahrenheit_to_celsius1(): """ BAD. Does not check input before using it. Input from keyboard, which is always a string and must often be converted to an int or float. Converts Fahrenheit temp to Celsius. """ temp_str = input("Enter a Fahrentheit temperature: ") temp = int(temp_str...
[ "def", "fahrenheit_to_celsius1", "(", ")", ":", "temp_str", "=", "input", "(", "\"Enter a Fahrentheit temperature: \"", ")", "temp", "=", "int", "(", "temp_str", ")", "newTemp", "=", "5", "*", "(", "temp", "-", "32", ")", "/", "9", "print", "(", "\"The Fah...
[ 282, 0 ]
[ 293, 36 ]
python
en
['en', 'en', 'en']
True
fahrenheit_to_celsius2
()
IMPROVED. Does some checking of input before using it. Input from keyboard, which is always a string and must often be converted to an int or float. Converts Fahrenheit temp to Celsius. Uses 'if' to make sure an entry was made.
IMPROVED. Does some checking of input before using it. Input from keyboard, which is always a string and must often be converted to an int or float. Converts Fahrenheit temp to Celsius. Uses 'if' to make sure an entry was made.
def fahrenheit_to_celsius2(): """ IMPROVED. Does some checking of input before using it. Input from keyboard, which is always a string and must often be converted to an int or float. Converts Fahrenheit temp to Celsius. Uses 'if' to make sure an entry was made. """ temp_str = input("En...
[ "def", "fahrenheit_to_celsius2", "(", ")", ":", "temp_str", "=", "input", "(", "\"Enter a Fahrenheit temperature: \"", ")", "if", "temp_str", ":", "temp", "=", "int", "(", "temp_str", ")", "newTemp", "=", "5", "*", "(", "temp", "-", "32", ")", "/", "9", ...
[ 301, 0 ]
[ 314, 40 ]
python
en
['en', 'en', 'en']
True
fahrenheit_to_celsius3
()
MORE IMPROVED. Does even more checking of input before using it. Input from keyboard, which is always a string and must often be converted to an int or float. Converts Fahrenheit temp to Celsius. Uses if to check whether input is a number and then uses .isdigit() method of strings to check wheth...
MORE IMPROVED. Does even more checking of input before using it. Input from keyboard, which is always a string and must often be converted to an int or float. Converts Fahrenheit temp to Celsius. Uses if to check whether input is a number and then uses .isdigit() method of strings to check wheth...
def fahrenheit_to_celsius3(): """ MORE IMPROVED. Does even more checking of input before using it. Input from keyboard, which is always a string and must often be converted to an int or float. Converts Fahrenheit temp to Celsius. Uses if to check whether input is a number and then uses .isdigit() ...
[ "def", "fahrenheit_to_celsius3", "(", ")", ":", "temp_str", "=", "input", "(", "\"Enter a Fahrentheit temperature: \"", ")", "if", "temp_str", ":", "if", "temp_str", ".", "isdigit", "(", ")", ":", "temp", "=", "int", "(", "temp_str", ")", "newTemp", "=", "5"...
[ 322, 0 ]
[ 339, 49 ]
python
en
['en', 'en', 'en']
True
inches_to_feet1
(inches)
converts inches to feet and inches
converts inches to feet and inches
def inches_to_feet1(inches): """ converts inches to feet and inches """ feet = inches//12 # division by integer with fraction thrown away extra_inches = inches - 12*feet print(inches,"inches is",feet,"feet and",extra_inches,"inches")
[ "def", "inches_to_feet1", "(", "inches", ")", ":", "feet", "=", "inches", "//", "12", "# division by integer with fraction thrown away", "extra_inches", "=", "inches", "-", "12", "*", "feet", "print", "(", "inches", ",", "\"inches is\"", ",", "feet", ",", "\"fee...
[ 350, 0 ]
[ 354, 67 ]
python
en
['en', 'en', 'en']
True
inches_to_feet2
(inches)
End solution
End solution
def inches_to_feet2(inches): #%% """ End solution """
[ "def", "inches_to_feet2", "(", "inches", ")", ":", "#%%" ]
[ 368, 0 ]
[ 377, 3 ]
python
en
['en', 'error', 'th']
False
cheer
()
Prints 2 4 6 8, who do we appreciate .... Note that everything in the while loop is indented. The first line not indented is the first line following the while loop.
Prints 2 4 6 8, who do we appreciate .... Note that everything in the while loop is indented. The first line not indented is the first line following the while loop.
def cheer(): """ Prints 2 4 6 8, who do we appreciate .... Note that everything in the while loop is indented. The first line not indented is the first line following the while loop. """ ct = 2 while ct <= 8: print(ct,end=" ") # end = " " keeps from starting a new line ct = ct + 2 ...
[ "def", "cheer", "(", ")", ":", "ct", "=", "2", "while", "ct", "<=", "8", ":", "print", "(", "ct", ",", "end", "=", "\" \"", ")", "# end = \" \" keeps from starting a new line", "ct", "=", "ct", "+", "2", "print", "(", ")", "# now we'll start a new line", ...
[ 383, 0 ]
[ 393, 22 ]
python
en
['en', 'en', 'en']
True
cheer2
()
Same as cheer, but uses a for loop and range() range uses a start number, a stop number and a step size.
Same as cheer, but uses a for loop and range() range uses a start number, a stop number and a step size.
def cheer2(): """ Same as cheer, but uses a for loop and range() range uses a start number, a stop number and a step size. """ for ct in range(2,9,2): print(ct,end=' ') print() print("Who do we appreciate?") print("COURSERA!")
[ "def", "cheer2", "(", ")", ":", "for", "ct", "in", "range", "(", "2", ",", "9", ",", "2", ")", ":", "print", "(", "ct", ",", "end", "=", "' '", ")", "print", "(", ")", "print", "(", "\"Who do we appreciate?\"", ")", "print", "(", "\"COURSERA!\"", ...
[ 423, 0 ]
[ 430, 22 ]
python
en
['en', 'en', 'en']
True
countdown1
()
End solution
End solution
def countdown1(): #%% """ End solution """
[ "def", "countdown1", "(", ")", ":", "#%%" ]
[ 444, 0 ]
[ 452, 3 ]
python
en
['en', 'error', 'th']
False
TFXLNetRelativeAttention.rel_shift
(self, x, klen=-1)
perform relative shift to form the relative attention score.
perform relative shift to form the relative attention score.
def rel_shift(self, x, klen=-1): """perform relative shift to form the relative attention score.""" x_size = shape_list(x) x = tf.reshape(x, (x_size[1], x_size[0], x_size[2], x_size[3])) x = x[1:, ...] x = tf.reshape(x, (x_size[0], x_size[1] - 1, x_size[2], x_size[3])) x...
[ "def", "rel_shift", "(", "self", ",", "x", ",", "klen", "=", "-", "1", ")", ":", "x_size", "=", "shape_list", "(", "x", ")", "x", "=", "tf", ".", "reshape", "(", "x", ",", "(", "x_size", "[", "1", "]", ",", "x_size", "[", "0", "]", ",", "x_...
[ 119, 4 ]
[ 129, 16 ]
python
en
['en', 'en', 'en']
True
TFXLNetRelativeAttention.rel_attn_core
( self, q_head, k_head_h, v_head_h, k_head_r, seg_mat, attn_mask, head_mask, output_attentions, training=False )
Core relative positional attention operations.
Core relative positional attention operations.
def rel_attn_core( self, q_head, k_head_h, v_head_h, k_head_r, seg_mat, attn_mask, head_mask, output_attentions, training=False ): """Core relative positional attention operations.""" # content based attention score ac = tf.einsum("ibnd,jbnd->ijbn", q_head + self.r_w_bias, k_head_h) ...
[ "def", "rel_attn_core", "(", "self", ",", "q_head", ",", "k_head_h", ",", "v_head_h", ",", "k_head_r", ",", "seg_mat", ",", "attn_mask", ",", "head_mask", ",", "output_attentions", ",", "training", "=", "False", ")", ":", "# content based attention score", "ac",...
[ 131, 4 ]
[ 173, 23 ]
python
en
['en', 'en', 'en']
True
TFXLNetRelativeAttention.post_attention
(self, h, attn_vec, residual=True, training=False)
Post-attention processing.
Post-attention processing.
def post_attention(self, h, attn_vec, residual=True, training=False): """Post-attention processing.""" # post-attention projection (back to `d_model`) attn_out = tf.einsum("ibnd,hnd->ibh", attn_vec, self.o) attn_out = self.dropout(attn_out, training=training) if residual: ...
[ "def", "post_attention", "(", "self", ",", "h", ",", "attn_vec", ",", "residual", "=", "True", ",", "training", "=", "False", ")", ":", "# post-attention projection (back to `d_model`)", "attn_out", "=", "tf", ".", "einsum", "(", "\"ibnd,hnd->ibh\"", ",", "attn_...
[ 175, 4 ]
[ 186, 21 ]
python
en
['en', 'en', 'en']
False
mock_panel_fixture
()
Mock a Konnected Panel bridge.
Mock a Konnected Panel bridge.
async def mock_panel_fixture(): """Mock a Konnected Panel bridge.""" with patch("konnected.Client", autospec=True) as konn_client: def mock_constructor(host, port, websession): """Fake the panel constructor.""" konn_client.host = host konn_client.port = port ...
[ "async", "def", "mock_panel_fixture", "(", ")", ":", "with", "patch", "(", "\"konnected.Client\"", ",", "autospec", "=", "True", ")", "as", "konn_client", ":", "def", "mock_constructor", "(", "host", ",", "port", ",", "websession", ")", ":", "\"\"\"Fake the pa...
[ 14, 0 ]
[ 41, 25 ]
python
en
['it', 'st', 'en']
False
test_create_and_setup
(hass, mock_panel)
Test that we create a Konnected Panel and save the data.
Test that we create a Konnected Panel and save the data.
async def test_create_and_setup(hass, mock_panel): """Test that we create a Konnected Panel and save the data.""" device_config = config_flow.CONFIG_ENTRY_SCHEMA( { "host": "1.2.3.4", "port": 1234, "id": "112233445566", "model": "Konnected Pro", ...
[ "async", "def", "test_create_and_setup", "(", "hass", ",", "mock_panel", ")", ":", "device_config", "=", "config_flow", ".", "CONFIG_ENTRY_SCHEMA", "(", "{", "\"host\"", ":", "\"1.2.3.4\"", ",", "\"port\"", ":", "1234", ",", "\"id\"", ":", "\"112233445566\"", ",...
[ 44, 0 ]
[ 204, 5 ]
python
en
['en', 'en', 'en']
True
test_create_and_setup_pro
(hass, mock_panel)
Test that we create a Konnected Pro Panel and save the data.
Test that we create a Konnected Pro Panel and save the data.
async def test_create_and_setup_pro(hass, mock_panel): """Test that we create a Konnected Pro Panel and save the data.""" device_config = config_flow.CONFIG_ENTRY_SCHEMA( { "host": "1.2.3.4", "port": 1234, "id": "112233445566", "model": "Konnected Pro", ...
[ "async", "def", "test_create_and_setup_pro", "(", "hass", ",", "mock_panel", ")", ":", "device_config", "=", "config_flow", ".", "CONFIG_ENTRY_SCHEMA", "(", "{", "\"host\"", ":", "\"1.2.3.4\"", ",", "\"port\"", ":", "1234", ",", "\"id\"", ":", "\"112233445566\"", ...
[ 207, 0 ]
[ 386, 5 ]
python
en
['en', 'en', 'en']
True
test_default_options
(hass, mock_panel)
Test that we create a Konnected Panel and save the data.
Test that we create a Konnected Panel and save the data.
async def test_default_options(hass, mock_panel): """Test that we create a Konnected Panel and save the data.""" device_config = config_flow.CONFIG_ENTRY_SCHEMA( { "host": "1.2.3.4", "port": 1234, "id": "112233445566", "model": "Konnected Pro", ...
[ "async", "def", "test_default_options", "(", "hass", ",", "mock_panel", ")", ":", "device_config", "=", "config_flow", ".", "CONFIG_ENTRY_SCHEMA", "(", "{", "\"host\"", ":", "\"1.2.3.4\"", ",", "\"port\"", ":", "1234", ",", "\"id\"", ":", "\"112233445566\"", ","...
[ 389, 0 ]
[ 552, 5 ]
python
en
['en', 'en', 'en']
True
test_connect_retry
(hass, mock_panel)
Test that we create a Konnected Panel and save the data.
Test that we create a Konnected Panel and save the data.
async def test_connect_retry(hass, mock_panel): """Test that we create a Konnected Panel and save the data.""" device_config = config_flow.CONFIG_ENTRY_SCHEMA( { "host": "1.2.3.4", "port": 1234, "id": "112233445566", "model": "Konnected Pro", "...
[ "async", "def", "test_connect_retry", "(", "hass", ",", "mock_panel", ")", ":", "device_config", "=", "config_flow", ".", "CONFIG_ENTRY_SCHEMA", "(", "{", "\"host\"", ":", "\"1.2.3.4\"", ",", "\"port\"", ":", "1234", ",", "\"id\"", ":", "\"112233445566\"", ",", ...
[ 555, 0 ]
[ 667, 79 ]
python
en
['en', 'en', 'en']
True
load_vocab
(vocab_file)
Loads a vocabulary file into a dictionary.
Loads a vocabulary file into a dictionary.
def load_vocab(vocab_file): """Loads a vocabulary file into a dictionary.""" vocab = collections.OrderedDict() with open(vocab_file, "r", encoding="utf-8") as reader: tokens = reader.readlines() for index, token in enumerate(tokens): token = token.rstrip("\n") vocab[token] = inde...
[ "def", "load_vocab", "(", "vocab_file", ")", ":", "vocab", "=", "collections", ".", "OrderedDict", "(", ")", "with", "open", "(", "vocab_file", ",", "\"r\"", ",", "encoding", "=", "\"utf-8\"", ")", "as", "reader", ":", "tokens", "=", "reader", ".", "read...
[ 43, 0 ]
[ 51, 16 ]
python
en
['en', 'en', 'en']
True
ProphetNetTokenizer._convert_token_to_id
(self, token)
Converts a token (str) in an id using the vocab.
Converts a token (str) in an id using the vocab.
def _convert_token_to_id(self, token): """ Converts a token (str) in an id using the vocab. """ return self.vocab.get(token, self.vocab.get(self.unk_token))
[ "def", "_convert_token_to_id", "(", "self", ",", "token", ")", ":", "return", "self", ".", "vocab", ".", "get", "(", "token", ",", "self", ".", "vocab", ".", "get", "(", "self", ".", "unk_token", ")", ")" ]
[ 173, 4 ]
[ 175, 68 ]
python
en
['en', 'en', 'en']
True
ProphetNetTokenizer._convert_id_to_token
(self, index)
Converts an index (integer) in a token (str) using the vocab.
Converts an index (integer) in a token (str) using the vocab.
def _convert_id_to_token(self, index): """Converts an index (integer) in a token (str) using the vocab.""" return self.ids_to_tokens.get(index, self.unk_token)
[ "def", "_convert_id_to_token", "(", "self", ",", "index", ")", ":", "return", "self", ".", "ids_to_tokens", ".", "get", "(", "index", ",", "self", ".", "unk_token", ")" ]
[ 177, 4 ]
[ 179, 60 ]
python
en
['en', 'en', 'en']
True
ProphetNetTokenizer.convert_tokens_to_string
(self, tokens)
Converts a sequence of tokens (string) in a single string.
Converts a sequence of tokens (string) in a single string.
def convert_tokens_to_string(self, tokens): """ Converts a sequence of tokens (string) in a single string. """ out_string = " ".join(tokens).replace(" ##", "").strip() return out_string
[ "def", "convert_tokens_to_string", "(", "self", ",", "tokens", ")", ":", "out_string", "=", "\" \"", ".", "join", "(", "tokens", ")", ".", "replace", "(", "\" ##\"", ",", "\"\"", ")", ".", "strip", "(", ")", "return", "out_string" ]
[ 181, 4 ]
[ 184, 25 ]
python
en
['en', 'en', 'en']
True
ProphetNetTokenizer.get_special_tokens_mask
( self, token_ids_0: List[int], token_ids_1: Optional[List[int]] = None, already_has_special_tokens: bool = False )
Retrieve sequence ids from a token list that has no special tokens added. This method is called when adding special tokens using the tokenizer ``prepare_for_model`` method. Args: token_ids_0 (:obj:`List[int]`): List of IDs. token_ids_1 (:obj:`List[int]`,...
Retrieve sequence ids from a token list that has no special tokens added. This method is called when adding special tokens using the tokenizer ``prepare_for_model`` method.
def get_special_tokens_mask( self, token_ids_0: List[int], token_ids_1: Optional[List[int]] = None, already_has_special_tokens: bool = False ) -> List[int]: """ Retrieve sequence ids from a token list that has no special tokens added. This method is called when adding special tokens ...
[ "def", "get_special_tokens_mask", "(", "self", ",", "token_ids_0", ":", "List", "[", "int", "]", ",", "token_ids_1", ":", "Optional", "[", "List", "[", "int", "]", "]", "=", "None", ",", "already_has_special_tokens", ":", "bool", "=", "False", ")", "->", ...
[ 186, 4 ]
[ 214, 78 ]
python
en
['en', 'error', 'th']
False
ProphetNetTokenizer.create_token_type_ids_from_sequences
( self, token_ids_0: List[int], token_ids_1: Optional[List[int]] = None )
Create a mask from the two sequences passed to be used in a sequence-pair classification task. A ProphetNet sequence pair mask has the following format: :: 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 | first sequence | second sequence | If :obj:`token_ids_1` is...
Create a mask from the two sequences passed to be used in a sequence-pair classification task. A ProphetNet sequence pair mask has the following format:
def create_token_type_ids_from_sequences( self, token_ids_0: List[int], token_ids_1: Optional[List[int]] = None ) -> List[int]: """ Create a mask from the two sequences passed to be used in a sequence-pair classification task. A ProphetNet sequence pair mask has the following format:...
[ "def", "create_token_type_ids_from_sequences", "(", "self", ",", "token_ids_0", ":", "List", "[", "int", "]", ",", "token_ids_1", ":", "Optional", "[", "List", "[", "int", "]", "]", "=", "None", ")", "->", "List", "[", "int", "]", ":", "sep", "=", "[",...
[ 216, 4 ]
[ 243, 74 ]
python
en
['en', 'error', 'th']
False
ProphetNetTokenizer.build_inputs_with_special_tokens
( self, token_ids_0: List[int], token_ids_1: Optional[List[int]] = None )
Build model inputs from a sequence or a pair of sequence for sequence classification tasks by concatenating and adding special tokens. A BERT sequence has the following format: - single sequence: ``[CLS] X [SEP]`` - pair of sequences: ``[CLS] A [SEP] B [SEP]`` Args: ...
Build model inputs from a sequence or a pair of sequence for sequence classification tasks by concatenating and adding special tokens. A BERT sequence has the following format:
def build_inputs_with_special_tokens( self, token_ids_0: List[int], token_ids_1: Optional[List[int]] = None ) -> List[int]: """ Build model inputs from a sequence or a pair of sequence for sequence classification tasks by concatenating and adding special tokens. A BERT sequence has t...
[ "def", "build_inputs_with_special_tokens", "(", "self", ",", "token_ids_0", ":", "List", "[", "int", "]", ",", "token_ids_1", ":", "Optional", "[", "List", "[", "int", "]", "]", "=", "None", ")", "->", "List", "[", "int", "]", ":", "if", "token_ids_1", ...
[ 265, 4 ]
[ 287, 52 ]
python
en
['en', 'error', 'th']
False
async_setup_platform
(hass, config, async_add_entities, discovery_info=None)
Find and return battery.
Find and return battery.
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None): """Find and return battery.""" if discovery_info is None: return batteries = [] lwlink = hass.data[LIGHTWAVE_LINK] for device_config in discovery_info.values(): name = device_config[CONF_NAME] ...
[ "async", "def", "async_setup_platform", "(", "hass", ",", "config", ",", "async_add_entities", ",", "discovery_info", "=", "None", ")", ":", "if", "discovery_info", "is", "None", ":", "return", "batteries", "=", "[", "]", "lwlink", "=", "hass", ".", "data", ...
[ 7, 0 ]
[ 21, 33 ]
python
en
['en', 'en', 'en']
True
LightwaveBattery.__init__
(self, name, lwlink, serial)
Initialize the Lightwave Trv battery sensor.
Initialize the Lightwave Trv battery sensor.
def __init__(self, name, lwlink, serial): """Initialize the Lightwave Trv battery sensor.""" self._name = name self._state = None self._lwlink = lwlink self._serial = serial
[ "def", "__init__", "(", "self", ",", "name", ",", "lwlink", ",", "serial", ")", ":", "self", ".", "_name", "=", "name", "self", ".", "_state", "=", "None", "self", ".", "_lwlink", "=", "lwlink", "self", ".", "_serial", "=", "serial" ]
[ 27, 4 ]
[ 32, 29 ]
python
en
['en', 'da', 'en']
True
LightwaveBattery.device_class
(self)
Return the device class of the sensor.
Return the device class of the sensor.
def device_class(self): """Return the device class of the sensor.""" return DEVICE_CLASS_BATTERY
[ "def", "device_class", "(", "self", ")", ":", "return", "DEVICE_CLASS_BATTERY" ]
[ 35, 4 ]
[ 37, 35 ]
python
en
['en', 'en', 'en']
True
LightwaveBattery.name
(self)
Return the name of the sensor.
Return the name of the sensor.
def name(self): """Return the name of the sensor.""" return self._name
[ "def", "name", "(", "self", ")", ":", "return", "self", ".", "_name" ]
[ 40, 4 ]
[ 42, 25 ]
python
en
['en', 'mi', 'en']
True
LightwaveBattery.state
(self)
Return the state of the sensor.
Return the state of the sensor.
def state(self): """Return the state of the sensor.""" return self._state
[ "def", "state", "(", "self", ")", ":", "return", "self", ".", "_state" ]
[ 45, 4 ]
[ 47, 26 ]
python
en
['en', 'en', 'en']
True
LightwaveBattery.unit_of_measurement
(self)
Return the state of the sensor.
Return the state of the sensor.
def unit_of_measurement(self): """Return the state of the sensor.""" return PERCENTAGE
[ "def", "unit_of_measurement", "(", "self", ")", ":", "return", "PERCENTAGE" ]
[ 50, 4 ]
[ 52, 25 ]
python
en
['en', 'en', 'en']
True
LightwaveBattery.update
(self)
Communicate with a Lightwave RTF Proxy to get state.
Communicate with a Lightwave RTF Proxy to get state.
def update(self): """Communicate with a Lightwave RTF Proxy to get state.""" (dummy_temp, dummy_targ, battery, dummy_output) = self._lwlink.read_trv_status( self._serial ) self._state = battery
[ "def", "update", "(", "self", ")", ":", "(", "dummy_temp", ",", "dummy_targ", ",", "battery", ",", "dummy_output", ")", "=", "self", ".", "_lwlink", ".", "read_trv_status", "(", "self", ".", "_serial", ")", "self", ".", "_state", "=", "battery" ]
[ 54, 4 ]
[ 59, 29 ]
python
en
['en', 'en', 'en']
True
mock_all
(aioclient_mock)
Mock all setup requests.
Mock all setup requests.
def mock_all(aioclient_mock): """Mock all setup requests.""" aioclient_mock.post("http://127.0.0.1/homeassistant/options", json={"result": "ok"}) aioclient_mock.get("http://127.0.0.1/supervisor/ping", json={"result": "ok"}) aioclient_mock.post("http://127.0.0.1/supervisor/options", json={"result": "ok"}...
[ "def", "mock_all", "(", "aioclient_mock", ")", ":", "aioclient_mock", ".", "post", "(", "\"http://127.0.0.1/homeassistant/options\"", ",", "json", "=", "{", "\"result\"", ":", "\"ok\"", "}", ")", "aioclient_mock", ".", "get", "(", "\"http://127.0.0.1/supervisor/ping\"...
[ 16, 0 ]
[ 56, 5 ]
python
en
['en', 'bg', 'en']
True
test_setup_api_ping
(hass, aioclient_mock)
Test setup with API ping.
Test setup with API ping.
async def test_setup_api_ping(hass, aioclient_mock): """Test setup with API ping.""" with patch.dict(os.environ, MOCK_ENVIRON): result = await async_setup_component(hass, "hassio", {}) assert result assert aioclient_mock.call_count == 9 assert hass.components.hassio.get_core_info()["ver...
[ "async", "def", "test_setup_api_ping", "(", "hass", ",", "aioclient_mock", ")", ":", "with", "patch", ".", "dict", "(", "os", ".", "environ", ",", "MOCK_ENVIRON", ")", ":", "result", "=", "await", "async_setup_component", "(", "hass", ",", "\"hassio\"", ",",...
[ 59, 0 ]
[ 67, 45 ]
python
en
['en', 'ceb', 'en']
True
test_setup_api_panel
(hass, aioclient_mock)
Test setup with API ping.
Test setup with API ping.
async def test_setup_api_panel(hass, aioclient_mock): """Test setup with API ping.""" assert await async_setup_component(hass, "frontend", {}) with patch.dict(os.environ, MOCK_ENVIRON): result = await async_setup_component(hass, "hassio", {}) assert result panels = hass.data[frontend.DA...
[ "async", "def", "test_setup_api_panel", "(", "hass", ",", "aioclient_mock", ")", ":", "assert", "await", "async_setup_component", "(", "hass", ",", "\"frontend\"", ",", "{", "}", ")", "with", "patch", ".", "dict", "(", "os", ".", "environ", ",", "MOCK_ENVIRO...
[ 70, 0 ]
[ 93, 5 ]
python
en
['en', 'ceb', 'en']
True
test_setup_api_push_api_data
(hass, aioclient_mock)
Test setup with API push.
Test setup with API push.
async def test_setup_api_push_api_data(hass, aioclient_mock): """Test setup with API push.""" with patch.dict(os.environ, MOCK_ENVIRON): result = await async_setup_component( hass, "hassio", {"http": {"server_port": 9999}, "hassio": {}} ) assert result assert aioclient_m...
[ "async", "def", "test_setup_api_push_api_data", "(", "hass", ",", "aioclient_mock", ")", ":", "with", "patch", ".", "dict", "(", "os", ".", "environ", ",", "MOCK_ENVIRON", ")", ":", "result", "=", "await", "async_setup_component", "(", "hass", ",", "\"hassio\"...
[ 96, 0 ]
[ 107, 54 ]
python
en
['en', 'zu', 'en']
True
test_setup_api_push_api_data_server_host
(hass, aioclient_mock)
Test setup with API push with active server host.
Test setup with API push with active server host.
async def test_setup_api_push_api_data_server_host(hass, aioclient_mock): """Test setup with API push with active server host.""" with patch.dict(os.environ, MOCK_ENVIRON): result = await async_setup_component( hass, "hassio", {"http": {"server_port": 9999, "server_ho...
[ "async", "def", "test_setup_api_push_api_data_server_host", "(", "hass", ",", "aioclient_mock", ")", ":", "with", "patch", ".", "dict", "(", "os", ".", "environ", ",", "MOCK_ENVIRON", ")", ":", "result", "=", "await", "async_setup_component", "(", "hass", ",", ...
[ 110, 0 ]
[ 123, 58 ]
python
en
['en', 'en', 'en']
True
test_setup_api_push_api_data_default
(hass, aioclient_mock, hass_storage)
Test setup with API push default data.
Test setup with API push default data.
async def test_setup_api_push_api_data_default(hass, aioclient_mock, hass_storage): """Test setup with API push default data.""" with patch.dict(os.environ, MOCK_ENVIRON): result = await async_setup_component(hass, "hassio", {"http": {}, "hassio": {}}) assert result assert aioclient_mock.ca...
[ "async", "def", "test_setup_api_push_api_data_default", "(", "hass", ",", "aioclient_mock", ",", "hass_storage", ")", ":", "with", "patch", ".", "dict", "(", "os", ".", "environ", ",", "MOCK_ENVIRON", ")", ":", "result", "=", "await", "async_setup_component", "(...
[ 126, 0 ]
[ 147, 47 ]
python
en
['en', 'hi-Latn', 'en']
True
test_setup_adds_admin_group_to_user
(hass, aioclient_mock, hass_storage)
Test setup with API push default data.
Test setup with API push default data.
async def test_setup_adds_admin_group_to_user(hass, aioclient_mock, hass_storage): """Test setup with API push default data.""" # Create user without admin user = await hass.auth.async_create_system_user("Hass.io") assert not user.is_admin await hass.auth.async_create_refresh_token(user) hass_s...
[ "async", "def", "test_setup_adds_admin_group_to_user", "(", "hass", ",", "aioclient_mock", ",", "hass_storage", ")", ":", "# Create user without admin", "user", "=", "await", "hass", ".", "auth", ".", "async_create_system_user", "(", "\"Hass.io\"", ")", "assert", "not...
[ 150, 0 ]
[ 167, 24 ]
python
en
['en', 'hi-Latn', 'en']
True
test_setup_api_existing_hassio_user
(hass, aioclient_mock, hass_storage)
Test setup with API push default data.
Test setup with API push default data.
async def test_setup_api_existing_hassio_user(hass, aioclient_mock, hass_storage): """Test setup with API push default data.""" user = await hass.auth.async_create_system_user("Hass.io test") token = await hass.auth.async_create_refresh_token(user) hass_storage[STORAGE_KEY] = {"version": 1, "data": {"ha...
[ "async", "def", "test_setup_api_existing_hassio_user", "(", "hass", ",", "aioclient_mock", ",", "hass_storage", ")", ":", "user", "=", "await", "hass", ".", "auth", ".", "async_create_system_user", "(", "\"Hass.io test\"", ")", "token", "=", "await", "hass", ".", ...
[ 170, 0 ]
[ 182, 74 ]
python
en
['en', 'hi-Latn', 'en']
True
test_setup_core_push_timezone
(hass, aioclient_mock)
Test setup with API push default data.
Test setup with API push default data.
async def test_setup_core_push_timezone(hass, aioclient_mock): """Test setup with API push default data.""" hass.config.time_zone = "testzone" with patch.dict(os.environ, MOCK_ENVIRON): result = await async_setup_component(hass, "hassio", {"hassio": {}}) assert result assert aioclient_...
[ "async", "def", "test_setup_core_push_timezone", "(", "hass", ",", "aioclient_mock", ")", ":", "hass", ".", "config", ".", "time_zone", "=", "\"testzone\"", "with", "patch", ".", "dict", "(", "os", ".", "environ", ",", "MOCK_ENVIRON", ")", ":", "result", "="...
[ 185, 0 ]
[ 199, 77 ]
python
en
['en', 'hi-Latn', 'en']
True
test_setup_hassio_no_additional_data
(hass, aioclient_mock)
Test setup with API push default data.
Test setup with API push default data.
async def test_setup_hassio_no_additional_data(hass, aioclient_mock): """Test setup with API push default data.""" with patch.dict(os.environ, MOCK_ENVIRON), patch.dict( os.environ, {"HASSIO_TOKEN": "123456"} ): result = await async_setup_component(hass, "hassio", {"hassio": {}}) ass...
[ "async", "def", "test_setup_hassio_no_additional_data", "(", "hass", ",", "aioclient_mock", ")", ":", "with", "patch", ".", "dict", "(", "os", ".", "environ", ",", "MOCK_ENVIRON", ")", ",", "patch", ".", "dict", "(", "os", ".", "environ", ",", "{", "\"HASS...
[ 202, 0 ]
[ 211, 71 ]
python
en
['en', 'hi-Latn', 'en']
True
test_fail_setup_without_environ_var
(hass)
Fail setup if no environ variable set.
Fail setup if no environ variable set.
async def test_fail_setup_without_environ_var(hass): """Fail setup if no environ variable set.""" with patch.dict(os.environ, {}, clear=True): result = await async_setup_component(hass, "hassio", {}) assert not result
[ "async", "def", "test_fail_setup_without_environ_var", "(", "hass", ")", ":", "with", "patch", ".", "dict", "(", "os", ".", "environ", ",", "{", "}", ",", "clear", "=", "True", ")", ":", "result", "=", "await", "async_setup_component", "(", "hass", ",", ...
[ 214, 0 ]
[ 218, 25 ]
python
en
['es', 'st', 'en']
False
test_warn_when_cannot_connect
(hass, caplog)
Fail warn when we cannot connect.
Fail warn when we cannot connect.
async def test_warn_when_cannot_connect(hass, caplog): """Fail warn when we cannot connect.""" with patch.dict(os.environ, MOCK_ENVIRON), patch( "homeassistant.components.hassio.HassIO.is_connected", return_value=None, ): result = await async_setup_component(hass, "hassio", {}) ...
[ "async", "def", "test_warn_when_cannot_connect", "(", "hass", ",", "caplog", ")", ":", "with", "patch", ".", "dict", "(", "os", ".", "environ", ",", "MOCK_ENVIRON", ")", ",", "patch", "(", "\"homeassistant.components.hassio.HassIO.is_connected\"", ",", "return_value...
[ 221, 0 ]
[ 231, 73 ]
python
en
['en', 'en', 'en']
True
test_service_register
(hassio_env, hass)
Check if service will be setup.
Check if service will be setup.
async def test_service_register(hassio_env, hass): """Check if service will be setup.""" assert await async_setup_component(hass, "hassio", {}) assert hass.services.has_service("hassio", "addon_start") assert hass.services.has_service("hassio", "addon_stop") assert hass.services.has_service("hassio"...
[ "async", "def", "test_service_register", "(", "hassio_env", ",", "hass", ")", ":", "assert", "await", "async_setup_component", "(", "hass", ",", "\"hassio\"", ",", "{", "}", ")", "assert", "hass", ".", "services", ".", "has_service", "(", "\"hassio\"", ",", ...
[ 234, 0 ]
[ 247, 65 ]
python
en
['en', 'en', 'en']
True
test_service_calls
(hassio_env, hass, aioclient_mock)
Call service and check the API calls behind that.
Call service and check the API calls behind that.
async def test_service_calls(hassio_env, hass, aioclient_mock): """Call service and check the API calls behind that.""" assert await async_setup_component(hass, "hassio", {}) aioclient_mock.post("http://127.0.0.1/addons/test/start", json={"result": "ok"}) aioclient_mock.post("http://127.0.0.1/addons/te...
[ "async", "def", "test_service_calls", "(", "hassio_env", ",", "hass", ",", "aioclient_mock", ")", ":", "assert", "await", "async_setup_component", "(", "hass", ",", "\"hassio\"", ",", "{", "}", ")", "aioclient_mock", ".", "post", "(", "\"http://127.0.0.1/addons/te...
[ 250, 0 ]
[ 321, 5 ]
python
en
['en', 'en', 'en']
True
test_service_calls_core
(hassio_env, hass, aioclient_mock)
Call core service and check the API calls behind that.
Call core service and check the API calls behind that.
async def test_service_calls_core(hassio_env, hass, aioclient_mock): """Call core service and check the API calls behind that.""" assert await async_setup_component(hass, "hassio", {}) aioclient_mock.post("http://127.0.0.1/homeassistant/restart", json={"result": "ok"}) aioclient_mock.post("http://127.0...
[ "async", "def", "test_service_calls_core", "(", "hassio_env", ",", "hass", ",", "aioclient_mock", ")", ":", "assert", "await", "async_setup_component", "(", "hass", ",", "\"hassio\"", ",", "{", "}", ")", "aioclient_mock", ".", "post", "(", "\"http://127.0.0.1/home...
[ 324, 0 ]
[ 348, 41 ]
python
en
['en', 'en', 'en']
True
filter_soup
(soup, **kwargs)
Adds an external link marker to external links and makes them open in new tabs.
Adds an external link marker to external links and makes them open in new tabs.
def filter_soup(soup, **kwargs): """ Adds an external link marker to external links and makes them open in new tabs. """ extern_regex = re.compile(r"^https?://") links = soup.find_all("a", href=True) for link in links: if extern_regex.match(link["href"]): link["target"]...
[ "def", "filter_soup", "(", "soup", ",", "*", "*", "kwargs", ")", ":", "extern_regex", "=", "re", ".", "compile", "(", "r\"^https?://\"", ")", "links", "=", "soup", ".", "find_all", "(", "\"a\"", ",", "href", "=", "True", ")", "for", "link", "in", "li...
[ 13, 0 ]
[ 33, 56 ]
python
en
['en', 'error', 'th']
False
TestKiraSensor.add_entities
(self, devices)
Mock add devices.
Mock add devices.
def add_entities(self, devices): """Mock add devices.""" for device in devices: self.DEVICES.append(device)
[ "def", "add_entities", "(", "self", ",", "devices", ")", ":", "for", "device", "in", "devices", ":", "self", ".", "DEVICES", ".", "append", "(", "device", ")" ]
[ 19, 4 ]
[ 22, 39 ]
python
en
['es', 'en', 'en']
True
TestKiraSensor.setUp
(self)
Initialize values for this testcase class.
Initialize values for this testcase class.
def setUp(self): """Initialize values for this testcase class.""" self.hass = get_test_home_assistant() mock_kira = MagicMock() self.hass.data[kira.DOMAIN] = {kira.CONF_SENSOR: {}} self.hass.data[kira.DOMAIN][kira.CONF_SENSOR]["kira"] = mock_kira self.addCleanup(self.hass...
[ "def", "setUp", "(", "self", ")", ":", "self", ".", "hass", "=", "get_test_home_assistant", "(", ")", "mock_kira", "=", "MagicMock", "(", ")", "self", ".", "hass", ".", "data", "[", "kira", ".", "DOMAIN", "]", "=", "{", "kira", ".", "CONF_SENSOR", ":...
[ 24, 4 ]
[ 30, 39 ]
python
en
['en', 'en', 'en']
True
TestKiraSensor.test_kira_sensor_callback
(self)
Ensure Kira sensor properly updates its attributes from callback.
Ensure Kira sensor properly updates its attributes from callback.
def test_kira_sensor_callback(self): """Ensure Kira sensor properly updates its attributes from callback.""" kira.setup_platform(self.hass, TEST_CONFIG, self.add_entities, DISCOVERY_INFO) assert len(self.DEVICES) == 1 sensor = self.DEVICES[0] assert sensor.name == "kira" ...
[ "def", "test_kira_sensor_callback", "(", "self", ")", ":", "kira", ".", "setup_platform", "(", "self", ".", "hass", ",", "TEST_CONFIG", ",", "self", ".", "add_entities", ",", "DISCOVERY_INFO", ")", "assert", "len", "(", "self", ".", "DEVICES", ")", "==", "...
[ 33, 4 ]
[ 49, 79 ]
python
en
['en', 'ny', 'en']
True
setup_platform
(hass, config, add_entities, discovery_info=None)
Set up the Lutron switches.
Set up the Lutron switches.
def setup_platform(hass, config, add_entities, discovery_info=None): """Set up the Lutron switches.""" devs = [] # Add Lutron Switches for (area_name, device) in hass.data[LUTRON_DEVICES]["switch"]: dev = LutronSwitch(area_name, device, hass.data[LUTRON_CONTROLLER]) devs.append(dev) ...
[ "def", "setup_platform", "(", "hass", ",", "config", ",", "add_entities", ",", "discovery_info", "=", "None", ")", ":", "devs", "=", "[", "]", "# Add Lutron Switches", "for", "(", "area_name", ",", "device", ")", "in", "hass", ".", "data", "[", "LUTRON_DEV...
[ 6, 0 ]
[ 24, 28 ]
python
en
['en', 'en', 'en']
True
LutronSwitch.__init__
(self, area_name, lutron_device, controller)
Initialize the switch.
Initialize the switch.
def __init__(self, area_name, lutron_device, controller): """Initialize the switch.""" self._prev_state = None super().__init__(area_name, lutron_device, controller)
[ "def", "__init__", "(", "self", ",", "area_name", ",", "lutron_device", ",", "controller", ")", ":", "self", ".", "_prev_state", "=", "None", "super", "(", ")", ".", "__init__", "(", "area_name", ",", "lutron_device", ",", "controller", ")" ]
[ 30, 4 ]
[ 33, 62 ]
python
en
['en', 'en', 'en']
True
LutronSwitch.turn_on
(self, **kwargs)
Turn the switch on.
Turn the switch on.
def turn_on(self, **kwargs): """Turn the switch on.""" self._lutron_device.level = 100
[ "def", "turn_on", "(", "self", ",", "*", "*", "kwargs", ")", ":", "self", ".", "_lutron_device", ".", "level", "=", "100" ]
[ 35, 4 ]
[ 37, 39 ]
python
en
['en', 'en', 'en']
True
LutronSwitch.turn_off
(self, **kwargs)
Turn the switch off.
Turn the switch off.
def turn_off(self, **kwargs): """Turn the switch off.""" self._lutron_device.level = 0
[ "def", "turn_off", "(", "self", ",", "*", "*", "kwargs", ")", ":", "self", ".", "_lutron_device", ".", "level", "=", "0" ]
[ 39, 4 ]
[ 41, 37 ]
python
en
['en', 'en', 'en']
True
LutronSwitch.device_state_attributes
(self)
Return the state attributes.
Return the state attributes.
def device_state_attributes(self): """Return the state attributes.""" return {"lutron_integration_id": self._lutron_device.id}
[ "def", "device_state_attributes", "(", "self", ")", ":", "return", "{", "\"lutron_integration_id\"", ":", "self", ".", "_lutron_device", ".", "id", "}" ]
[ 44, 4 ]
[ 46, 64 ]
python
en
['en', 'en', 'en']
True
LutronSwitch.is_on
(self)
Return true if device is on.
Return true if device is on.
def is_on(self): """Return true if device is on.""" return self._lutron_device.last_level() > 0
[ "def", "is_on", "(", "self", ")", ":", "return", "self", ".", "_lutron_device", ".", "last_level", "(", ")", ">", "0" ]
[ 49, 4 ]
[ 51, 51 ]
python
en
['en', 'fy', 'en']
True
LutronSwitch.update
(self)
Call when forcing a refresh of the device.
Call when forcing a refresh of the device.
def update(self): """Call when forcing a refresh of the device.""" if self._prev_state is None: self._prev_state = self._lutron_device.level > 0
[ "def", "update", "(", "self", ")", ":", "if", "self", ".", "_prev_state", "is", "None", ":", "self", ".", "_prev_state", "=", "self", ".", "_lutron_device", ".", "level", ">", "0" ]
[ 53, 4 ]
[ 56, 60 ]
python
en
['en', 'en', 'en']
True
LutronLed.__init__
(self, area_name, keypad_name, scene_device, led_device, controller)
Initialize the switch.
Initialize the switch.
def __init__(self, area_name, keypad_name, scene_device, led_device, controller): """Initialize the switch.""" self._keypad_name = keypad_name self._scene_name = scene_device.name super().__init__(area_name, led_device, controller)
[ "def", "__init__", "(", "self", ",", "area_name", ",", "keypad_name", ",", "scene_device", ",", "led_device", ",", "controller", ")", ":", "self", ".", "_keypad_name", "=", "keypad_name", "self", ".", "_scene_name", "=", "scene_device", ".", "name", "super", ...
[ 62, 4 ]
[ 66, 59 ]
python
en
['en', 'en', 'en']
True
LutronLed.turn_on
(self, **kwargs)
Turn the LED on.
Turn the LED on.
def turn_on(self, **kwargs): """Turn the LED on.""" self._lutron_device.state = 1
[ "def", "turn_on", "(", "self", ",", "*", "*", "kwargs", ")", ":", "self", ".", "_lutron_device", ".", "state", "=", "1" ]
[ 68, 4 ]
[ 70, 37 ]
python
en
['en', 'zu', 'en']
True
LutronLed.turn_off
(self, **kwargs)
Turn the LED off.
Turn the LED off.
def turn_off(self, **kwargs): """Turn the LED off.""" self._lutron_device.state = 0
[ "def", "turn_off", "(", "self", ",", "*", "*", "kwargs", ")", ":", "self", ".", "_lutron_device", ".", "state", "=", "0" ]
[ 72, 4 ]
[ 74, 37 ]
python
en
['en', 'sm', 'en']
True
LutronLed.device_state_attributes
(self)
Return the state attributes.
Return the state attributes.
def device_state_attributes(self): """Return the state attributes.""" return { "keypad": self._keypad_name, "scene": self._scene_name, "led": self._lutron_device.name, }
[ "def", "device_state_attributes", "(", "self", ")", ":", "return", "{", "\"keypad\"", ":", "self", ".", "_keypad_name", ",", "\"scene\"", ":", "self", ".", "_scene_name", ",", "\"led\"", ":", "self", ".", "_lutron_device", ".", "name", ",", "}" ]
[ 77, 4 ]
[ 83, 9 ]
python
en
['en', 'en', 'en']
True
LutronLed.is_on
(self)
Return true if device is on.
Return true if device is on.
def is_on(self): """Return true if device is on.""" return self._lutron_device.last_state
[ "def", "is_on", "(", "self", ")", ":", "return", "self", ".", "_lutron_device", ".", "last_state" ]
[ 86, 4 ]
[ 88, 45 ]
python
en
['en', 'fy', 'en']
True
LutronLed.name
(self)
Return the name of the LED.
Return the name of the LED.
def name(self): """Return the name of the LED.""" return f"{self._area_name} {self._keypad_name}: {self._scene_name} LED"
[ "def", "name", "(", "self", ")", ":", "return", "f\"{self._area_name} {self._keypad_name}: {self._scene_name} LED\"" ]
[ 91, 4 ]
[ 93, 79 ]
python
en
['en', 'en', 'en']
True
LutronLed.update
(self)
Call when forcing a refresh of the device.
Call when forcing a refresh of the device.
def update(self): """Call when forcing a refresh of the device.""" if self._lutron_device.last_state is not None: return # The following property getter actually triggers an update in Lutron self._lutron_device.state
[ "def", "update", "(", "self", ")", ":", "if", "self", ".", "_lutron_device", ".", "last_state", "is", "not", "None", ":", "return", "# The following property getter actually triggers an update in Lutron", "self", ".", "_lutron_device", ".", "state" ]
[ 95, 4 ]
[ 101, 33 ]
python
en
['en', 'en', 'en']
True
load_tf_weights_in_t5
(model, config, tf_checkpoint_path)
Load tf checkpoints in a pytorch model.
Load tf checkpoints in a pytorch model.
def load_tf_weights_in_t5(model, config, tf_checkpoint_path): """Load tf checkpoints in a pytorch model.""" try: import re import numpy as np import tensorflow as tf except ImportError: logger.error( "Loading a TensorFlow model in PyTorch, requires TensorFlow to ...
[ "def", "load_tf_weights_in_t5", "(", "model", ",", "config", ",", "tf_checkpoint_path", ")", ":", "try", ":", "import", "re", "import", "numpy", "as", "np", "import", "tensorflow", "as", "tf", "except", "ImportError", ":", "logger", ".", "error", "(", "\"Loa...
[ 70, 0 ]
[ 173, 16 ]
python
en
['en', 'en', 'en']
True
T5LayerNorm.__init__
(self, hidden_size, eps=1e-6)
Construct a layernorm module in the T5 style No bias and no subtraction of mean.
Construct a layernorm module in the T5 style No bias and no subtraction of mean.
def __init__(self, hidden_size, eps=1e-6): """ Construct a layernorm module in the T5 style No bias and no subtraction of mean. """ super().__init__() self.weight = nn.Parameter(torch.ones(hidden_size)) self.variance_epsilon = eps
[ "def", "__init__", "(", "self", ",", "hidden_size", ",", "eps", "=", "1e-6", ")", ":", "super", "(", ")", ".", "__init__", "(", ")", "self", ".", "weight", "=", "nn", ".", "Parameter", "(", "torch", ".", "ones", "(", "hidden_size", ")", ")", "self"...
[ 229, 4 ]
[ 235, 35 ]
python
en
['en', 'error', 'th']
False
T5Attention._relative_position_bucket
(relative_position, bidirectional=True, num_buckets=32, max_distance=128)
Adapted from Mesh Tensorflow: https://github.com/tensorflow/mesh/blob/0cb87fe07da627bf0b7e60475d59f95ed6b5be3d/mesh_tensorflow/transformer/transformer_layers.py#L593 Translate relative position to a bucket number for relative attention. The relative position is defined as memory_positi...
Adapted from Mesh Tensorflow: https://github.com/tensorflow/mesh/blob/0cb87fe07da627bf0b7e60475d59f95ed6b5be3d/mesh_tensorflow/transformer/transformer_layers.py#L593
def _relative_position_bucket(relative_position, bidirectional=True, num_buckets=32, max_distance=128): """ Adapted from Mesh Tensorflow: https://github.com/tensorflow/mesh/blob/0cb87fe07da627bf0b7e60475d59f95ed6b5be3d/mesh_tensorflow/transformer/transformer_layers.py#L593 Translate rel...
[ "def", "_relative_position_bucket", "(", "relative_position", ",", "bidirectional", "=", "True", ",", "num_buckets", "=", "32", ",", "max_distance", "=", "128", ")", ":", "relative_buckets", "=", "0", "if", "bidirectional", ":", "num_buckets", "//=", "2", "relat...
[ 343, 4 ]
[ 388, 31 ]
python
en
['en', 'error', 'th']
False
T5Attention.compute_bias
(self, query_length, key_length)
Compute binned relative position bias
Compute binned relative position bias
def compute_bias(self, query_length, key_length): """ Compute binned relative position bias """ context_position = torch.arange(query_length, dtype=torch.long)[:, None] memory_position = torch.arange(key_length, dtype=torch.long)[None, :] relative_position = memory_position - context_pos...
[ "def", "compute_bias", "(", "self", ",", "query_length", ",", "key_length", ")", ":", "context_position", "=", "torch", ".", "arange", "(", "query_length", ",", "dtype", "=", "torch", ".", "long", ")", "[", ":", ",", "None", "]", "memory_position", "=", ...
[ 390, 4 ]
[ 403, 21 ]
python
en
['en', 'en', 'nl']
True
T5Attention.forward
( self, hidden_states, mask=None, key_value_states=None, position_bias=None, past_key_value=None, layer_head_mask=None, query_length=None, use_cache=False, output_attentions=False, )
Self-attention (if key_value_states is None) or attention over source sentence (provided by key_value_states).
Self-attention (if key_value_states is None) or attention over source sentence (provided by key_value_states).
def forward( self, hidden_states, mask=None, key_value_states=None, position_bias=None, past_key_value=None, layer_head_mask=None, query_length=None, use_cache=False, output_attentions=False, ): """ Self-attention (if ke...
[ "def", "forward", "(", "self", ",", "hidden_states", ",", "mask", "=", "None", ",", "key_value_states", "=", "None", ",", "position_bias", "=", "None", ",", "past_key_value", "=", "None", ",", "layer_head_mask", "=", "None", ",", "query_length", "=", "None",...
[ 405, 4 ]
[ 518, 22 ]
python
en
['en', 'error', 'th']
False
T5PreTrainedModel._init_weights
(self, module)
Initialize the weights
Initialize the weights
def _init_weights(self, module): """ Initialize the weights """ factor = self.config.initializer_factor # Used for testing weights initialization if isinstance(module, T5LayerNorm): module.weight.data.fill_(factor * 1.0) elif isinstance(module, (T5Model, T5ForConditionalGene...
[ "def", "_init_weights", "(", "self", ",", "module", ")", ":", "factor", "=", "self", ".", "config", ".", "initializer_factor", "# Used for testing weights initialization", "if", "isinstance", "(", "module", ",", "T5LayerNorm", ")", ":", "module", ".", "weight", ...
[ 719, 4 ]
[ 759, 110 ]
python
en
['en', 'en', 'en']
True
buy_doge
()
doge_price = binance_client.get_symbol_ticker(symbol="DOGEEUR") doge_amount = int(config.get("CONFIG", "SPEND")) / float(doge_price["price"]) print(round(doge_amount, 4)) print(round(doge_amount, 4) * float(doge_price["price"]))
doge_price = binance_client.get_symbol_ticker(symbol="DOGEEUR") doge_amount = int(config.get("CONFIG", "SPEND")) / float(doge_price["price"]) print(round(doge_amount, 4)) print(round(doge_amount, 4) * float(doge_price["price"]))
def buy_doge(): """doge_price = binance_client.get_symbol_ticker(symbol="DOGEEUR") doge_amount = int(config.get("CONFIG", "SPEND")) / float(doge_price["price"]) print(round(doge_amount, 4)) print(round(doge_amount, 4) * float(doge_price["price"]))""" try: binance_client.create_test_order( ...
[ "def", "buy_doge", "(", ")", ":", "try", ":", "binance_client", ".", "create_test_order", "(", "symbol", "=", "'DOGEEUR'", ",", "side", "=", "SIDE_BUY", ",", "type", "=", "ORDER_TYPE_MARKET", ",", "quantity", "=", "1000", ")", "except", "BinanceAPIException", ...
[ 116, 0 ]
[ 131, 16 ]
python
de
['en', 'de', 'nl']
False
main
()
if not os.path.isfile("settings/handles.txt"): first_time() with open("settings/handles.txt", "r") as file: handles = file.read().splitlines() for i in range(len(handles)): doge_mentioned = check_tweets_for_doge(handles[i]) if doge_mentioned: buy_doge()
if not os.path.isfile("settings/handles.txt"): first_time()
def main(): """if not os.path.isfile("settings/handles.txt"): first_time() with open("settings/handles.txt", "r") as file: handles = file.read().splitlines() for i in range(len(handles)): doge_mentioned = check_tweets_for_doge(handles[i]) if doge_mentioned: buy_doge()""...
[ "def", "main", "(", ")", ":", "buy_doge", "(", ")" ]
[ 134, 0 ]
[ 146, 14 ]
python
en
['en', 'en', 'en']
True
setup_platform
(hass, config, add_entities, discovery_info=None)
Set up mFi sensors.
Set up mFi sensors.
def setup_platform(hass, config, add_entities, discovery_info=None): """Set up mFi sensors.""" host = config.get(CONF_HOST) username = config.get(CONF_USERNAME) password = config.get(CONF_PASSWORD) use_tls = config[CONF_SSL] verify_tls = config.get(CONF_VERIFY_SSL) default_port = 6443 if use...
[ "def", "setup_platform", "(", "hass", ",", "config", ",", "add_entities", ",", "discovery_info", "=", "None", ")", ":", "host", "=", "config", ".", "get", "(", "CONF_HOST", ")", "username", "=", "config", ".", "get", "(", "CONF_USERNAME", ")", "password", ...
[ 37, 0 ]
[ 60, 5 ]
python
en
['en', 'bg', 'en']
True
MfiSwitch.__init__
(self, port)
Initialize the mFi device.
Initialize the mFi device.
def __init__(self, port): """Initialize the mFi device.""" self._port = port self._target_state = None
[ "def", "__init__", "(", "self", ",", "port", ")", ":", "self", ".", "_port", "=", "port", "self", ".", "_target_state", "=", "None" ]
[ 66, 4 ]
[ 69, 33 ]
python
en
['en', 'en', 'en']
True
MfiSwitch.unique_id
(self)
Return the unique ID of the device.
Return the unique ID of the device.
def unique_id(self): """Return the unique ID of the device.""" return self._port.ident
[ "def", "unique_id", "(", "self", ")", ":", "return", "self", ".", "_port", ".", "ident" ]
[ 72, 4 ]
[ 74, 31 ]
python
en
['en', 'en', 'en']
True
MfiSwitch.name
(self)
Return the name of the device.
Return the name of the device.
def name(self): """Return the name of the device.""" return self._port.label
[ "def", "name", "(", "self", ")", ":", "return", "self", ".", "_port", ".", "label" ]
[ 77, 4 ]
[ 79, 31 ]
python
en
['en', 'en', 'en']
True
MfiSwitch.is_on
(self)
Return true if the device is on.
Return true if the device is on.
def is_on(self): """Return true if the device is on.""" return self._port.output
[ "def", "is_on", "(", "self", ")", ":", "return", "self", ".", "_port", ".", "output" ]
[ 82, 4 ]
[ 84, 32 ]
python
en
['en', 'en', 'en']
True
MfiSwitch.update
(self)
Get the latest state and update the state.
Get the latest state and update the state.
def update(self): """Get the latest state and update the state.""" self._port.refresh() if self._target_state is not None: self._port.data["output"] = float(self._target_state) self._target_state = None
[ "def", "update", "(", "self", ")", ":", "self", ".", "_port", ".", "refresh", "(", ")", "if", "self", ".", "_target_state", "is", "not", "None", ":", "self", ".", "_port", ".", "data", "[", "\"output\"", "]", "=", "float", "(", "self", ".", "_targe...
[ 86, 4 ]
[ 91, 37 ]
python
en
['en', 'en', 'en']
True
MfiSwitch.turn_on
(self, **kwargs)
Turn the switch on.
Turn the switch on.
def turn_on(self, **kwargs): """Turn the switch on.""" self._port.control(True) self._target_state = True
[ "def", "turn_on", "(", "self", ",", "*", "*", "kwargs", ")", ":", "self", ".", "_port", ".", "control", "(", "True", ")", "self", ".", "_target_state", "=", "True" ]
[ 93, 4 ]
[ 96, 33 ]
python
en
['en', 'en', 'en']
True
MfiSwitch.turn_off
(self, **kwargs)
Turn the switch off.
Turn the switch off.
def turn_off(self, **kwargs): """Turn the switch off.""" self._port.control(False) self._target_state = False
[ "def", "turn_off", "(", "self", ",", "*", "*", "kwargs", ")", ":", "self", ".", "_port", ".", "control", "(", "False", ")", "self", ".", "_target_state", "=", "False" ]
[ 98, 4 ]
[ 101, 34 ]
python
en
['en', 'en', 'en']
True
MfiSwitch.current_power_w
(self)
Return the current power usage in W.
Return the current power usage in W.
def current_power_w(self): """Return the current power usage in W.""" return int(self._port.data.get("active_pwr", 0))
[ "def", "current_power_w", "(", "self", ")", ":", "return", "int", "(", "self", ".", "_port", ".", "data", ".", "get", "(", "\"active_pwr\"", ",", "0", ")", ")" ]
[ 104, 4 ]
[ 106, 56 ]
python
en
['en', 'en', 'en']
True
MfiSwitch.device_state_attributes
(self)
Return the state attributes for the device.
Return the state attributes for the device.
def device_state_attributes(self): """Return the state attributes for the device.""" return { "volts": round(self._port.data.get("v_rms", 0), 1), "amps": round(self._port.data.get("i_rms", 0), 1), }
[ "def", "device_state_attributes", "(", "self", ")", ":", "return", "{", "\"volts\"", ":", "round", "(", "self", ".", "_port", ".", "data", ".", "get", "(", "\"v_rms\"", ",", "0", ")", ",", "1", ")", ",", "\"amps\"", ":", "round", "(", "self", ".", ...
[ 109, 4 ]
[ 114, 9 ]
python
en
['en', 'en', 'en']
True
test_has_location_with_invalid_states
()
Set up the tests.
Set up the tests.
def test_has_location_with_invalid_states(): """Set up the tests.""" for state in (None, 1, "hello", object): assert not location.has_location(state)
[ "def", "test_has_location_with_invalid_states", "(", ")", ":", "for", "state", "in", "(", "None", ",", "1", ",", "\"hello\"", ",", "object", ")", ":", "assert", "not", "location", ".", "has_location", "(", "state", ")" ]
[ 6, 0 ]
[ 9, 47 ]
python
en
['en', 'en', 'en']
True
test_has_location_with_states_with_invalid_locations
()
Set up the tests.
Set up the tests.
def test_has_location_with_states_with_invalid_locations(): """Set up the tests.""" state = State( "hello.world", "invalid", {ATTR_LATITUDE: "no number", ATTR_LONGITUDE: 123.12} ) assert not location.has_location(state)
[ "def", "test_has_location_with_states_with_invalid_locations", "(", ")", ":", "state", "=", "State", "(", "\"hello.world\"", ",", "\"invalid\"", ",", "{", "ATTR_LATITUDE", ":", "\"no number\"", ",", "ATTR_LONGITUDE", ":", "123.12", "}", ")", "assert", "not", "locati...
[ 12, 0 ]
[ 17, 43 ]
python
en
['en', 'en', 'en']
True
test_has_location_with_states_with_valid_location
()
Set up the tests.
Set up the tests.
def test_has_location_with_states_with_valid_location(): """Set up the tests.""" state = State( "hello.world", "invalid", {ATTR_LATITUDE: 123.12, ATTR_LONGITUDE: 123.12} ) assert location.has_location(state)
[ "def", "test_has_location_with_states_with_valid_location", "(", ")", ":", "state", "=", "State", "(", "\"hello.world\"", ",", "\"invalid\"", ",", "{", "ATTR_LATITUDE", ":", "123.12", ",", "ATTR_LONGITUDE", ":", "123.12", "}", ")", "assert", "location", ".", "has_...
[ 20, 0 ]
[ 25, 39 ]
python
en
['en', 'en', 'en']
True
test_closest_with_no_states_with_location
()
Set up the tests.
Set up the tests.
def test_closest_with_no_states_with_location(): """Set up the tests.""" state = State("light.test", "on") state2 = State( "light.test", "on", {ATTR_LATITUDE: "invalid", ATTR_LONGITUDE: 123.45} ) state3 = State("light.test", "on", {ATTR_LONGITUDE: 123.45}) assert location.closest(123.45...
[ "def", "test_closest_with_no_states_with_location", "(", ")", ":", "state", "=", "State", "(", "\"light.test\"", ",", "\"on\"", ")", "state2", "=", "State", "(", "\"light.test\"", ",", "\"on\"", ",", "{", "ATTR_LATITUDE", ":", "\"invalid\"", ",", "ATTR_LONGITUDE",...
[ 28, 0 ]
[ 36, 76 ]
python
en
['en', 'en', 'en']
True