Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Code is unreachable" but code still gets reached (Visual Studio Code)

I have the following code that accesses a website and stops browser notifications:

from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.options import Options

option = webdriver.ChromeOptions()
***option.add_experimental_option("excludeSwitches", ["enable-automation"])
option.add_experimental_option('useAutomationExtension', False)
option.add_argument("--disable-infobars")
option.add_argument("start-maximized")
option.add_argument("--disable-extensions")
option.add_experimental_option("detach", True)
option.add_experimental_option("prefs", { 
    "profile.default_content_setting_values.notifications": 2 
})

driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()),options=option)
driver.get("https://www.reddit.com/r/AskReddit/")

The code runs, but my IDE (Visual Studio Code) says that from *** onwards the "Code is unreachable Pylance". Does anyone know how I could fix this? It's annoying since it grays out everything after the *** line. Thank you.

Visual representation of what I'm seeing:

enter image description here

With warning:

enter image description here

like image 833
THEMOUNTAINSANDTHESKIES Avatar asked Sep 23 '26 02:09

THEMOUNTAINSANDTHESKIES


1 Answers

Solution:

It's a bug. Update to the most recent version of selenium to fix the issue.

I found this out by finding the same issue also being discussed here: https://github.com/microsoft/pylance-release/issues/2807

like image 107
THEMOUNTAINSANDTHESKIES Avatar answered Sep 25 '26 16:09

THEMOUNTAINSANDTHESKIES