'is pop or push to tuple Invalid in TypeScript?

e.g.

let tuple: [string, number];
// the tuple is working
tuple = ["this is string type!", 123456];
tuple.pop();
// ["this is string type!"]
// now , tuple is only 1 item , type like be broken.
console.log(tuple);
tuple.push("this is string type?");
// ["this is string type!","this is string type?"]
// string into number item
console.log(tuple);

push and pop method is not keep tuple specific positions. this is bug ? or features ?



Solution 1:[1]

This is most likely a limitation of TypeScript, JavaScript doesn't know that tuple variable is a tuple, because there's no tuple type in JavaScript, only array.

Technically, you can't (or shouldn't) do a push or pop a tuple, because tuple is an "array with a fixed number of elements whose types are known", doing a pop, or push won't make it a tuple anymore.

Accessing the tuple's index directly, however, will shows the correct type:

let tuple: [string, number] = ["foo", 123];

tuple[0] = "bar"; // no error
tuple[1] = "baz"; // error
tuple[1] = 100; // no error

Solution 2:[2]

The HTTP 403 is an HTTP status code meaning access to the requested resource is forbidden.

So the requested resource is just blocking your request. You should specify the real URL for further investigation.

But the first step you should do is to specify headers in your request like this

import urllib.request

opener = urllib.request.build_opener()
opener.addheaders = [('User-Agent', 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36')]
urllib.request.install_opener(opener)

url_csv = "example_url"
local_path_csv = "./example.csv"
_ = urllib.request.urlretrieve(url_csv, local_path_csv)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Owl
Solution 2 Oleksii Tambovtsev