Skip to content

Commit

Permalink
style: deal with B024 added to flake8 recently
Browse files Browse the repository at this point in the history
More details about B024 here PyCQA/flake8-bugbear#274

* ./skywalking/agent/protocol/__init__.py:22:1: B024 Protocol is an abstract base class, but it has no abstract methods.
Set 'heartbeat', 'report' and 'report_log' as abstract method

* ./skywalking/trace/span.py:36:1: B024 Span is an abstract base class, but it has no abstract methods.
Prevent base class Span from being directly instantiated by raising error in __new__ with reference to
https://stackoverflow.com/questions/7989042/preventing-a-class-from-direct-instantiation-in-python

* ./tests/plugin/base.py:35:1: B024 TestPluginBase is an abstract base class
Due to pytest may instantiate parent class for searching test functions, TestPluginBase has to be instantiable.
  • Loading branch information
jiang1997 committed Aug 28, 2022
1 parent 5aca0df commit 82c4db1
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion skywalking/agent/__init__.py
Expand Up @@ -35,7 +35,7 @@
from skywalking.trace.context import Segment

__started = False
__protocol = Protocol() # type: Protocol
__protocol = None # type: Protocol
__heartbeat_thread = __report_thread = __log_report_thread = __query_profile_thread = __command_dispatch_thread \
= __send_profile_thread = __queue = __log_queue = __snapshot_queue = __finished = None

Expand Down
5 changes: 4 additions & 1 deletion skywalking/agent/protocol/__init__.py
Expand Up @@ -15,7 +15,7 @@
# limitations under the License.
#

from abc import ABC
from abc import ABC, abstractmethod
from queue import Queue


Expand All @@ -29,12 +29,15 @@ def fork_after_in_parent(self):
def fork_after_in_child(self):
pass

@abstractmethod
def heartbeat(self):
raise NotImplementedError()

@abstractmethod
def report(self, queue: Queue, block: bool = True):
raise NotImplementedError()

@abstractmethod
def report_log(self, queue: Queue, block: bool = True):
raise NotImplementedError()

Expand Down
8 changes: 6 additions & 2 deletions skywalking/trace/span.py
Expand Up @@ -16,7 +16,6 @@
#

import time
from abc import ABC
from collections import defaultdict
from typing import List, Union, DefaultDict
from typing import TYPE_CHECKING
Expand All @@ -33,7 +32,12 @@


@tostring
class Span(ABC):
class Span:
def __new__(cls, *args, **kwargs):
if cls is Span:
raise TypeError(f"only children of '{cls.__name__}' may be instantiated")
return object.__new__(cls, *args, **kwargs)

def __init__(
self,
context: 'SpanContext',
Expand Down
3 changes: 1 addition & 2 deletions tests/plugin/base.py
Expand Up @@ -18,7 +18,6 @@
import inspect
import os
import sys
from abc import ABC
from difflib import Differ
from os.path import dirname

Expand All @@ -32,7 +31,7 @@
from yaml import SafeLoader as Loader


class TestPluginBase(ABC):
class TestPluginBase:
def validate(self, expected_file_name=None):
# type: (str) -> Response

Expand Down

0 comments on commit 82c4db1

Please sign in to comment.