Skip to content

Commit

Permalink
👹 Feed the hobgoblins (delint).
Browse files Browse the repository at this point in the history
  • Loading branch information
jaraco committed Mar 30, 2024
1 parent 3428b28 commit b93ab04
Show file tree
Hide file tree
Showing 14 changed files with 32 additions and 34 deletions.
2 changes: 1 addition & 1 deletion cssutils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def createCSSStyleSheet(self, title, media):
"https://web.archive.org/web/20200701035537/"
"https://bitbucket.org/cthedot/cssutils/issues/69#comment-30669799"
)
warnings.warn(warning, DeprecationWarning)
warnings.warn(warning, DeprecationWarning, stacklevel=2)
return css.CSSStyleSheet(title=title, media=media)

def createDocument(self, *args, **kwargs):
Expand Down
6 changes: 3 additions & 3 deletions cssutils/css/cssrule.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def _setCssRules(self, cssRules):
"Set new cssRules and update contained rules refs."
cssRules.append = self.insertRule
cssRules.extend = self.insertRule
cssRules.__delitem__ == self.deleteRule
cssRules.__delitem__ = self.deleteRule

for rule in cssRules:
rule._parentRule = self
Expand Down Expand Up @@ -225,12 +225,12 @@ def deleteRule(self, index):
self._cssRules[index]._parentRule = None
del self._cssRules[index]

except IndexError:
except IndexError as err:
raise xml.dom.IndexSizeErr(
'%s: %s is not a valid index '
'in the rulelist of length %i'
% (self.__class__.__name__, index, self._cssRules.length)
)
) from err

def _prepareInsertRule(self, rule, index=None):
"return checked `index` and optional parsed `rule`"
Expand Down
4 changes: 2 additions & 2 deletions cssutils/css/cssstylesheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -526,11 +526,11 @@ def deleteRule(self, index):

try:
rule = self._cssRules[index]
except IndexError:
except IndexError as err:
raise xml.dom.IndexSizeErr(
'CSSStyleSheet: %s is not a valid index in the rulelist of '
'length %i' % (index, self._cssRules.length)
)
) from err
else:
if rule.type == rule.NAMESPACE_RULE:
# check all namespacerules if used
Expand Down
20 changes: 9 additions & 11 deletions cssutils/css/cssvalue.py
Original file line number Diff line number Diff line change
Expand Up @@ -560,9 +560,7 @@ def __init__(self, cssText=None, parent=None, readonly=False):
super().__init__(cssText=cssText, parent=parent, readonly=readonly)

def __str__(self):
return (
f"<cssutils.css.{self.__class__.__name__} object primitiveType={self.primitiveTypeString} cssText={self.cssText!r} at 0x{id(self):x}>"
)
return f"<cssutils.css.{self.__class__.__name__} object primitiveType={self.primitiveTypeString} cssText={self.cssText!r} at 0x{id(self):x}>"

_unitnames = [
'CSS_UNKNOWN',
Expand Down Expand Up @@ -696,10 +694,10 @@ def _getNumDim(self, value=None):
val = float(val)
if val == int(val):
val = int(val)
except ValueError:
except ValueError as err:
raise xml.dom.InvalidAccessErr(
'CSSPrimitiveValue: No float value %r' % self._value[0]
)
) from err

return val, dim

Expand Down Expand Up @@ -731,14 +729,14 @@ def getFloatValue(self, unitType=None):
# convert if needed
try:
val = self._converter[self.primitiveType, unitType](val)
except KeyError:
except KeyError as err:
raise xml.dom.InvalidAccessErr(
'CSSPrimitiveValue: Cannot coerce primitiveType %r to %r'
% (
self.primitiveTypeString,
self._getCSSPrimitiveTypeString(unitType),
)
)
) from err

if val == int(val):
val = int(val)
Expand Down Expand Up @@ -775,24 +773,24 @@ def setFloatValue(self, unitType, floatValue):
)
try:
val = float(floatValue)
except ValueError:
except ValueError as err:
raise xml.dom.InvalidAccessErr(
'CSSPrimitiveValue: floatValue %r is not a float' % floatValue
)
) from err

oldval, dim = self._getNumDim()
if self.primitiveType != unitType:
# convert if possible
try:
val = self._converter[unitType, self.primitiveType](val)
except KeyError:
except KeyError as err:
raise xml.dom.InvalidAccessErr(
'CSSPrimitiveValue: Cannot coerce primitiveType %r to %r'
% (
self.primitiveTypeString,
self._getCSSPrimitiveTypeString(unitType),
)
)
) from err

if val == int(val):
val = int(val)
Expand Down
2 changes: 1 addition & 1 deletion cssutils/css2productions.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,5 +127,5 @@ class CSSProductions:
pass


for i, t in enumerate(PRODUCTIONS):
for t in PRODUCTIONS:
setattr(CSSProductions, t[0].replace('-', '_'), t[0])
2 changes: 1 addition & 1 deletion cssutils/cssproductions.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class CSSProductions:
VARIABLES_SYM = 'VARIABLES_SYM'


for i, t in enumerate(PRODUCTIONS):
for t in PRODUCTIONS:
setattr(CSSProductions, t[0].replace('-', '_'), t[0])


Expand Down
2 changes: 1 addition & 1 deletion cssutils/prodparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ def toStore(store, item):
else:
self.toSeq = lambda t, tokens: (t[0], t[1])

if hasattr(toStore, '__call__'):
if callable(toStore):
self.toStore = toStore
elif toStore:
self.toStore = makeToStore(toStore)
Expand Down
16 changes: 8 additions & 8 deletions cssutils/tests/test_cssrule.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,12 @@ def test(s):
test(s)
# sheet.add CSS
s = cssutils.css.CSSStyleSheet()
for css, type_ in rules:
for css, _ in rules:
s.add(css)
test(s)
# sheet.insertRule CSS
s = cssutils.css.CSSStyleSheet()
for css, type_ in rules:
for css, _ in rules:
s.insertRule(css)
test(s)

Expand All @@ -120,14 +120,14 @@ def test(s):
]
# sheet.add CSSRule
s = cssutils.css.CSSStyleSheet()
for i, (css, type_) in enumerate(rules):
for i, (css, _) in enumerate(rules):
rule = types[i]()
rule.cssText = css
s.add(rule)
test(s)
# sheet.insertRule CSSRule
s = cssutils.css.CSSStyleSheet()
for i, (css, type_) in enumerate(rules):
for i, (css, _) in enumerate(rules):
rule = types[i]()
rule.cssText = css
s.insertRule(rule)
Expand Down Expand Up @@ -165,12 +165,12 @@ def getMediaSheet():

# sheet.add CSS
s, mr = getMediaSheet()
for css, type_ in rules:
for css, _ in rules:
mr.add(css)
test(s)
# sheet.insertRule CSS
s, mr = getMediaSheet()
for css, type_ in rules:
for css, _ in rules:
mr.insertRule(css)
test(s)

Expand All @@ -181,14 +181,14 @@ def getMediaSheet():
]
# sheet.add CSSRule
s, mr = getMediaSheet()
for i, (css, type_) in enumerate(rules):
for i, (css, _) in enumerate(rules):
rule = types[i]()
rule.cssText = css
mr.add(rule)
test(s)
# sheet.insertRule CSSRule
s, mr = getMediaSheet()
for i, (css, type_) in enumerate(rules):
for i, (css, _) in enumerate(rules):
rule = types[i]()
rule.cssText = css
mr.insertRule(rule)
Expand Down
2 changes: 1 addition & 1 deletion cssutils/tests/test_cssstylesheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def test_refs(self):
).cssRules
# new object
assert rules != s.cssRules
for i, r in enumerate(s.cssRules):
for r in s.cssRules:
assert r.parentStyleSheet == s

# namespaces
Expand Down
2 changes: 1 addition & 1 deletion cssutils/tests/test_cssvalue.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def test_cssText(self):
assert v.CSS_VALUE_LIST == v.cssValueType
assert 'normal 1px a, b, "c" end' == v.cssText

for i, x in enumerate(v):
for x in v:
assert x.CSS_PRIMITIVE_VALUE == x.cssValueType
if x == 0:
assert x.CSS_IDENT == x.primitiveType
Expand Down
2 changes: 1 addition & 1 deletion cssutils/tests/test_prodparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ def test_nextProd(self):
}
for seqitems, results in list(tests.items()):
for result in results:
seq = Sequence(minmax=lambda: (1, 2), *seqitems)
seq = Sequence(*seqitems, minmax=lambda: (1, 2))
for t, p in result:
if isinstance(p, str):
with pytest.raises(ParseError, match=re.escape(p)):
Expand Down
2 changes: 1 addition & 1 deletion cssutils/tests/test_profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,7 @@ def test_validate(self):
),
}
# TODO!!!
for (name, values), (valid, matching, profile) in list(tests.items()):
for (name, values), (valid, _matching, _profile) in list(tests.items()):
for value in values:
assert valid == cssutils.profile.validate(name, value)

Expand Down
2 changes: 1 addition & 1 deletion cssutils/tests/test_value.py
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,7 @@ def test_cssText(self):
),
'var(C, #f00 )': ('var(C, #f00)', 'C', '#fff'),
}
for var, (cssText, name, fallback) in list(tests.items()):
for var, (cssText, name, _fallback) in list(tests.items()):
v = cssutils.css.CSSVariable(var)
assert cssText == v.cssText
assert 'VARIABLE' == v.type
Expand Down
2 changes: 1 addition & 1 deletion tools/try.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def maketokens(valuelist):
font-family : a b;
}
'''
cssutils.parseString(s).cssText
cssutils.parseString(s).cssText # noqa: B018
sys.exit(1)

import cssutils
Expand Down

0 comments on commit b93ab04

Please sign in to comment.