fix #19580; add warning for bare except: clause (#21099)

* fix #19580; add warning for bare except: clause

* fixes some easy ones

* Update doc/manual.md

* fixes docs

* Update changelog.md

* addition

* Apply suggestions from code review

Co-authored-by: Jacek Sieka <arnetheduck@gmail.com>

* Update doc/tut2.md

Co-authored-by: Jacek Sieka <arnetheduck@gmail.com>
This commit is contained in:
ringabout 2022-12-15 13:45:36 +08:00 • committed by GitHub
commit 91ce8c385d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 50 additions and 26 deletions

View file

@ -1610,7 +1610,7 @@ proc getFootnoteType(label: PRstNode): (FootnoteType, int) =
elif label.len == 1 and label.sons[0].kind == rnLeaf:
try:
result = (fnManualNumber, parseInt(label.sons[0].text))
except:
except ValueError:
result = (fnCitation, -1)
else:
result = (fnCitation, -1)
@ -2899,13 +2899,13 @@ proc parseEnumList(p: var RstParser): PRstNode =
let enumerator = p.tok[p.idx + 1 + wildIndex[w]].symbol
# check that it's in sequence: enumerator == next(prevEnum)
if "n" in wildcards[w]: # arabic numeral
let prevEnumI = try: parseInt(prevEnum) except: 1
let prevEnumI = try: parseInt(prevEnum) except ValueError: 1
if enumerator in autoEnums:
if prevAE != "" and enumerator != prevAE:
break
prevAE = enumerator
curEnum = prevEnumI + 1
else: curEnum = (try: parseInt(enumerator) except: 1)
else: curEnum = (try: parseInt(enumerator) except ValueError: 1)
if curEnum - prevEnumI != 1:
break
prevEnum = enumerator

View file

@ -394,10 +394,10 @@ proc entityToRune*(entity: string): Rune =
case entity[1]
of '0'..'9':
try: runeValue = parseInt(entity[1..^1])
except: discard
except ValueError: discard
of 'x', 'X': # not case sensitive here
try: runeValue = parseHexInt(entity[2..^1])
except: discard
except ValueError: discard
else: discard # other entities are not defined with prefix `#`
if runeValue notin 0..0x10FFFF: runeValue = 0 # only return legal values
return Rune(runeValue)

View file

@ -98,6 +98,7 @@ template doAssertRaises*(exception: typedesc, code: untyped) =
const begin = "expected raising '" & astToStr(exception) & "', instead"
const msgEnd = " by: " & astToStr(code)
template raisedForeign {.gensym.} = raiseAssert(begin & " raised foreign exception" & msgEnd)
{.warning[BareExcept]:off.}
when Exception is exception:
try:
if true:
@ -116,5 +117,6 @@ template doAssertRaises*(exception: typedesc, code: untyped) =
mixin `$` # alternatively, we could define $cstring in this module
raiseAssert(begin & " raised '" & $e.name & "'" & msgEnd)
except: raisedForeign()
{.warning[BareExcept]:on.}
if wrong:
raiseAssert(begin & " nothing was raised" & msgEnd)