The following code produces the error message:
- Operator "|" not supported for types "set[str]" and "set[str]"
...... Operator "|" not supported for types "set[str]" and "set[str]" when expected type is "Iterable[LiteralString]"
def update_no_proxy():
def _normalize_url(url: str) -> str:
return urlparse(url).netloc
old_no_proxy_urls = set(os.getenv('NO_PROXY', '').split(','))
no_proxy_new_urls = {_normalize_url(url) for url in NO_PROXY_URLS}
no_proxy_new_urls = {*no_proxy_new_urls, get_local_ip_address()}
no_proxy_urls: str = ','.join(old_no_proxy_urls | no_proxy_new_urls)
for env_name in NO_PROXY_ENV_NAMES:
os.environ[env_name] = no_proxy_urls.strip(', ')
However, the following code does not produce the error:
def update_no_proxy():
def _normalize_url(url: str) -> str:
return urlparse(url).netloc
old_no_proxy_urls = set(os.getenv('NO_PROXY', '').split(','))
no_proxy_new_urls = {_normalize_url(url) for url in NO_PROXY_URLS}
no_proxy_new_urls = {*no_proxy_new_urls, get_local_ip_address()}
all_no_proxy_urls = old_no_proxy_urls | no_proxy_new_urls
no_proxy_urls = ','.join(all_no_proxy_urls)
for env_name in NO_PROXY_ENV_NAMES:
os.environ[env_name] = no_proxy_urls.strip(', ')
Why putting all_no_proxy_urls
in a new variable solves the problem?