Skip to content

Commit

Permalink
Address new lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
tabatkins committed Aug 26, 2024
1 parent 4193de9 commit 880b32e
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 39 deletions.
2 changes: 1 addition & 1 deletion bikeshed/Spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ def printTargets(self) -> None:
def isOpaqueElement(self, el: t.ElementT) -> bool:
if el.tag in self.md.opaqueElements:
return True
if el.get("data-opaque") is not None or el.get("bs-opaque") is not None:
if el.get("data-opaque") is not None or el.get("bs-opaque") is not None: # noqa needless-bool
return True
return False

Expand Down
8 changes: 4 additions & 4 deletions bikeshed/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -693,12 +693,12 @@ def handleProfile(options: argparse.Namespace) -> None:
root = f'--root="{options.root}"' if options.root else ""
leaf = f'--leaf="{options.leaf}"' if options.leaf else ""
if options.svgFile:
os.system(
f"time python -m cProfile -o stat.prof -m bikeshed -f spec && gprof2dot -f pstats --skew=.0001 {root} {leaf} stat.prof | dot -Tsvg -o {options.svgFile} && rm stat.prof", # noqa: S605
os.system( # noqa s605
f"time python -m cProfile -o stat.prof -m bikeshed -f spec && gprof2dot -f pstats --skew=.0001 {root} {leaf} stat.prof | dot -Tsvg -o {options.svgFile} && rm stat.prof",
)
else:
os.system(
f"time python -m cProfile -o /tmp/stat.prof -m bikeshed -f spec && gprof2dot -f pstats --skew=.0001 {root} {leaf} /tmp/stat.prof | xdot &", # noqa: S605
os.system( # noqa s605
f"time python -m cProfile -o /tmp/stat.prof -m bikeshed -f spec && gprof2dot -f pstats --skew=.0001 {root} {leaf} /tmp/stat.prof | xdot &",
)


Expand Down
2 changes: 1 addition & 1 deletion bikeshed/doctypes/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def looselyMatch(self, rawStatus: str) -> bool:
orgName, statusName = utils.splitOrg(rawStatus)
if statusName and self.name.upper() != statusName.upper():
return False
if orgName and self.org.name != orgName.upper():
if orgName and self.org.name != orgName.upper(): # noqa needless-bool
return False
return True

Expand Down
20 changes: 6 additions & 14 deletions bikeshed/h/dom.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,7 @@ def escapeCSSIdent(val: str) -> str:
):
ident += rf"\{code:x} "
elif (
code >= 0x80
or code == 0x2D
or code == 0x5F
or 0x30 <= code <= 0x39
or 0x41 <= code <= 0x5A
or 0x61 <= code <= 0x7A
code >= 0x80 or code in (0x2D, 0x5F) or 0x30 <= code <= 0x39 or 0x41 <= code <= 0x5A or 0x61 <= code <= 0x7A
):
ident += chr(code)
else:
Expand All @@ -94,23 +89,20 @@ def validUrlUnit(char: str) -> bool:
c = ord(char)
if c < 0xA0:
# ASCII range
if (
c == 0x21
or c == 0x24
return (
c in (0x21, 0x24)
or 0x26 <= c <= 0x29
or 0x2A <= c <= 0x3B
or c == 0x3D
or 0x3F <= c <= 0x5A
or c == 0x5F
or 0x61 <= c <= 0x7A
or c == 0x7E
):
return True
return False
)
else:
if 0xD800 <= c <= 0xDFFF or 0xFDD0 <= c <= 0xFDEF:
return False
if (c % 0xFFFF) in [0xFFFE, 0xFFFF]:
if (c % 0xFFFF) in [0xFFFE, 0xFFFF]: # noqa needless-bool
# Last two bytes are FFFE or FFFF
return False
return True
Expand Down Expand Up @@ -745,7 +737,7 @@ def isOddNode(node: t.Any) -> bool:
# Something other than an element node or string.
if isinstance(node, str):
return False
if isElement(node):
if isElement(node): # noqa needless-bool
return False
return True

Expand Down
8 changes: 3 additions & 5 deletions bikeshed/h/parser/preds.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,7 @@ def isTagnameChar(ch: str) -> bool:
if cp == 0xB7:
return True
if 0xC0 <= cp <= 0x1FFF:
if cp in (0xD7, 0xF7, 0x37E):
return False
return True
return cp not in (0xD7, 0xF7, 0x37E)
if cp in (0x200C, 0x200D, 0x203F, 0x2040):
return True
if 0x2070 <= cp <= 0x218F:
Expand All @@ -250,15 +248,15 @@ def isTagnameChar(ch: str) -> bool:
return True
if 0xFDF0 <= cp <= 0xFFFD:
return True
if 0x10000 <= cp <= 0xEFFFF:
if 0x10000 <= cp <= 0xEFFFF: # noqa needless-bool
return True
return False


def isAttrNameChar(ch: str) -> bool:
if len(ch) != 1:
return False
if isWhitespace(ch) or ch in "/<>=\"'" or ord(ch) == 0:
if isWhitespace(ch) or ch in "/<>=\"'" or ord(ch) == 0: # noqa needless-bool
return False
return True

Expand Down
2 changes: 1 addition & 1 deletion bikeshed/h/serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ def needsEndTag(self, el: t.ElementT, nextEl: Nodes | None = None) -> bool:
if el.tag in ["dt", "dd"]:
if nextEl is None:
return False
if self.isElement(nextEl) and nextEl.tag in ["dt", "dd"]:
if self.isElement(nextEl) and nextEl.tag in ["dt", "dd"]: # noqa needless-bool
return False
return True
return False
Expand Down
7 changes: 3 additions & 4 deletions bikeshed/markdown/markdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,9 @@ def inlineElementStart(line: str) -> bool:
if tagname in inlineElements:
return True
assert blockElements is not None
if "-" in tagname and tagname not in blockElements:
# Assume custom elements are inline by default
return True
return False

# Assume custom elements are inline by default
return "-" in tagname and tagname not in blockElements

tokens: list[TokenT] = []
rawStack: list[RawTokenT] = []
Expand Down
1 change: 0 additions & 1 deletion bikeshed/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ class MessagesState:
printOn: str = "everything"
# Suppress *all* categories, *plus* the final success/fail message
silent: bool = False
#
printMode: str = "console"
asciiOnly: bool = False
fh: io.TextIOWrapper = t.cast("io.TextIOWrapper", sys.stdout) # noqa: RUF009
Expand Down
8 changes: 4 additions & 4 deletions bikeshed/refs/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,16 +195,16 @@ def allRefsIterator() -> t.Generator[t.RefWrapper, None, None]:

def textRefsIterator(texts: list[str]) -> t.Generator[t.RefWrapper, None, None]:
# Same as above, but only grabs those keyed to a given text
for text in texts:
yield from self.fetchRefs(text)
for x in texts:
yield from self.fetchRefs(x)

def forRefsIterator(targetFors: str | list[str]) -> t.Generator[t.RefWrapper, None, None]:
# Same as above, but only grabs those for certain values
if isinstance(targetFors, str):
targetFors = [targetFors]
for for_ in targetFors:
for text in self.fors[for_]:
yield from self.fetchRefs(text)
for x in self.fors[for_]:
yield from self.fetchRefs(x)

# Set up the initial list of refs to query
if text:
Expand Down
6 changes: 2 additions & 4 deletions bikeshed/stylescript/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ def insertable(self, allowList: t.BoolSet) -> bool:
return False
if self.data is None:
return True
if self.data[1]:
if self.data[1]: # noqa needless-bool
return True
return False

Expand Down Expand Up @@ -220,9 +220,7 @@ class Style(JCResource):
script: Script | None = None

def insertable(self, allowList: t.BoolSet) -> bool:
if f"style-{self.name}" not in allowList:
return False
return True
return f"style-{self.name}" in allowList

def toElement(self, darkMode: bool = True) -> t.ElementT:
with self.textPath.open("r", encoding="utf-8") as fh:
Expand Down

0 comments on commit 880b32e

Please sign in to comment.