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

[easy] Enhance the protocol checker #560

Closed
pylint-bot opened this issue Jun 20, 2015 · 4 comments · Fixed by #3259
Closed

[easy] Enhance the protocol checker #560

pylint-bot opened this issue Jun 20, 2015 · 4 comments · Fixed by #3259
Labels
Enhancement ✨ Improvement to a component Good first issue Friendly and approachable by new contributors

Comments

@pylint-bot
Copy link

Originally reported by: Claudiu Popa (BitBucket: PCManticore, GitHub: @PCManticore)


We could improve the protocol checker, there are a lot of special methods which must return something of a given type in order work properly, other special methods require the presence of another method defined and so on: https://docs.python.org/3/reference/datamodel.html


@pylint-bot
Copy link
Author

Original comment by Claudiu Popa (BitBucket: PCManticore, GitHub: @PCManticore):


Here's a short list of checks that can be implemented:

  • __index__ returned non-int
  • __repr__ must return string
  • __str__ must return string
  • __bytes__ must return bytes
  • __getnewargs_ex__ should return a tuple of length 2
  • first item of __getnewargs_ex__ must be a tuple
  • second item of __getnewargs_ex__ must be a dict
  • __getnewargs__ should return a tuple
  • __bool__ should return bool
  • __hash__ should return integer
  • __lenght_hint__ must be an integer
  • __length_hint__ should return >=0
  • __format__ must return string

@pylint-bot pylint-bot added the Enhancement ✨ Improvement to a component label Dec 9, 2015
@PCManticore PCManticore added the Good first issue Friendly and approachable by new contributors label May 14, 2018
@craig-sh
Copy link
Contributor

Hi, I'm at the Pycon canada sprints and I like to try to fix this issue. I'm thinking of following the same approach as in #845, is that a good place to start? Thanks

@PCManticore
Copy link
Contributor

Hi @craig-sh Yeah, that's a good place to start! Thanks for taking a look at it!

@craig-sh
Copy link
Contributor

I added some code to check if __bool__returns a bool. If you get a chance could you take a look at the WIP pull request and let me know if I'm on the right track?
Thanks!

PCManticore pushed a commit that referenced this issue Nov 27, 2019
This commit adds multiple checks for various Python protocols

  E0304 (invalid-bool-returned): __bool__ did not return a bool
  E0305 (invalid-index-returned): __index__ did not return an integer
  E0306 (invalid-repr-returned): __repr__ did not return a string
  E0307 (invalid-str-returned): __str__ did not return a string
  E0308 (invalid-bytes-returned): __bytes__ did not return a string
  E0309 (invalid-hash-returned): __hash__ did not return an integer
  E0310 (invalid-length-hint-returned): __length_hint__ did not return a non-negative integer
  E0311 (invalid-format-returned): __format__ did not return a string
  E0312 (invalid-getnewargs-returned): __getnewargs__ did not return a tuple
  E0313 (invalid-getnewargs-ex-returned): __getnewargs_ex__ did not return a tuple of the form (tuple, dict)

Close #560
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement ✨ Improvement to a component Good first issue Friendly and approachable by new contributors
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants