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 758e85a commit 5fcc22c
Show file tree
Hide file tree
Showing 11 changed files with 90 additions and 64 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
13 changes: 9 additions & 4 deletions cssutils/css/cssmediarule.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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):
"""
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
29 changes: 17 additions & 12 deletions cssutils/css/property.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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.
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
15 changes: 8 additions & 7 deletions cssutils/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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 "<cssutils.util.{} object namespaces={!r} at 0x{:x}>".format(
Expand Down

0 comments on commit 5fcc22c

Please sign in to comment.