Skip to content

Commit 2fc9765

Browse files
authored
Revert non-tooling Pyright compatibility changes
1 parent a9d3ff5 commit 2fc9765

6 files changed

Lines changed: 13 additions & 101 deletions

File tree

.isort.cfg

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
## read the docs: https://pycqa.github.io/isort/docs/configuration/options.html
33
## keep in sync with flake8 config - in `.flake8` file
44
known_first_party = cyclonedx
5-
known_third_party = py_serializable
65
skip_gitignore = false
76
skip_glob =
87
build/*,dist/*,__pycache__,.eggs,*.egg-info*,

cyclonedx/model/definition.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -375,10 +375,8 @@ def requirements(self) -> 'SortedSet[BomRef]':
375375

376376
@requirements.setter
377377
def requirements(self, requirements: Iterable[Union[str, BomRef]]) -> None:
378-
self._requirements = SortedSet(
379-
_bom_ref_from_str(requirement)
380-
for requirement in requirements
381-
)
378+
self._requirements = SortedSet(map(_bom_ref_from_str, # type:ignore[arg-type]
379+
requirements))
382380

383381
def __comparable_tuple(self) -> _ComparableTuple:
384382
# all properties are optional - so need to compare all, in hope that one is unique

cyclonedx/schema/__init__.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,22 +73,19 @@ def to_version(self) -> str:
7373
"""Return as a version string - e.g. `1.4`"""
7474
return '.'.join(map(str, self.value))
7575

76-
def __comparable_value(self) -> tuple[int, int]:
77-
return self.value
78-
7976
def __ne__(self, other: Any) -> bool:
8077
if isinstance(other, self.__class__):
8178
return self.value != other.value
8279
return NotImplemented # pragma: no cover
8380

8481
def __lt__(self, other: Any) -> bool:
8582
if isinstance(other, self.__class__):
86-
return self.__comparable_value() < other.__comparable_value()
83+
return self.value < other.value
8784
return NotImplemented # pragma: no cover
8885

8986
def __le__(self, other: Any) -> bool:
9087
if isinstance(other, self.__class__):
91-
return self.__comparable_value() <= other.__comparable_value()
88+
return self.value <= other.value
9289
return NotImplemented # pragma: no cover
9390

9491
def __eq__(self, other: Any) -> bool:
@@ -98,12 +95,12 @@ def __eq__(self, other: Any) -> bool:
9895

9996
def __ge__(self, other: Any) -> bool:
10097
if isinstance(other, self.__class__):
101-
return self.__comparable_value() >= other.__comparable_value()
98+
return self.value >= other.value
10299
return NotImplemented # pragma: no cover
103100

104101
def __gt__(self, other: Any) -> bool:
105102
if isinstance(other, self.__class__):
106-
return self.__comparable_value() > other.__comparable_value()
103+
return self.value > other.value
107104
return NotImplemented # pragma: no cover
108105

109106
def __hash__(self) -> int:

examples/complex_validation.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
from cyclonedx.exception import MissingOptionalDependencyException
2323
from cyclonedx.schema import OutputFormat, SchemaVersion
2424
from cyclonedx.validation import make_schemabased_validator
25-
from cyclonedx.validation.json import JsonValidationError
2625

2726
if TYPE_CHECKING:
2827
from cyclonedx.validation.json import JsonValidator
@@ -86,29 +85,27 @@
8685

8786
# 1. Validate valid SBOM
8887
try:
89-
validation_error = json_validator.validate_str(JSON_SBOM)
88+
validation_errors = json_validator.validate_str(JSON_SBOM)
9089
except MissingOptionalDependencyException as error:
9190
print('JSON validation was skipped:', error)
9291
else:
93-
if validation_error:
92+
if validation_errors:
9493
print('JSON SBOM is unexpectedly invalid!', file=sys.stderr)
9594
else:
9695
print('JSON SBOM is valid')
9796

9897
# 2. Validate invalid SBOM and inspect details
9998
print('\nChecking invalid JSON SBOM...')
10099
try:
101-
validation_error = json_validator.validate_str(INVALID_JSON_SBOM)
100+
validation_errors = json_validator.validate_str(INVALID_JSON_SBOM)
102101
except MissingOptionalDependencyException as error:
103102
print('JSON validation was skipped:', error)
104103
else:
105-
if validation_error:
106-
if not isinstance(validation_error, JsonValidationError):
107-
raise TypeError('Expected a single JSON validation error')
104+
if validation_errors:
108105
print('Validation failed as expected.')
109-
print(f'Error Message: {validation_error.data.message}')
110-
print(f'JSON Path: {validation_error.data.json_path}')
111-
print(f'Invalid Data: {validation_error.data.instance}')
106+
print(f'Error Message: {validation_errors.data.message}')
107+
print(f'JSON Path: {validation_errors.data.json_path}')
108+
print(f'Invalid Data: {validation_errors.data.instance}')
112109

113110
# endregion JSON Validation
114111

typings/py_serializable/__init__.pyi

Lines changed: 0 additions & 68 deletions
This file was deleted.

typings/py_serializable/helpers.pyi

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)