From 51b1ca12f3f833c0a4af897ce2890380df825290 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 27 Nov 2023 18:02:14 +0000 Subject: [PATCH 1/2] [pre-commit.ci] pre-commit autoupdate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/pre-commit/pre-commit-hooks: v4.4.0 → v4.5.0](https://github.com/pre-commit/pre-commit-hooks/compare/v4.4.0...v4.5.0) - [github.com/psf/black: 23.7.0 → 23.11.0](https://github.com/psf/black/compare/23.7.0...23.11.0) - [github.com/pre-commit/mirrors-mypy: v1.4.1 → v1.7.1](https://github.com/pre-commit/mirrors-mypy/compare/v1.4.1...v1.7.1) - [github.com/PyCQA/autoflake: v2.2.0 → v2.2.1](https://github.com/PyCQA/autoflake/compare/v2.2.0...v2.2.1) - [github.com/pycqa/flake8: 6.0.0 → 6.1.0](https://github.com/pycqa/flake8/compare/6.0.0...6.1.0) - [github.com/netromdk/vermin: v1.5.2 → v1.6.0](https://github.com/netromdk/vermin/compare/v1.5.2...v1.6.0) - [github.com/adrienverge/yamllint.git: v1.32.0 → v1.33.0](https://github.com/adrienverge/yamllint.git/compare/v1.32.0...v1.33.0) - [github.com/igorshubovych/markdownlint-cli: v0.35.0 → v0.37.0](https://github.com/igorshubovych/markdownlint-cli/compare/v0.35.0...v0.37.0) --- .pre-commit-config.yaml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index ab895f8..1f885ea 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -3,7 +3,7 @@ exclude: ^(api_protobuf/.*|docs/protobuf_docs\.md|dhaul_openapi/messages/.*)$ repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.4.0 + rev: v4.5.0 hooks: - id: check-yaml - id: end-of-file-fixer @@ -16,7 +16,7 @@ repos: - id: check-merge-conflict - id: check-added-large-files - repo: https://github.com/psf/black - rev: 23.7.0 + rev: 23.11.0 hooks: - id: black args: [--config=pyproject.toml] @@ -25,7 +25,7 @@ repos: hooks: - id: isort - repo: https://github.com/pre-commit/mirrors-mypy - rev: "v1.4.1" + rev: "v1.7.1" hooks: - id: mypy - repo: https://github.com/PyCQA/docformatter @@ -36,28 +36,28 @@ repos: - --in-place - --config=pyproject.toml - repo: https://github.com/PyCQA/autoflake - rev: v2.2.0 + rev: v2.2.1 hooks: - id: autoflake - repo: https://github.com/pycqa/flake8 - rev: 6.0.0 + rev: 6.1.0 hooks: - id: flake8 entry: pflake8 additional_dependencies: [pyproject-flake8] - repo: https://github.com/netromdk/vermin - rev: v1.5.2 + rev: v1.6.0 hooks: - id: vermin # specify your target version here, OR in a Vermin config file as usual: args: ["-t=3.9-", "--violations"] # (if your target is specified in a Vermin config, you may omit the 'args' entry entirely) - repo: https://github.com/adrienverge/yamllint.git - rev: v1.32.0 + rev: v1.33.0 hooks: - id: yamllint - repo: https://github.com/igorshubovych/markdownlint-cli - rev: v0.35.0 + rev: v0.37.0 hooks: - id: markdownlint-fix - id: markdownlint From d30b6ea2d262da8b5877ddfd891a1150f25838a5 Mon Sep 17 00:00:00 2001 From: alufers Date: Tue, 5 Dec 2023 19:23:26 +0100 Subject: [PATCH 2/2] refactor: Use isinstance instead of type comparison for value check Use isinstance function instead of type comparison for checking the type of the value in the utility functions `value_to_schema` and `limit_example_size`. As suggested by flake8. --- mitmproxy2swagger/swagger_util.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/mitmproxy2swagger/swagger_util.py b/mitmproxy2swagger/swagger_util.py index 4d50ca8..f9847fa 100644 --- a/mitmproxy2swagger/swagger_util.py +++ b/mitmproxy2swagger/swagger_util.py @@ -111,22 +111,22 @@ def response_to_headers(headers): def value_to_schema(value): # check if value is a number - if type(value) == int or type(value) == float: + if isinstance(value, (int, float)): return {"type": "number"} # check if value is a boolean - elif type(value) == bool: + elif isinstance(value, bool): return {"type": "boolean"} # check if value is a string - elif type(value) == str: + elif isinstance(value, str): return {"type": "string"} # check if value is a list - elif type(value) == list: + elif isinstance(value, list): if len(value) == 0: return {"type": "array", "items": {}} return {"type": "array", "items": value_to_schema(value[0])} # check if value is a dict - elif type(value) == dict: + elif isinstance(value, dict): return { "type": "object", "properties": {key: value_to_schema(value[key]) for key in value}, @@ -142,14 +142,14 @@ MAX_EXAMPLE_OBJECT_PROPERTIES = 150 # recursively scan an example value and limit the number of elements and properties def limit_example_size(example): - if type(example) == list: + if isinstance(example, list): new_list = [] for element in example: if len(new_list) >= MAX_EXAMPLE_ARRAY_ELEMENTS: break new_list.append(limit_example_size(element)) return new_list - elif type(example) == dict: + elif isinstance(example, dict): new_dict = {} for key in example: if len(new_dict) >= MAX_EXAMPLE_OBJECT_PROPERTIES: