-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Metaclass syntax is not py3k-compatible #2121
Comments
Ok i got the files to contribute. |
@nfelt I have to repalce abstractmethod with @abc.abstractmethod in all functions in that class |
No, the problem isn’t to do with the Rather, the problem is that the classes’ metaclasses are not being >>> import sys
>>> sys.version_info
sys.version_info(major=2, minor=7, micro=16, releaselevel='candidate', serial=1)
>>> from tensorboard.plugins import base_plugin
>>> p = base_plugin.TBPlugin()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: Can't instantiate abstract class TBPlugin with abstract methods get_plugin_apps, is_active But in Python 3 you do not get an error: >>> import sys
>>> sys.version_info
sys.version_info(major=3, minor=6, micro=5, releaselevel='final', serial=0)
>>> from tensorboard.plugins import base_plugin
>>> p = base_plugin.TBPlugin()
>>> type(p)
<class 'tensorboard.plugins.base_plugin.TBPlugin'> This is the problem. It should be an error in all Python versions. |
So basically we have to make those classes compatible with both python 2 and python 3. But I am not able to understand what's the bug in their declaration which makes them incompatible with python 2 they appear perfectly fine in documents. |
The current forms that we use are compatible with Python 2 but not Python 3 changed the metaclass syntax, and Python 2 is not The decorator |
class TensorBoardServer(object): @wchargin I have modified TensorboardServer class of tensorboard/program.py. Can you please tell me that whether this is right way or not? |
When posting comments, please use code formatting for code so that it Here is my code:
```python
class TensorBoardServer(object):
"""Class for customizing TensorBoard WSGI app serving."""
@six.add_metaclass
def __init__(self, wsgi_app, flags, metaclass=ABCMeta):
"""Create a flag-configured HTTP server for TensorBoard's WSGI app.
Args:
wsgi_app: The TensorBoard WSGI application to create a server for.
flags: argparse.Namespace instance of TensorBoard flags.
"""
raise NotImplementedError()
@six.add_metaclass
def serve_forever(self, metaclass=ABCMeta):
"""Blocking call to start serving the TensorBoard server."""
raise NotImplementedError()
@six.add_metaclass
def get_url(self, metaclass=ABCMeta):
"""Returns a URL at which this server should be reachable."""
raise NotImplementedError()
```
Here is some more text. This way, the indentation and line breaks are preserved (which is Before submitting your comment, you can “Preview” it to make sure that Now, to your question: Do you think that this is correct? What does it |
No I have not tested it. I just tried to change it according to the guide provided by you in previous comments. |
@shashvatshahi1998 is this done or anything left, if left can i work on this?? |
@amanp592 I am working on further modification as told by wchargin |
@shashvatshahi1998 ohk cool |
Summary: Fixes #2121. Test Plan: $ git grep '__metaclass__' | wc -l 0 wchargin-branch: six-add-metaclass
Summary: Fixes #2121. Test Plan: $ git grep '__metaclass__' | wc -l 0 wchargin-branch: six-add-metaclass
Low-priority.
Our codebase assigns to
__metaclass__
to set metaclasses, but thisonly works in Python 2. The portable way is to use
six.add_metaclass
,which works as a decorator. The following occurrences are broken in
Python 3:
Demo:
The text was updated successfully, but these errors were encountered: