diff --git a/mypy.ini b/mypy.ini index bb378a66..9c307d85 100644 --- a/mypy.ini +++ b/mypy.ini @@ -1,25 +1,8 @@ [mypy] +strict = True show_error_context = true show_column_numbers = true show_error_codes = true pretty = true +warn_unreachable = True -# --strict options as of mypy 0.910 -warn_unused_configs = True -disallow_any_generics = True -disallow_subclassing_any = True -disallow_untyped_calls = True -disallow_untyped_defs = True -disallow_incomplete_defs = True -check_untyped_defs = True -disallow_untyped_decorators = True -no_implicit_optional = True -warn_redundant_casts = True -warn_unused_ignores = True -warn_return_any = True -implicit_reexport = False -strict_equality = True -enable_recursive_aliases = True - -[mypy-ruamel.*] -ignore_errors = True diff --git a/schema_salad/avro/schema.py b/schema_salad/avro/schema.py index 0fb1a2a3..51790335 100644 --- a/schema_salad/avro/schema.py +++ b/schema_salad/avro/schema.py @@ -240,14 +240,11 @@ def __init__( ) -> None: # Ensure valid ctor args if not name: - fail_msg = "Named Schemas must have a non-empty name." - raise SchemaParseException(fail_msg) + raise SchemaParseException("Named Schemas must have a non-empty name.") elif not isinstance(name, str): - fail_msg = "The name property must be a string." - raise SchemaParseException(fail_msg) + raise SchemaParseException("The name property must be a string.") elif namespace is not None and not isinstance(namespace, str): - fail_msg = "The namespace property must be a string." - raise SchemaParseException(fail_msg) + raise SchemaParseException("The namespace property must be a string.") if names is None: raise SchemaParseException("Must provide Names.") @@ -289,7 +286,7 @@ def __init__( fail_msg = "Fields must have a non-empty name." raise SchemaParseException(fail_msg) elif not isinstance(name, str): - fail_msg = "The name property must be a string." + fail_msg = "The name property must be a string." # type: ignore[unreachable] raise SchemaParseException(fail_msg) elif order is not None and order not in VALID_FIELD_SORT_ORDERS: fail_msg = f"The order property {order} is not valid." @@ -368,14 +365,13 @@ def __init__( ) -> None: # Ensure valid ctor args if not isinstance(symbols, list): - fail_msg = "Enum Schema requires a JSON array for the symbols property." - raise AvroException(fail_msg) + raise AvroException( + "Enum Schema requires a JSON array for the symbols property." + ) elif False in [isinstance(s, str) for s in symbols]: - fail_msg = "Enum Schema requires all symbols to be JSON strings." - raise AvroException(fail_msg) + raise AvroException("Enum Schema requires all symbols to be JSON strings.") elif len(set(symbols)) < len(symbols): - fail_msg = f"Duplicate symbol: {symbols}" - raise AvroException(fail_msg) + raise AvroException(f"Duplicate symbol: {symbols}") # Call parent ctor NamedSchema.__init__(self, "enum", name, namespace, names, other_props) @@ -440,8 +436,7 @@ def __init__( if names is None: raise SchemaParseException("Must provide Names.") if not isinstance(schemas, list): - fail_msg = "Union schema requires a list of schemas." - raise SchemaParseException(fail_msg) + raise SchemaParseException("Union schema requires a list of schemas.") # Call parent ctor Schema.__init__(self, "union") @@ -526,8 +521,9 @@ def __init__( ) -> None: # Ensure valid ctor args if not isinstance(fields, list): - fail_msg = "Fields property must be a list of Avro schemas." - raise SchemaParseException(fail_msg) + raise SchemaParseException( + "Fields property must be a list of Avro schemas." + ) # Call parent ctor (adds own name to namespace, too) NamedSchema.__init__(self, schema_type, name, namespace, names, other_props) diff --git a/schema_salad/main.py b/schema_salad/main.py index 660bfc7a..e6e16154 100644 --- a/schema_salad/main.py +++ b/schema_salad/main.py @@ -354,7 +354,7 @@ def main(argsl: Optional[List[str]] = None) -> int: json_dump(avsc_obj, fp=sys.stdout, indent=4, default=str) return 1 else: - _logger.error("Schema `%s` must be a list.", args.schema) + _logger.error("Schema `%s` must be a list.", args.schema) # type: ignore[unreachable] return 1 # Optionally print Avro-compatible schema from schema diff --git a/schema_salad/metaschema.py b/schema_salad/metaschema.py index d3232468..cfad2983 100644 --- a/schema_salad/metaschema.py +++ b/schema_salad/metaschema.py @@ -778,10 +778,7 @@ def _document_load_by_url( doc_url, frg = urldefrag(url) text = loadingOptions.fetcher.fetch_text(doc_url) - if isinstance(text, bytes): - textIO = StringIO(text.decode("utf-8")) - else: - textIO = StringIO(text) + textIO = StringIO(text) textIO.name = str(doc_url) yaml = yaml_no_ts() result = yaml.load(textIO) diff --git a/schema_salad/python_codegen_support.py b/schema_salad/python_codegen_support.py index b591211b..60694eff 100644 --- a/schema_salad/python_codegen_support.py +++ b/schema_salad/python_codegen_support.py @@ -775,10 +775,7 @@ def _document_load_by_url( doc_url, frg = urldefrag(url) text = loadingOptions.fetcher.fetch_text(doc_url) - if isinstance(text, bytes): - textIO = StringIO(text.decode("utf-8")) - else: - textIO = StringIO(text) + textIO = StringIO(text) textIO.name = str(doc_url) yaml = yaml_no_ts() result = yaml.load(textIO) diff --git a/schema_salad/ref_resolver.py b/schema_salad/ref_resolver.py index 078a7021..3463c4b3 100644 --- a/schema_salad/ref_resolver.py +++ b/schema_salad/ref_resolver.py @@ -856,11 +856,9 @@ def resolve_all( ) elif isinstance(document, CommentedSeq): pass - elif isinstance(document, (list, dict)): + elif isinstance(document, (list, dict)): # type: ignore[unreachable] raise ValidationException( - "Expected CommentedMap or CommentedSeq, got {}: `{}`".format( - type(document), document - ) + f"Expected CommentedMap or CommentedSeq, got {type(document)}: {document!r}" ) else: return (document, metadata) @@ -1008,11 +1006,7 @@ def fetch( return self.idx[url] try: text = self.fetch_text(url, content_types=content_types) - if isinstance(text, bytes): - textIO = StringIO(text.decode("utf-8")) - - else: - textIO = StringIO(text) + textIO = StringIO(text) textIO.name = str(url) yaml = yaml_no_ts() attachments = yaml.load_all(textIO) @@ -1070,10 +1064,10 @@ def validate_scoped(self, field: str, link: str, docid: str) -> str: def validate_link( self, field: str, - link: Union[str, CommentedSeq, CommentedMap], + link: Union[str, CommentedSeq, CommentedMap, None], docid: str, all_doc_ids: Dict[str, str], - ) -> Union[str, CommentedSeq, CommentedMap]: + ) -> Union[str, CommentedSeq, CommentedMap, None]: if field in self.nolinkcheck: return link if isinstance(link, str): @@ -1115,9 +1109,7 @@ def validate_link( return link else: raise ValidationException( - "`{}` field is {}, expected string, list, or a dict.".format( - field, type(link).__name__ - ) + f"{field!r} field is {type(link).__name__}, expected string, list, or a dict." ) return link diff --git a/schema_salad/tests/test_errors.py b/schema_salad/tests/test_errors.py index 5faadee1..90a0ea6d 100644 --- a/schema_salad/tests/test_errors.py +++ b/schema_salad/tests/test_errors.py @@ -119,7 +119,7 @@ def test_error_message4() -> None: match = r""" ^.+test4\.cwl:5:1: checking field\s+`outputs` .+test4\.cwl:6:3: checking object\s+`.+test4\.cwl#bar` -\s+`type`\s+field\s+is\s+int,\s+expected\s+string,\s+list,\s+or\s+a\s+dict.$"""[ +\s+'type'\s+field\s+is\s+int,\s+expected\s+string,\s+list,\s+or\s+a\s+dict.$"""[ 1: ] with pytest.raises(ValidationException, match=match): @@ -206,7 +206,7 @@ def test_error_message9() -> None: match = ( r"""^.+test9\.cwl:7:1: checking field\s+`steps` .+test9\.cwl:8:3: checking object\s+`.+test9\.cwl#step1` -.+test9\.cwl:9:5: `scatterMethod`\s+field\s+is\s+""" +.+test9\.cwl:9:5: 'scatterMethod'\s+field\s+is\s+""" + r"""int,\s+expected\s+string,\s+list,\s+or a\s+dict.$""" ) with pytest.raises(ValidationException, match=match):