Skip to content

Commit b91280d

Browse files
committed
style: upgrade python code style
Signed-off-by: Jan Kowalleck <[email protected]>
1 parent 45979e3 commit b91280d

File tree

10 files changed

+17
-17
lines changed

10 files changed

+17
-17
lines changed

cyclonedx/_internal/compare.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class ComparableDict(ComparableTuple):
6464
"""
6565

6666
def __new__(cls, d: dict[Any, Any]) -> 'ComparableDict':
67-
return super(ComparableDict, cls).__new__(cls, sorted(d.items()))
67+
return super().__new__(cls, sorted(d.items()))
6868

6969

7070
class ComparablePackageURL(ComparableTuple):
@@ -73,7 +73,7 @@ class ComparablePackageURL(ComparableTuple):
7373
"""
7474

7575
def __new__(cls, p: 'PackageURL') -> 'ComparablePackageURL':
76-
return super(ComparablePackageURL, cls).__new__(cls, (
76+
return super().__new__(cls, (
7777
p.type,
7878
p.namespace,
7979
p.version,

cyclonedx/spdx.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
__IDS: set[str] = set(json_load(schema).get('enum', []))
4040
assert len(__IDS) > 0, 'known SPDX-IDs should be non-empty set'
4141

42-
__IDS_LOWER_MAP: dict[str, str] = dict((id_.lower(), id_) for id_ in __IDS)
42+
__IDS_LOWER_MAP: dict[str, str] = {id_.lower(): id_ for id_ in __IDS}
4343

4444
__SPDX_EXPRESSION_LICENSING: 'Licensing' = get_spdx_licensing()
4545

cyclonedx/validation/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def make_schemabased_validator(output_format: OutputFormat, schema_version: 'Sch
111111
"""
112112
if TYPE_CHECKING: # pragma: no cover
113113
from typing import Type
114-
Validator: Type[BaseSchemabasedValidator] # noqa:N806
114+
Validator: type[BaseSchemabasedValidator] # noqa:N806
115115
if OutputFormat.JSON is output_format:
116116
from .json import JsonValidator as Validator
117117
elif OutputFormat.XML is output_format:

tests/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def writeSnapshot(cls, snapshot_name: str, data: str) -> None: # noqa: N802
5858

5959
@classmethod
6060
def readSnapshot(cls, snapshot_name: str) -> str: # noqa: N802
61-
with open(cls.getSnapshotFile(snapshot_name), 'r') as s:
61+
with open(cls.getSnapshotFile(snapshot_name)) as s:
6262
return s.read()
6363

6464
def assertEqualSnapshot(self: Union[TestCase, 'SnapshotMixin'], # noqa: N802

tests/test_deserialize_xml.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def test_prepared(self, get_bom: Callable[[], Bom], *_: Any, **__: Any) -> None:
4242
# only latest schema will have all data populated in serialized form
4343
snapshot_name = mksname(get_bom, SchemaVersion.V1_6, OutputFormat.XML)
4444
expected = get_bom()
45-
with open(self.getSnapshotFile(snapshot_name), 'r') as s:
45+
with open(self.getSnapshotFile(snapshot_name)) as s:
4646
bom = Bom.from_xml(s)
4747
self.assertBomDeepEqual(expected, bom,
4848
fuzzy_deps=get_bom in all_get_bom_funct_with_incomplete_deps)

tests/test_enums.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,7 @@ def dp_cases_from_json_schema(sf: str, jsonpointer: Iterable[str]) -> Generator[
103103
data = data[pp]
104104
except KeyError:
105105
return
106-
for value in data['enum']:
107-
yield value
106+
yield from data['enum']
108107

109108

110109
def dp_cases_from_json_schemas(*jsonpointer: str) -> Generator[str, None, None]:

tests/test_validation_json.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from glob import iglob
1919
from itertools import chain
2020
from os.path import join
21-
from typing import Generator
21+
from collections.abc import Generator
2222
from unittest import TestCase
2323

2424
from ddt import data, ddt, idata, unpack
@@ -69,7 +69,7 @@ def test_throws_with_unsupported_schema_version(self, schema_version: SchemaVers
6969
@unpack
7070
def test_validate_no_none(self, schema_version: SchemaVersion, test_data_file: str) -> None:
7171
validator = JsonValidator(schema_version)
72-
with open(join(test_data_file), 'r') as tdfh:
72+
with open(join(test_data_file)) as tdfh:
7373
test_data = tdfh.read()
7474
try:
7575
validation_error = validator.validate_str(test_data)
@@ -84,7 +84,7 @@ def test_validate_no_none(self, schema_version: SchemaVersion, test_data_file: s
8484
@unpack
8585
def test_validate_expected_error(self, schema_version: SchemaVersion, test_data_file: str) -> None:
8686
validator = JsonValidator(schema_version)
87-
with open(join(test_data_file), 'r') as tdfh:
87+
with open(join(test_data_file)) as tdfh:
8888
test_data = tdfh.read()
8989
try:
9090
validation_error = validator.validate_str(test_data)
@@ -109,7 +109,7 @@ def test_throws_with_unsupported_schema_version(self, schema_version: SchemaVers
109109
@unpack
110110
def test_validate_no_none(self, schema_version: SchemaVersion, test_data_file: str) -> None:
111111
validator = JsonStrictValidator(schema_version)
112-
with open(join(test_data_file), 'r') as tdfh:
112+
with open(join(test_data_file)) as tdfh:
113113
test_data = tdfh.read()
114114
try:
115115
validation_error = validator.validate_str(test_data)
@@ -124,7 +124,7 @@ def test_validate_no_none(self, schema_version: SchemaVersion, test_data_file: s
124124
@unpack
125125
def test_validate_expected_error(self, schema_version: SchemaVersion, test_data_file: str) -> None:
126126
validator = JsonStrictValidator(schema_version)
127-
with open(join(test_data_file), 'r') as tdfh:
127+
with open(join(test_data_file)) as tdfh:
128128
test_data = tdfh.read()
129129
try:
130130
validation_error = validator.validate_str(test_data)

tests/test_validation_xml.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def test_throws_with_unsupported_schema_version(self, schema_version: SchemaVers
6969
@unpack
7070
def test_validate_no_none(self, schema_version: SchemaVersion, test_data_file: str) -> None:
7171
validator = XmlValidator(schema_version)
72-
with open(join(test_data_file), 'r') as tdfh:
72+
with open(join(test_data_file)) as tdfh:
7373
test_data = tdfh.read()
7474
try:
7575
validation_error = validator.validate_str(test_data)
@@ -84,7 +84,7 @@ def test_validate_no_none(self, schema_version: SchemaVersion, test_data_file: s
8484
@unpack
8585
def test_validate_expected_error(self, schema_version: SchemaVersion, test_data_file: str) -> None:
8686
validator = XmlValidator(schema_version)
87-
with open(join(test_data_file), 'r') as tdfh:
87+
with open(join(test_data_file)) as tdfh:
8888
test_data = tdfh.read()
8989
try:
9090
validation_error = validator.validate_str(test_data)

tools/schema-downloader.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@
102102
target = dspec['targetPattern'].replace('%s', version)
103103
tempfile, _ = urlretrieve(source) # nosec B310
104104
print(source, '->', target)
105-
with open(tempfile, 'r') as tmpf:
105+
with open(tempfile) as tmpf:
106106
text = tmpf.read()
107107
with open(target, 'w', newline='\n') as tarf:
108108
for search, replace in dspec['replace']:

typings/sortedcontainers.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
# https://github.com/althonos/python-sortedcontainers/blob/d0a225d7fd0fb4c54532b8798af3cbeebf97e2d5/sortedcontainers/sortedset.pyi
55

66
from collections.abc import Callable, Iterable, MutableSet, Sequence
7-
from typing import Any, Hashable, Optional, TypeVar, Union, overload # Iterator,; Tuple,; Type, Set
7+
from typing import Any, Optional, TypeVar, Union, overload # Iterator,; Tuple,; Type, Set
8+
from collections.abc import Hashable
89

910
# --- Global
1011

0 commit comments

Comments
 (0)