Skip to content

Commit

Permalink
Fix docs errors by replacing select lambda definitions with real meth…
Browse files Browse the repository at this point in the history
…od definitions. Fixes #36.
  • Loading branch information
jaraco committed Jun 11, 2023
1 parent 9e6cee0 commit 33d461d
Show file tree
Hide file tree
Showing 11 changed files with 81 additions and 62 deletions.
5 changes: 1 addition & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,16 +90,13 @@ jobs:
python -m pip install tox
- name: Run tests
run: tox
# workaround for #36
continue-on-error: true

check: # This job does nothing and is only used for the branch protection
if: always()

needs:
- test
# workaround for #36
# - docs
- docs

runs-on: ubuntu-latest

Expand Down
5 changes: 4 additions & 1 deletion cssutils/css/cssimportrule.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,8 +407,11 @@ def _setName(self, name=''):
else:
self._log.error('CSSImportRule: Not a valid name: %s' % name)

def _getName(self):
return self._name

name = property(
lambda self: self._name,
_getName,
_setName,
doc="An optional name for the imported sheet.",
)
Expand Down
10 changes: 6 additions & 4 deletions cssutils/css/cssmediarule.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,12 @@ def atrule(expected, seq, token, tokenizer):
doc="(DOM) The parsable textual representation of this " "rule.",
)

@property
def name(self):
"""An optional name for this media rule."""
return self._name

@name.setter
def _setName(self, name):
if isinstance(name, str) or name is None:
# "" or ''
Expand All @@ -271,10 +277,6 @@ def _setName(self, name):
else:
self._log.error('CSSImportRule: Not a valid name: %s' % name)

name = property(
lambda self: self._name, _setName, doc="An optional name for this media rule."
)

def _setMedia(self, media):
"""
:param media:
Expand Down
7 changes: 4 additions & 3 deletions cssutils/css/cssrule.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,10 @@ def _setCssText(self, cssText):
"and not its initial value.",
)

parent = property(
lambda self: self._parent, doc="The Parent Node of this CSSRule or None."
)
@property
def parent(self):
"""The Parent Node of this CSSRule or None."""
return self._parent

parentRule = property(
lambda self: self._parentRule,
Expand Down
7 changes: 4 additions & 3 deletions cssutils/css/cssrulelist.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,10 @@ def item(self, index):
except IndexError:
return None

length = property(
lambda self: len(self), doc="(DOM) The number of CSSRules in the list."
)
@property
def length(self):
"""(DOM) The number of CSSRules in the list."""
return len(self)

def rulesOfType(self, type):
"""Yield the rules which have the given `type` only, one of the
Expand Down
7 changes: 4 additions & 3 deletions cssutils/css/cssstylesheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,9 +456,10 @@ def _setEncoding(self, encoding):
"(default) if set to ``None``",
)

namespaces = property(
lambda self: self._namespaces, doc="All Namespaces used in this CSSStyleSheet."
)
@property
def namespaces(self):
"""All Namespaces used in this CSSStyleSheet."""
return self._namespaces

def _updateVariables(self):
"""Updates self._variables, called when @import or @variables rules
Expand Down
22 changes: 12 additions & 10 deletions cssutils/css/property.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,12 @@ def _setValue(self, value):
_getValue, _setValue, doc="The textual value of this Properties propertyValue."
)

@property
def priority(self):
"""Priority of this property."""
return self._priority

@priority.setter
def _setPriority(self, priority): # noqa: C901
"""
priority
Expand Down Expand Up @@ -371,24 +377,20 @@ def _ident(expected, seq, token, tokenizer=None):
if self._priority not in ('', 'important'):
self._log.error('Property: No CSS priority value: %s' % self._priority)

priority = property(
lambda self: self._priority, _setPriority, doc="Priority of this property."
)

literalpriority = property(
lambda self: self._literalpriority,
doc="Readonly literal (not normalized) priority of this property",
)

@property
def parent(self):
"""The Parent Node (normally a CSSStyledeclaration) of this Property"""
return self._parent

@parent.setter
def _setParent(self, parent):
self._parent = parent

parent = property(
lambda self: self._parent,
_setParent,
doc="The Parent Node (normally a CSSStyledeclaration) of this " "Property",
)

def validate(self): # noqa: C901
"""Validate value against `profiles` which are checked dynamically.
properties in e.g. @font-face rules are checked against
Expand Down
7 changes: 4 additions & 3 deletions cssutils/css/selector.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,10 @@ def __getNamespaces(self):
"namespaceURI} is used.",
)

element = property(
lambda self: self._element, doc="Effective element target of this selector."
)
@property
def element(self):
"""Effective element target of this selector."""
return self._element

parent = property(
lambda self: self._parent,
Expand Down
52 changes: 31 additions & 21 deletions cssutils/css/value.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,12 +291,14 @@ def _setCssText(self, cssText):
doc='String value of this value.',
)

type = property(
lambda self: self._type, # _setType,
doc="Type of this value, for now the production type "
"like e.g. `DIMENSION` or `STRING`. All types are "
"defined as constants in :class:`~cssutils.css.Value`.",
)
@property
def type(self):
"""
Type of this value, for now the production type
like e.g. `DIMENSION` or `STRING`. All types are
defined as constants in :class:`~cssutils.css.Value`.
"""
return self._type

def _setValue(self, value):
# TODO: check!
Expand Down Expand Up @@ -493,9 +495,10 @@ def _setCssText(self, cssText): # noqa: C901
doc='Same as cssText but without comments.',
)

type = property(
lambda self: Value.COLOR_VALUE, doc="Type is fixed to Value.COLOR_VALUE."
)
@property
def type(self):
"""Type is fixed to Value.COLOR_VALUE."""
return Value.COLOR_VALUE

def _getName(self):
for n, v in list(self.COLORS.items()):
Expand All @@ -512,15 +515,21 @@ def _getName(self):
)

red = property(lambda self: self._red, doc='red part as integer between 0 and 255')
green = property(
lambda self: self._green, doc='green part as integer between 0 and 255'
)
blue = property(
lambda self: self._blue, doc='blue part as integer between 0 and 255'
)
alpha = property(
lambda self: self._alpha, doc='alpha part as float between 0.0 and 1.0'
)

@property
def green(self):
"""green part as integer between 0 and 255"""
return self._green

@property
def blue(self):
"""blue part as integer between 0 and 255"""
return self._blue

@property
def alpha(self):
"""alpha part as float between 0.0 and 1.0"""
return self._alpha


class DimensionValue(Value):
Expand Down Expand Up @@ -928,9 +937,10 @@ def _setCssText(self, cssText):
":class:`cssutils.css.CSSVariablesDeclaration`.",
)

fallback = property(
lambda self: self._fallback, doc="The fallback Value of this variable"
)
@property
def fallback(self):
"""The fallback Value of this variable"""
return self._fallback

type = property(lambda self: Value.VARIABLE, doc="Type is fixed to Value.VARIABLE.")

Expand Down
7 changes: 4 additions & 3 deletions cssutils/profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,10 @@ def _setDefaultProfiles(self, profiles):
doc='Names of all profiles in order as defined.',
)

knownNames = property(
lambda self: self._knownNames, doc="All known property names of all profiles."
)
@property
def knownNames(self):
"""All known property names of all profiles."""
return self._knownNames

def _resetProperties(self, newMacros=None):
"reset all props from raw values as changes in macros happened"
Expand Down
14 changes: 7 additions & 7 deletions cssutils/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ def _tempSeq(self, readonly=False):
"Get a writeable Seq() which is used to set ``seq`` later"
return Seq(readonly=readonly)

seq = property(
lambda self: self._seq, doc="Internal readonly attribute, **DO NOT USE**!"
)
def seq(self):
"""Internal readonly attribute, **DO NOT USE**!"""
return self._seq


class _NewListBase(_NewBase):
Expand Down Expand Up @@ -892,10 +892,10 @@ def __init__(self, log=None, *args):
def __setitem__(self, prefix, namespaceURI):
self.__namespaces[prefix] = namespaceURI

namespaces = property(
lambda self: self.__namespaces,
doc='Dict Wrapper for self.sheets @namespace rules.',
)
@property
def namespaces(self):
"""Dict Wrapper for self.sheets @namespace rules."""
return self.__namespaces

def __str__(self):
return "<cssutils.util.{} object namespaces={!r} at 0x{:x}>".format(
Expand Down

0 comments on commit 33d461d

Please sign in to comment.