From 55b54c26f14f8eaf7b83c484048b1f247325653b Mon Sep 17 00:00:00 2001 From: "Edgar R. M" Date: Thu, 30 Mar 2023 09:56:49 -0600 Subject: [PATCH] chore: Enable `N` (pep8-naming) Ruff checks (#1564) * chore: Enable `N` (pep8-naming) Ruff checks * Disable N818 globally --- pyproject.toml | 6 ++++-- samples/sample_tap_bigquery/__init__.py | 2 +- singer_sdk/_singerlib/schema.py | 16 ++++++++-------- singer_sdk/helpers/capabilities.py | 2 +- singer_sdk/mapper_base.py | 4 ++-- singer_sdk/plugin_base.py | 16 ++++++++-------- singer_sdk/streams/graphql.py | 2 +- singer_sdk/tap_base.py | 2 +- singer_sdk/target_base.py | 2 +- singer_sdk/testing/factory.py | 16 ++++++++-------- singer_sdk/typing.py | 12 ++++++------ tests/core/test_streams.py | 2 +- 12 files changed, 42 insertions(+), 40 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 390916d1e..de12656b0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -217,8 +217,9 @@ exclude = [ "cookiecutter/*", ] ignore = [ - "ANN101", - "ANN102", + "ANN101", # Missing type annotation for `self` in method + "ANN102", # Missing type annotation for `cls` in class method + "N818", # Exception name should be named with an Error suffix ] line-length = 88 select = [ @@ -226,6 +227,7 @@ select = [ "E", # pycodestyle (error) "W", # pycodestyle (warning) "I", # isort + "N", # pep8-naming "D", # pydocstyle/flake8-docstrings "UP", # pyupgrade "YTT", # flake8-2020 diff --git a/samples/sample_tap_bigquery/__init__.py b/samples/sample_tap_bigquery/__init__.py index 0607a8080..bf0681faf 100644 --- a/samples/sample_tap_bigquery/__init__.py +++ b/samples/sample_tap_bigquery/__init__.py @@ -9,7 +9,7 @@ class BigQueryConnector(SQLConnector): """Connects to the BigQuery SQL source.""" - def get_sqlalchemy_url(cls, config: dict) -> str: + def get_sqlalchemy_url(self, config: dict) -> str: """Concatenate a SQLAlchemy URL for use in connecting to the source.""" return f"bigquery://{config['project_id']}" diff --git a/singer_sdk/_singerlib/schema.py b/singer_sdk/_singerlib/schema.py index 442c16478..3b396f971 100644 --- a/singer_sdk/_singerlib/schema.py +++ b/singer_sdk/_singerlib/schema.py @@ -49,15 +49,15 @@ class Schema: description: str | None = None minimum: float | None = None maximum: float | None = None - exclusiveMinimum: float | None = None - exclusiveMaximum: float | None = None - multipleOf: float | None = None - maxLength: int | None = None - minLength: int | None = None - anyOf: t.Any | None = None + exclusiveMinimum: float | None = None # noqa: N815 + exclusiveMaximum: float | None = None # noqa: N815 + multipleOf: float | None = None # noqa: N815 + maxLength: int | None = None # noqa: N815 + minLength: int | None = None # noqa: N815 + anyOf: t.Any | None = None # noqa: N815 format: str | None = None # noqa: A003 - additionalProperties: t.Any | None = None - patternProperties: t.Any | None = None + additionalProperties: t.Any | None = None # noqa: N815 + patternProperties: t.Any | None = None # noqa: N815 required: list[str] | None = None enum: list[t.Any] | None = None title: str | None = None diff --git a/singer_sdk/helpers/capabilities.py b/singer_sdk/helpers/capabilities.py index 6c4655e08..62b9170bc 100644 --- a/singer_sdk/helpers/capabilities.py +++ b/singer_sdk/helpers/capabilities.py @@ -117,7 +117,7 @@ def __getitem__(self, name: str) -> Any: # noqa: ANN401 obj.emit_warning() return obj - def __getattribute__(cls, name: str) -> Any: # noqa: ANN401 + def __getattribute__(cls, name: str) -> Any: # noqa: ANN401, N805 """Retrieve enum attribute. Args: diff --git a/singer_sdk/mapper_base.py b/singer_sdk/mapper_base.py index bc7880dce..4db2723f2 100644 --- a/singer_sdk/mapper_base.py +++ b/singer_sdk/mapper_base.py @@ -23,7 +23,7 @@ class InlineMapper(PluginBase, SingerReader, metaclass=abc.ABCMeta): """Abstract base class for inline mappers.""" @classproperty - def _env_prefix(cls) -> str: + def _env_prefix(cls) -> str: # noqa: N805 return f"{cls.name.upper().replace('-', '_')}_" @classproperty @@ -111,7 +111,7 @@ def map_batch_message( raise NotImplementedError("BATCH messages are not supported by mappers.") @classproperty - def cli(cls) -> Callable: + def cli(cls) -> Callable: # noqa: N805 """Execute standard CLI handler for inline mappers. Returns: diff --git a/singer_sdk/plugin_base.py b/singer_sdk/plugin_base.py index 90a44110b..a2e6fee40 100644 --- a/singer_sdk/plugin_base.py +++ b/singer_sdk/plugin_base.py @@ -49,7 +49,7 @@ class PluginBase(metaclass=abc.ABCMeta): _config: dict @classproperty - def logger(cls) -> logging.Logger: + def logger(cls) -> logging.Logger: # noqa: N805 """Get logger. Returns: @@ -57,14 +57,14 @@ def logger(cls) -> logging.Logger: """ # Get the level from _LOGLEVEL or LOGLEVEL environment variables plugin_env_prefix = f"{cls.name.upper().replace('-', '_')}_" - LOGLEVEL = os.environ.get(f"{plugin_env_prefix}LOGLEVEL") or os.environ.get( + log_level = os.environ.get(f"{plugin_env_prefix}LOGLEVEL") or os.environ.get( "LOGLEVEL", ) logger = logging.getLogger(cls.name) - if LOGLEVEL is not None and LOGLEVEL.upper() in logging._levelToName.values(): - logger.setLevel(LOGLEVEL.upper()) + if log_level is not None and log_level.upper() in logging._levelToName.values(): + logger.setLevel(log_level.upper()) return logger @@ -132,7 +132,7 @@ def capabilities(self) -> list[CapabilitiesEnum]: ] @classproperty - def _env_var_config(cls) -> dict[str, Any]: + def _env_var_config(cls) -> dict[str, Any]: # noqa: N805 """Return any config specified in environment variables. Variables must match the convention "_", @@ -150,7 +150,7 @@ def _env_var_config(cls) -> dict[str, Any]: # Core plugin metadata: @classproperty - def plugin_version(cls) -> str: + def plugin_version(cls) -> str: # noqa: N805 """Get version. Returns: @@ -163,7 +163,7 @@ def plugin_version(cls) -> str: return version @classproperty - def sdk_version(cls) -> str: + def sdk_version(cls) -> str: # noqa: N805 """Return the package version number. Returns: @@ -400,7 +400,7 @@ def print_about( print(formatted) # noqa: T201 @classproperty - def cli(cls) -> Callable: + def cli(cls) -> Callable: # noqa: N805 """Handle command line execution. Returns: diff --git a/singer_sdk/streams/graphql.py b/singer_sdk/streams/graphql.py index 824ad04fa..37e54043d 100644 --- a/singer_sdk/streams/graphql.py +++ b/singer_sdk/streams/graphql.py @@ -22,7 +22,7 @@ class GraphQLStream(RESTStream, metaclass=abc.ABCMeta): rest_method = "POST" @classproperty - def records_jsonpath(cls) -> str: # type: ignore[override] + def records_jsonpath(cls) -> str: # type: ignore[override] # noqa: N805 """Get the JSONPath expression to extract records from an API response. Returns: diff --git a/singer_sdk/tap_base.py b/singer_sdk/tap_base.py index cae8b7dc5..f75bed389 100644 --- a/singer_sdk/tap_base.py +++ b/singer_sdk/tap_base.py @@ -391,7 +391,7 @@ def sync_all(self) -> None: # Command Line Execution @classproperty - def cli(cls) -> Callable: + def cli(cls) -> Callable: # noqa: N805 """Execute standard CLI handler for taps. Returns: diff --git a/singer_sdk/target_base.py b/singer_sdk/target_base.py index 406b1912d..c3319acad 100644 --- a/singer_sdk/target_base.py +++ b/singer_sdk/target_base.py @@ -501,7 +501,7 @@ def _write_state_message(self, state: dict) -> None: # CLI handler @classproperty - def cli(cls) -> Callable: + def cli(cls) -> Callable: # noqa: N805 """Execute standard CLI handler for taps. Returns: diff --git a/singer_sdk/testing/factory.py b/singer_sdk/testing/factory.py index 152494127..ca5892351 100644 --- a/singer_sdk/testing/factory.py +++ b/singer_sdk/testing/factory.py @@ -73,8 +73,8 @@ def runner(self) -> TapTestRunner | TargetTestRunner: ) if suite.kind in {"tap", "target"}: - for TestClass in suite.tests: - test = TestClass() + for test_class in suite.tests: + test = test_class() test_name = f"test_{suite.kind}_{test.name}" setattr(BaseTestClass, f"test_{suite.kind}_{test.name}", test.run) @@ -90,8 +90,8 @@ def runner(self) -> TapTestRunner | TargetTestRunner: ] param_ids = [stream.name for stream in streams] - for TestClass in suite.tests: - test = TestClass() + for test_class in suite.tests: + test = test_class() test_name = f"test_{suite.kind}_{test.name}" setattr( BaseTestClass, @@ -102,8 +102,8 @@ def runner(self) -> TapTestRunner | TargetTestRunner: BaseTestClass.param_ids[test_name] = param_ids if suite.kind == "tap_stream_attribute": - for TestClass in suite.tests: - test = TestClass() + for test_class in suite.tests: + test = test_class() test_name = f"test_{suite.kind}_{test.name}" test_params = [] test_ids = [] @@ -117,7 +117,7 @@ def runner(self) -> TapTestRunner | TargetTestRunner: for property_name, property_schema in stream.schema[ "properties" ].items() - if TestClass.evaluate( + if test_class.evaluate( stream=stream, property_name=property_name, property_schema=property_schema, @@ -130,7 +130,7 @@ def runner(self) -> TapTestRunner | TargetTestRunner: for property_name, property_schema in stream.schema[ "properties" ].items() - if TestClass.evaluate( + if test_class.evaluate( stream=stream, property_name=property_name, property_schema=property_schema, diff --git a/singer_sdk/typing.py b/singer_sdk/typing.py index 5ec5363c0..f16fcf799 100644 --- a/singer_sdk/typing.py +++ b/singer_sdk/typing.py @@ -163,7 +163,7 @@ class JSONTypeHelper: """Type helper base class for JSONSchema types.""" @classproperty - def type_dict(cls) -> dict: + def type_dict(cls) -> dict: # noqa: N805 """Return dict describing the type. Raises: @@ -207,11 +207,11 @@ class StringType(JSONTypeHelper): """ @classproperty - def _format(cls) -> dict: + def _format(cls) -> dict: # noqa: N805 return {"format": cls.string_format} if cls.string_format else {} @classproperty - def type_dict(cls) -> dict: + def type_dict(cls) -> dict: # noqa: N805 """Get type dictionary. Returns: @@ -332,7 +332,7 @@ class BooleanType(JSONTypeHelper): """Boolean type.""" @classproperty - def type_dict(cls) -> dict: + def type_dict(cls) -> dict: # noqa: N805 """Get type dictionary. Returns: @@ -345,7 +345,7 @@ class IntegerType(JSONTypeHelper): """Integer type.""" @classproperty - def type_dict(cls) -> dict: + def type_dict(cls) -> dict: # noqa: N805 """Get type dictionary. Returns: @@ -358,7 +358,7 @@ class NumberType(JSONTypeHelper): """Number type.""" @classproperty - def type_dict(cls) -> dict: + def type_dict(cls) -> dict: # noqa: N805 """Get type dictionary. Returns: diff --git a/tests/core/test_streams.py b/tests/core/test_streams.py index 7a8a1601b..35c1385e2 100644 --- a/tests/core/test_streams.py +++ b/tests/core/test_streams.py @@ -383,7 +383,7 @@ def test_jsonpath_graphql_stream_override(tap: SimpleTestTap): class GraphQLJSONPathOverride(GraphqlTestStream): @classproperty - def records_jsonpath(cls): + def records_jsonpath(cls): # noqa: N805 return "$[*]" stream = GraphQLJSONPathOverride(tap)