From 5fcc22c1ad877a7f3b1f0cdb7ec779ec51b11c88 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sun, 11 Jun 2023 17:16:03 -0400 Subject: [PATCH] Fix docs errors by replacing select lambda definitions with real method definitions. Fixes #36. --- .github/workflows/main.yml | 5 +--- cssutils/css/cssimportrule.py | 5 +++- cssutils/css/cssmediarule.py | 13 ++++++--- cssutils/css/cssrule.py | 7 +++-- cssutils/css/cssrulelist.py | 7 +++-- cssutils/css/cssstylesheet.py | 7 +++-- cssutils/css/property.py | 29 +++++++++++-------- cssutils/css/selector.py | 7 +++-- cssutils/css/value.py | 52 +++++++++++++++++++++-------------- cssutils/profiles.py | 7 +++-- cssutils/util.py | 15 +++++----- 11 files changed, 90 insertions(+), 64 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 43a9d704..3fa1c81e 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -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 diff --git a/cssutils/css/cssimportrule.py b/cssutils/css/cssimportrule.py index d0f5e70f..e3d4af57 100644 --- a/cssutils/css/cssimportrule.py +++ b/cssutils/css/cssimportrule.py @@ -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.", ) diff --git a/cssutils/css/cssmediarule.py b/cssutils/css/cssmediarule.py index 0a9660c2..e9ce7369 100644 --- a/cssutils/css/cssmediarule.py +++ b/cssutils/css/cssmediarule.py @@ -261,7 +261,13 @@ def atrule(expected, seq, token, tokenizer): doc="(DOM) The parsable textual representation of this " "rule.", ) - def _setName(self, name): + @property + def name(self): + """An optional name for this media rule.""" + return self._name + + @name.setter + def name(self, name): if isinstance(name, str) or name is None: # "" or '' if not name: @@ -271,9 +277,8 @@ 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 _setName(self, name): + self.name = name def _setMedia(self, media): """ diff --git a/cssutils/css/cssrule.py b/cssutils/css/cssrule.py index 85a16e9c..1f2fb195 100644 --- a/cssutils/css/cssrule.py +++ b/cssutils/css/cssrule.py @@ -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, diff --git a/cssutils/css/cssrulelist.py b/cssutils/css/cssrulelist.py index 2970f994..86c1885d 100644 --- a/cssutils/css/cssrulelist.py +++ b/cssutils/css/cssrulelist.py @@ -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 diff --git a/cssutils/css/cssstylesheet.py b/cssutils/css/cssstylesheet.py index fcc79db2..3ebfe976 100644 --- a/cssutils/css/cssstylesheet.py +++ b/cssutils/css/cssstylesheet.py @@ -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 diff --git a/cssutils/css/property.py b/cssutils/css/property.py index d7706924..ccfb892e 100644 --- a/cssutils/css/property.py +++ b/cssutils/css/property.py @@ -290,7 +290,16 @@ def _setValue(self, value): _getValue, _setValue, doc="The textual value of this Properties propertyValue." ) - def _setPriority(self, priority): # noqa: C901 + def _setPriority(self, priority): + self.priority = priority + + @property + def priority(self): + """Priority of this property.""" + return self._priority + + @priority.setter + def priority(self, priority): # noqa: C901 """ priority a string, currently either u'', u'!important' or u'important' @@ -371,23 +380,19 @@ 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", ) - def _setParent(self, parent): - self._parent = parent + @property + def parent(self): + """The Parent Node (normally a CSSStyledeclaration) of this Property""" + return self._parent - parent = property( - lambda self: self._parent, - _setParent, - doc="The Parent Node (normally a CSSStyledeclaration) of this " "Property", - ) + @parent.setter + def parent(self, parent): + self._parent = parent def validate(self): # noqa: C901 """Validate value against `profiles` which are checked dynamically. diff --git a/cssutils/css/selector.py b/cssutils/css/selector.py index 1c1f76fe..22d40edb 100644 --- a/cssutils/css/selector.py +++ b/cssutils/css/selector.py @@ -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, diff --git a/cssutils/css/value.py b/cssutils/css/value.py index c9b25b33..25ecebfa 100644 --- a/cssutils/css/value.py +++ b/cssutils/css/value.py @@ -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! @@ -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()): @@ -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): @@ -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.") diff --git a/cssutils/profiles.py b/cssutils/profiles.py index b4b2c839..9f1ce965 100644 --- a/cssutils/profiles.py +++ b/cssutils/profiles.py @@ -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" diff --git a/cssutils/util.py b/cssutils/util.py index 4dab40d8..377d24cb 100644 --- a/cssutils/util.py +++ b/cssutils/util.py @@ -73,9 +73,10 @@ 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**!" - ) + @property + def seq(self): + """Internal readonly attribute, **DO NOT USE**!""" + return self._seq class _NewListBase(_NewBase): @@ -892,10 +893,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 "".format(