Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unreachable mark but it is reachable #2093

Closed
simm4256 opened this issue Nov 20, 2021 · 11 comments
Closed

Unreachable mark but it is reachable #2093

simm4256 opened this issue Nov 20, 2021 · 11 comments
Labels
bug Something isn't working fixed in next version (main) A fix has been implemented and will appear in an upcoming version

Comments

@simm4256
Copy link

image

pylance v2021.11.2
python v3.9,6
os windows10 20H2 19042.1348

@erictraut
Copy link
Contributor

Thanks for the bug report. This will be fixed in the next release. In the meantime, you can work around the problem by providing a return type annotation for your function:

def tree(len) -> None:
    ...

@erictraut erictraut added bug Something isn't working fixed in next version (main) A fix has been implemented and will appear in an upcoming version and removed triage labels Nov 20, 2021
@bschnurr
Copy link
Member

bschnurr commented Dec 2, 2021

This issue has been fixed in version 2021.12.0, which we've just released. You can find the changelog here: CHANGELOG.md

@bschnurr bschnurr closed this as completed Dec 2, 2021
@zigomir
Copy link

zigomir commented Jan 7, 2022

Getting same problem on VSC: Version: 1.63.2, Pylance v2022.1.0 and macOS.

Happens after instantiating factory.base.Factory object from factoryboy 🤷‍♂️

[edit]
I guess it's because this method in BaseFactory class

def __new__(cls, *args, **kwargs):
    """Would be called if trying to instantiate the class."""
    raise errors.FactoryError('You cannot instantiate BaseFactory')

If I comment it out, all code becomes reachable again.

@adrianosmarinho
Copy link

Getting same problem on VSC: Version: 1.63.2, Pylance v2022.1.0 and macOS.

Happens after instantiating factory.base.Factory object from factoryboy 🤷‍♂️

[edit] I guess it's because this method in BaseFactory class

def __new__(cls, *args, **kwargs):
    """Would be called if trying to instantiate the class."""
    raise errors.FactoryError('You cannot instantiate BaseFactory')

If I comment it out, all code becomes reachable again.

Hey @zigomir
Same setup here, same problem. Pylance marks my code as unreachable after instantiating a factoryboy object 🤷
It is important to note that the same code was working fine two weeks ago, before I left the office on annual leave.

from api.models import Token
from datetime import datetime
from django.contrib.auth.models import User
from factory.django import DjangoModelFactory


class UserFactory(DjangoModelFactory):
    """
    User Factory to be used on tests.
    """

    password = ""
    is_superuser = False
    username = "test_user"
    first_name = "Test"
    last_name = "User"
    email = "[email protected]"
    is_staff = True
    is_active = True
    date_joined = datetime.utcnow()

    class Meta:
        model = User
        django_get_or_create = ("username", "email", "is_active")


class TokenFactory(DjangoModelFactory):
    """
    Token Factory to be used on our tests
    """

    user = UserFactory()
    name = "test_user_token"
    identifier = "2e42a19593f047e080285e49864b0fb6"
    secret = "6ff2dc141c0841e2a43c25be9ae9b097"

    class Meta:
        model = Token
        django_get_or_create = ("user", "name", "identifier")
        

@erictraut
Copy link
Contributor

@adrianosmarinho, the problem you're seeing is this issue, which will be fixed in the next release.

@adchang21
Copy link

adchang21 commented Jul 26, 2022

I am also encountering this issue, here is a sample of my code.

Environment data

  • Language Server version: 2022.7.40
  • OS and version: win32 x64
  • Python version (and distribution if applicable, e.g. Anaconda):
  • python.analysis.indexing: null
  • python.analysis.typeCheckingMode: off

Code Snippet

os.chdir(r'C:\Users\example')
path = r'C:\Users\example'
today = str(date.today())
filename = os.path.join(path, 'example_'+ today + '.txt')

ob=Screenshot_Clipping.Screenshot()
chrome_options = Options()
chrome_options.add_argument("--start-maximized")
driver = webdriver.Chrome(options=chrome_options)

driver.get('https://www.google.com/search?q=aardvark')
WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, '//*[@id="fsl"]/a[1]')))
html = driver.page_source
img_url=ob.full_Screenshot(driver, save_path=r'C:\Users\example', image_name='screenshot.png')
print(img_url)

time.sleep(random.randint(2,5))
driver.quit()

with open(filename, 'w', encoding="utf-8") as f:
    f.write(html)

The code after driver.quit() is marked as unreachable, even though it very much is.

@erictraut
Copy link
Contributor

@adchang21, could you provide a self-contained minimal code sample? The sample above references symbols that are presumably imported from somewhere. Am I correct in assuming that you are using the selenium library? If so, are you using the latest version? There is a known bug in earlier versions of selenium that results in this behavior. Try pip install selenium --upgrade and see if that fixes your issue.

@adchang21
Copy link

Upgrading selenium fixed it, thank you!

@rwayan
Copy link

rwayan commented Jul 26, 2022

@adchang21, could you provide a self-contained minimal code sample? The sample above references symbols that are presumably imported from somewhere. Am I correct in assuming that you are using the selenium library? If so, are you using the latest version? There is a known bug in earlier versions of selenium that results in this behavior. Try pip install selenium --upgrade and see if that fixes your issue.

upgraded to version 4.3.0 but it said code unreachable

import rqdatac
rqdatac.init()

# code below will treated as unreacable
print("a")

@erictraut
Copy link
Contributor

@adchang21, it looks like the issue you're hitting is not related to selenium. Your code snippet above references a module called rqdatac. Am I correct in assuming that's a reference to the rqdatac package? If so, which version are you using? The latest version is 2.9.55. When I install that version, I'm not able to repro unreachable code. I'm guessing that you have an older version installed. Please try updating with pip install rqdatac --upgrade.

@erictraut
Copy link
Contributor

This issue is closed. If you got here because you are seeing code that is marked as unreachable by pylance, it is most likely an issue in a library or type stub, not a bug in pylance. If you want help diagnosing the problem, please use the discussion tab.

If you think that it is potentially a bug in pylance, please open a new bug report. Do not use this closed issue. And as with all bug reports, please include a self-contained minimal code example and specify which versions of third-party libraries the code sample imports.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixed in next version (main) A fix has been implemented and will appear in an upcoming version
Projects
None yet
Development

No branches or pull requests

7 participants