Skip to content

Commit

Permalink
Revert "Removed unnecessary classproperty decorator"
Browse files Browse the repository at this point in the history
  • Loading branch information
ilblackdragon authored Nov 28, 2016
1 parent 5657d0d commit ee3dc33
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
14 changes: 7 additions & 7 deletions tensorflow/python/framework/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
from tensorflow.python.framework import versions
from tensorflow.python.platform import tf_logging as logging
from tensorflow.python.util import compat
from tensorflow.python.util import deprecation
from tensorflow.python.util import decorator_utils


def _override_helper(clazz_object, operator, func):
Expand Down Expand Up @@ -4063,12 +4063,12 @@ class GraphKeys(object):
COND_CONTEXT = "cond_context"
WHILE_CONTEXT = "while_context"

@property
@deprecation.deprecated("2017-03-02",
"VARIABLES collection name is deprecated, "
"please use GLOBAL_VARIABLES instead")
def VARIABLES(self):
return self.GLOBAL_VARIABLES
@decorator_utils.classproperty
def VARIABLES(cls): # pylint: disable=no-self-argument
logging.warning("VARIABLES collection name is deprecated, "
"please use GLOBAL_VARIABLES instead; "
"VARIABLES will be removed after 2017-03-02.")
return cls.GLOBAL_VARIABLES


def add_to_collection(name, value):
Expand Down
22 changes: 22 additions & 0 deletions tensorflow/python/util/decorator_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,25 @@ def validate_callable(func, decorator_name):
' @property appears before @%s in your source code:'
'\n\n@property\n@%s\ndef method(...)' % (
func, decorator_name, decorator_name))


class classproperty(object): # pylint: disable=invalid-name
"""Class property decorator.
Example usage:
class MyClass(object):
@classproperty
def value(cls):
return '123'
> print MyClass.value
123
"""

def __init__(self, func):
self._func = func

def __get__(self, owner_self, owner_cls):
return self._func(owner_cls)

0 comments on commit ee3dc33

Please sign in to comment.