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

[Improvement] "Unresolved attribute reference 'stop' for classes SyncPlaywrightContextManager/ AsyncPlaywrightContextManager appears in IDE #179

Closed
Igur007 opened this issue Aug 26, 2020 · 7 comments

Comments

@Igur007
Copy link

Igur007 commented Aug 26, 2020

When to use "REPL support without context managers", IDE shows inspection warning "Unresolved attribute reference 'stop' for classes SyncPlaywrightContextManager (for Async too).
It's because stop is registered not obviously, e.g. in line 96: playwright.stop = self.exit # type: ignore
It's better to implement the same solution for stop() as with start()
OR
if to change e.g. in SyncPlaywrightContextManager:

  1. delete def start(self)
  2. delete playwright.stop = self.exit # type: ignore (line 97)
  3. in the end of the class after exit add:
start = __enter__
stop = __exit__
  1. line 96 playwright = self._playwright also seems not needed and can be deleted.

the 'Unresolved attribute reference' inspection in IDE will be fixed and everything will work as expected.
The same changes may be applied for Async for start/stop.

@mxschmitt
Copy link
Member

Could you share with us the exact snippet which is causing that error? And which IDE are you using?

@Igur007
Copy link
Author

Igur007 commented Aug 28, 2020

PyCharm
when to use as:

from playwright import sync_playwright

sync_plw = sync_playwright()
sync_plw.start()

when later is needed to use sync_plw.stop() ---> stop method is not listed by IDE among available methods.

@mxschmitt
Copy link
Member

The usage is a bit different, see this example:

from playwright import sync_playwright

playwright = sync_playwright().start()
for browser_type in [playwright.chromium, playwright.firefox, playwright.webkit]:
    browser = browser_type.launch()
    page = browser.newPage()
    page.goto("http://whatsmyuseragent.org/")
    page.screenshot(path=f"example-{browser_type.name}.png")
    browser.close()

playwright.stop()

@Igur007
Copy link
Author

Igur007 commented Aug 28, 2020

thanks, I saw it before creation of this improvement ).

@mxschmitt
Copy link
Member

Then I close it okay?

@Igur007
Copy link
Author

Igur007 commented Aug 28, 2020

of course, you can. My purpose was if I can control an instance of a context manager with the start method, why I need to use __exit__ or not obviously defined "stop". Everything works with or without this change.

@mxschmitt
Copy link
Member

So we internally start a driver which is basically the upstream github.com/microsoft/playwright project under the hood. In the upstream package the magic happens and in the Python world we only call the Node.js methods internally with a custom JSON based protocol over stdin/stdout.
Thats why we have to start and stop it. Stop is probably not that important but start is needed to use it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants