ruff icon indicating copy to clipboard operation
ruff copied to clipboard

Implement `tryceratops`

Open sbrugman opened this issue 1 year ago • 13 comments

  • [x] TC002: Create your own exception
  • [x] TC003: Avoid specifying long messages outside the exception class
  • [x] TC004: Prefer TypeError exception for invalid type
  • [ ] TC100: Check to continue
  • [ ] TC101: Too many try blocks
  • [x] TC200: Use raise Exception from
  • [x] TC201: Simply use raise
  • [ ] TC202: Don't ignore a broad exception without even logging
  • [x] TC300: Consider adding an else block
  • [x] TC301: Avoid direct raises in try body
  • [x] TC400: Use logging .exception instead of .error
  • [ ] TC401: Do not log the exception object

sbrugman avatar Jan 21 '23 11:01 sbrugman

Taking TC201

alonme avatar Jan 21 '23 17:01 alonme

For tracking: I'm working on TC004

sbrugman avatar Jan 21 '23 17:01 sbrugman

@charliermarsh, i would like to do TC200.

karpa4o4 avatar Jan 21 '23 20:01 karpa4o4

Awesome -- thanks all! Will review as they come in :)

charliermarsh avatar Jan 21 '23 22:01 charliermarsh

I'll take TC301 next.

karpa4o4 avatar Jan 23 '23 19:01 karpa4o4

I'd like to implement TC400, which would be my first rule so it might take a few days. Would that be fast enough ?

Flowake avatar Jan 23 '23 20:01 Flowake

@Flowake - Sure! Take your time. Feel free to open a draft PR and ask questions there if you run into any.

charliermarsh avatar Jan 23 '23 20:01 charliermarsh

I'll take TC002 next.

karpa4o4 avatar Jan 24 '23 13:01 karpa4o4

Ciao, I'm testing the new implementation, but I'm getting this error: TRY300 Consider else block

Screenshot 2023-01-26 at 22 16 04

Isn't it a false positive? Thanks so much

bigluck avatar Jan 26 '23 21:01 bigluck

Hmm, comparing to the original plugin, I think what's incorrect is the highlighted region. It seems to want you to do this (omitting some intermediary lines since I had to copy from the screenshot :)):

try:
    assert isinstance(value, list) is False
except Exception as exc:
    msg = ""
    raise EnsureStrException(msg)
else:
    return str(value)

charliermarsh avatar Jan 26 '23 21:01 charliermarsh

(Fixed in #2228.)

charliermarsh avatar Jan 26 '23 21:01 charliermarsh

Superb, thanks!

bigluck avatar Jan 26 '23 21:01 bigluck

@charliermarsh me and luca should buy you lunch in BKL - ping me on linkedin or whatever and I'm happy to buy you lunch. Thanks for all the great work!

jacopotagliabue avatar Jan 26 '23 22:01 jacopotagliabue

Taking TC401 and TC202

colin99d avatar Feb 19 '23 13:02 colin99d