websockets: Release 9.0 breaks mypy (and pylint etc.)

Running a project that uses websockets 9.0 against mypy, throws:

error: Module has no attribute "connect"

for

import websockets
await websockects.connect(uri)

and

Module 'websockets' has no attribute 'connect'

for

from websockets import connect

Version 8.1 of websockets has no such issue. Using the latest mypy 0.812.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 4
  • Comments: 30 (15 by maintainers)

Commits related to this issue

Most upvoted comments

For whoever ends up here: try this:

from websockets.client import connect
from websockets.server import serve

if mypy or other tools that don’t understand the dynamic nature of Python give you false positives.

@ltworf If this is really such a big issue for you then you should pin all of your dependencies. I too was affected by this and the solution was quite simple. Quickly make a commit to pin the dependency to <9.0 and then come back to it with a better fix once there is one.

I too maintain an open source project and it baffles me that you do as well but then choose to come harass the maintainer here. Since any change in a dependency could break end users, you should probably pin all of your dependencies or maintain forks of all of your dependencies so that you can properly vet all changes if a change like this is such a disruptive change for you.

You could have at least put a changelog file to say that the api was changing.

Also semver would be nice.

Yes, it makes sense 😃 I’m glad you’re sticking with websockets 😃

Apologies for the disruption!

I just released 9.0.2 with the fix.

The conversation diverged quite a bit from the original issue so I’m going to lock it and go back to solving the issue.

Option 1bis - hide .legacy … I think this is my favorite option.

I agree that this is a good option and it appears to work for a simple example. However, if IDEs and other development tools prefer this pattern, then it could become widespread making the deprecation warnings less useful.

Edit: removed hasty suggestion

Edit: Another idea is to bypass lazy import system for type checking. It’s cumbersome and kind of defeats the purpose of the lazy import, but it appears to work for mypy, pylint and pycharm alike:

from typing import TYPE_CHECKING
if TYPE_CHECKING:
    from websockets.legacy.client import connect
    from websockets.legacy.client import WebSocketClientProtocol
    # etc

I did. That didn’t help since you didn’t read the changelog before complaining.

I downloaded the .tar.gz and there is no changelog file, so unless you mean I clone the repo and check all the commits, there is no changelog.

Please consider the effect that the patronizing tone of your comments has on my willingness to work for you for free.

I use your library in a open source project that I maintain in my free time and for which I have never received a single donation.

So now because of your breaking changes I’m on a sunday debugging things because those changes completely break my project for my (non paying) users.

Could you report whether https://github.com/aaugustin/websockets/commit/a7b240064b579f0c1a5b14d5404646bf289092f3 works?

Supported uses should include:

import websockets.client
await websockects.client.connect(uri)

and

from websockets.client import connect
await connect(uri)

(This will have to be a bugfix release on top on 9.0.1, but I never did maintenance branches in websockets, so this isn’t a request.)