Skip to content

Commit 9dee014

Browse files
committed
Fixed Flake8 issues in v2
Type hinting on non-imported types
1 parent 9a9d351 commit 9dee014

File tree

6 files changed

+74
-45
lines changed

6 files changed

+74
-45
lines changed

javaobj/v2/api.py

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,15 @@
2626

2727
from __future__ import absolute_import
2828

29-
from typing import Optional
29+
from typing import List, Optional
3030

31-
from .beans import JavaClassDesc, JavaInstance # pylint:disable=W0611
32-
from .stream import DataStreamReader # pylint:disable=W0611
3331
from ..constants import TypeCode # pylint:disable=W0611
32+
from .beans import ( # pylint:disable=W0611
33+
JavaClassDesc,
34+
JavaInstance,
35+
ParsedJavaContent,
36+
)
37+
from .stream import DataStreamReader # pylint:disable=W0611
3438

3539
# ------------------------------------------------------------------------------
3640

@@ -44,6 +48,32 @@
4448
# ------------------------------------------------------------------------------
4549

4650

51+
class IJavaStreamParser:
52+
"""
53+
API of the Java stream parser
54+
"""
55+
56+
def run(self):
57+
# type: () -> List[ParsedJavaContent]
58+
"""
59+
Parses the input stream
60+
"""
61+
raise NotImplementedError
62+
63+
def dump(self, content):
64+
# type: (List[ParsedJavaContent]) -> str
65+
"""
66+
Dumps to a string the given objects
67+
"""
68+
raise NotImplementedError
69+
70+
def _read_content(self, type_code, block_data, class_desc=None):
71+
# type: (int, bool, Optional[JavaClassDesc]) -> ParsedJavaContent
72+
"""
73+
Parses the next content. Use with care (use only in a transformer)
74+
"""
75+
76+
4777
class ObjectTransformer(object): # pylint:disable=R0205
4878
"""
4979
Representation of an object transformer
@@ -84,7 +114,7 @@ def load_array(
84114
def load_custom_writeObject(
85115
self, parser, reader, name
86116
): # pylint:disable=W0613,R0201
87-
# type: (JavaStreamParser, DataStreamReader, str) -> Optional[JavaClassDesc]
117+
# type: (IJavaStreamParser, DataStreamReader, str) -> Optional[JavaClassDesc]
88118
"""
89119
Reads content stored from a custom writeObject.
90120

javaobj/v2/beans.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@
2626

2727
from __future__ import absolute_import
2828

29+
import logging
2930
from enum import IntEnum
3031
from typing import Any, Dict, List, Optional, Set
31-
import logging
3232

3333
from ..constants import ClassDescFlags, TypeCode
34-
from ..modifiedutf8 import decode_modified_utf8, byte_to_int
34+
from ..modifiedutf8 import byte_to_int, decode_modified_utf8
3535
from ..utils import UNICODE_TYPE
3636

3737
# ------------------------------------------------------------------------------

javaobj/v2/core.py

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -27,46 +27,45 @@
2727

2828
from __future__ import absolute_import
2929

30-
from typing import (
30+
import logging
31+
import os
32+
from typing import ( # pylint:disable=W0611
33+
IO,
3134
Any,
3235
Callable,
3336
Dict,
34-
IO,
3537
List,
3638
Optional,
37-
) # pylint:disable=W0611
38-
import logging
39-
import os
39+
)
4040

41+
from ..constants import (
42+
PRIMITIVE_TYPES,
43+
StreamConstants,
44+
TerminalCode,
45+
TypeCode,
46+
)
47+
from ..modifiedutf8 import ( # pylint:disable=W0611 # noqa: F401
48+
decode_modified_utf8,
49+
)
4150
from . import api # pylint:disable=W0611
4251
from .beans import (
43-
ParsedJavaContent,
4452
BlockData,
45-
JavaClassDesc,
46-
JavaClass,
53+
ClassDataType,
54+
ClassDescType,
55+
ExceptionRead,
56+
ExceptionState,
57+
FieldType,
4758
JavaArray,
59+
JavaClass,
60+
JavaClassDesc,
4861
JavaEnum,
4962
JavaField,
5063
JavaInstance,
5164
JavaString,
52-
ExceptionState,
53-
ExceptionRead,
54-
ClassDescType,
55-
FieldType,
56-
ClassDataType,
65+
ParsedJavaContent,
5766
)
5867
from .stream import DataStreamReader
5968
from .transformers import DefaultObjectTransformer
60-
from ..constants import (
61-
StreamConstants,
62-
TerminalCode,
63-
TypeCode,
64-
PRIMITIVE_TYPES,
65-
)
66-
67-
from ..modifiedutf8 import (
68-
decode_modified_utf8,
69-
) # pylint:disable=W0611 # noqa: F401
7069

7170
# ------------------------------------------------------------------------------
7271

@@ -80,7 +79,7 @@
8079
# ------------------------------------------------------------------------------
8180

8281

83-
class JavaStreamParser:
82+
class JavaStreamParser(api.IJavaStreamParser):
8483
"""
8584
Parses a Java stream
8685
"""

javaobj/v2/main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
from __future__ import absolute_import
77

8-
from typing import Any, IO # pylint:disable=W0611
8+
from typing import IO, Any # pylint:disable=W0611
99

1010
try:
1111
# Python 2
@@ -14,10 +14,10 @@
1414
# Python 3+
1515
from io import BytesIO
1616

17+
from ..utils import java_data_fd
1718
from .api import ObjectTransformer # pylint:disable=W0611
1819
from .core import JavaStreamParser
1920
from .transformers import DefaultObjectTransformer, NumpyArrayTransformer
20-
from ..utils import java_data_fd
2121

2222
# ------------------------------------------------------------------------------
2323

javaobj/v2/stream.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@
2626

2727
from __future__ import absolute_import
2828

29-
from typing import Any, IO, Tuple # pylint:disable=W0611
3029
import struct
30+
from typing import IO, Any, Tuple # pylint:disable=W0611
3131

3232
from ..modifiedutf8 import decode_modified_utf8
33-
from ..utils import unicode_char, UNICODE_TYPE # pylint:disable=W0611
33+
from ..utils import UNICODE_TYPE, unicode_char # pylint:disable=W0611
3434

3535
# ------------------------------------------------------------------------------
3636

javaobj/v2/transformers.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,25 +25,25 @@
2525
"""
2626

2727
# Standard library
28-
from typing import List, Optional, Tuple
2928
import functools
29+
from typing import List, Optional, Tuple
3030

3131
# Numpy (optional)
3232
try:
3333
import numpy
3434
except ImportError:
35-
numpy = None
36-
35+
numpy = None # type: ignore
3736

3837
# Javaobj
39-
from .api import ObjectTransformer
40-
from .beans import (
41-
JavaInstance,
42-
JavaClassDesc,
43-
BlockData,
44-
) # pylint:disable=W0611
4538
from ..constants import TerminalCode, TypeCode
46-
from ..utils import to_bytes, log_error, log_debug, read_struct, read_string
39+
from ..utils import log_debug, log_error, read_string, read_struct, to_bytes
40+
from .api import IJavaStreamParser, ObjectTransformer
41+
from .beans import ( # pylint:disable=W0611
42+
BlockData,
43+
JavaClassDesc,
44+
JavaInstance,
45+
)
46+
from .stream import DataStreamReader
4747

4848
# ------------------------------------------------------------------------------
4949

@@ -183,7 +183,7 @@ class JavaLinkedHashMap(JavaMap):
183183
HANDLED_CLASSES = ("java.util.LinkedHashMap",)
184184

185185
def load_from_blockdata(self, parser, reader, indent=0):
186-
# type: (JavaStreamParser, DataStreamReader, int) -> bool
186+
# type: (IJavaStreamParser, DataStreamReader, int) -> bool
187187
"""
188188
Loads the content of the map, written with a custom implementation
189189
"""

0 commit comments

Comments
 (0)