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

Buffer class makes unexpected RPC calls #449

Open
ms-jpq opened this issue Jul 13, 2020 · 5 comments
Open

Buffer class makes unexpected RPC calls #449

ms-jpq opened this issue Jul 13, 2020 · 5 comments

Comments

@ms-jpq
Copy link

ms-jpq commented Jul 13, 2020

The Buffer class makes unexpected RPC calls.

This is due to the __len__ method being called during boolean tests.

For example, the following code will print 2.

class Example:
    def __len__(self) -> int:
        print(2)
        return 0


example = Example()

if example:
    pass

This is very surprising behaviour, and there is absoutely no way to fix it without breaking backwards compatibility.

But it should be documentated, because this will actually break your code if you are using Buffer class from another thread.

It took me a quite a bit of effort to figure out that an or statement was causing crashes in my plugin.

@blueyed
Copy link
Contributor

blueyed commented Jul 13, 2020

It could also implement __bool__ itself (returning True always), couldn't it? https://docs.python.org/3.8/reference/datamodel.html?highlight=__del__#object.__bool__

@ms-jpq
Copy link
Author

ms-jpq commented Jul 13, 2020

I think thats an excellent idea, even though it would be a breaking change.

im not sure what our policy is on that though

@tjdevries
Copy link

Are there any circumstances that you would the buffer to be false-y?

I think it seems reasonable to override __bool__. It seems unlikely to break anything? Unless it returns false when there are no lines and people are relying on that.

@ms-jpq
Copy link
Author

ms-jpq commented Aug 8, 2020

ya, thats the case.

a very minor breaking change, but then again i wouldn't be surprised if people actually relied on it.

@justinmk
Copy link
Member

PR welcome. We monkey-patch various things, this is more or less idiomatic in python land.

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

4 participants