Skip to content

Commit

Permalink
Rename _ensure_method for better clarity. Use tristate expression.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaraco committed Aug 8, 2022
1 parent 46ca809 commit b7d4048
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions jaraco/classes/properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def __setattr__(self, key, value):
return super().__setattr__(key, value)

def __init__(self, fget, fset=None):
self.fget = self._fix_function(fget)
self.fget = self._ensure_method(fget)
self.fset = fset
fset and self.setter(fset)

Expand All @@ -158,14 +158,13 @@ def __set__(self, owner, value):
return self.fset.__get__(None, owner)(value)

def setter(self, fset):
self.fset = self._fix_function(fset)
self.fset = self._ensure_method(fset)
return self

@classmethod
def _fix_function(cls, fn):
def _ensure_method(cls, fn):
"""
Ensure fn is a classmethod or staticmethod.
"""
if not isinstance(fn, (classmethod, staticmethod)):
return classmethod(fn)
return fn
needs_method = not isinstance(fn, (classmethod, staticmethod))
return classmethod(fn) if needs_method else fn

0 comments on commit b7d4048

Please sign in to comment.