Skip to content

Commit 82c4db1

Browse files
committed
style: deal with B024 added to flake8 recently
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.
1 parent 5aca0df commit 82c4db1

File tree

4 files changed

+12
-6
lines changed

4 files changed

+12
-6
lines changed

skywalking/agent/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
from skywalking.trace.context import Segment
3636

3737
__started = False
38-
__protocol = Protocol() # type: Protocol
38+
__protocol = None # type: Protocol
3939
__heartbeat_thread = __report_thread = __log_report_thread = __query_profile_thread = __command_dispatch_thread \
4040
= __send_profile_thread = __queue = __log_queue = __snapshot_queue = __finished = None
4141

skywalking/agent/protocol/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# limitations under the License.
1616
#
1717

18-
from abc import ABC
18+
from abc import ABC, abstractmethod
1919
from queue import Queue
2020

2121

@@ -29,12 +29,15 @@ def fork_after_in_parent(self):
2929
def fork_after_in_child(self):
3030
pass
3131

32+
@abstractmethod
3233
def heartbeat(self):
3334
raise NotImplementedError()
3435

36+
@abstractmethod
3537
def report(self, queue: Queue, block: bool = True):
3638
raise NotImplementedError()
3739

40+
@abstractmethod
3841
def report_log(self, queue: Queue, block: bool = True):
3942
raise NotImplementedError()
4043

skywalking/trace/span.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#
1717

1818
import time
19-
from abc import ABC
2019
from collections import defaultdict
2120
from typing import List, Union, DefaultDict
2221
from typing import TYPE_CHECKING
@@ -33,7 +32,12 @@
3332

3433

3534
@tostring
36-
class Span(ABC):
35+
class Span:
36+
def __new__(cls, *args, **kwargs):
37+
if cls is Span:
38+
raise TypeError(f"only children of '{cls.__name__}' may be instantiated")
39+
return object.__new__(cls, *args, **kwargs)
40+
3741
def __init__(
3842
self,
3943
context: 'SpanContext',

tests/plugin/base.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import inspect
1919
import os
2020
import sys
21-
from abc import ABC
2221
from difflib import Differ
2322
from os.path import dirname
2423

@@ -32,7 +31,7 @@
3231
from yaml import SafeLoader as Loader
3332

3433

35-
class TestPluginBase(ABC):
34+
class TestPluginBase:
3635
def validate(self, expected_file_name=None):
3736
# type: (str) -> Response
3837

0 commit comments

Comments
 (0)