-
Notifications
You must be signed in to change notification settings - Fork 185
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
fix types for protocols to add type safety #1903
Conversation
@@ -37,47 +37,63 @@ class SessionView: | |||
_session_buffers = WeakValueDictionary() # type: WeakValueDictionary[Tuple[int, int], SessionBuffer] | |||
|
|||
def __init__(self, listener: AbstractViewListener, session: Session, uri: DocumentUri) -> None: | |||
self.view = listener.view |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To avoid changing too much code, decided to use the "underscore" property in __init__
and access through the getter elsewhere. This is maybe not super consistent but makes the diff smaller.
Let me know what you prefer. Maybe just assign to _view
and use the getter from there on.
|
The https://mypy.readthedocs.io/en/stable/class_basics.html#instance-and-class-attributes
Do we really need accessor methods? It's starting to look a bit enterprisey... |
I do appreciate that |
I don't know of another way to do it. Changing: session_buffer = None # type: Any to session_buffer = None # type: SessionViewProtocol confuses |
I would think that type safety is more important over how it "feels"? And to me it doesn't even feel bad from the *Protocol perspective. I guess it is a bit weird how it feels in the actual "implementations" of those protocols but it can be seen as a positive thing since the distinction between the private properties and the public interface is made clear that way. |
Fixes types for pyright in cases like below where we've blatantly lied about types.
The way it was done before, apart from causing type issues with Pyright, allowed users to just access
session_view.session_buffer
fromSession
, for example, and get away with accessing anything onSessionBuffer
because the type wasAny
.@jwortmann sorry to cause troubles for you again. I don't mean bad. :)