diff --git a/pyproject.toml b/pyproject.toml index bc919c60..45b26f00 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -92,8 +92,9 @@ select = [ "I", # isort "N", # pep8-naming "D", # pydocsyle - "ICN", # flake8-import-conventions "UP", # pyupgrade + "ICN", # flake8-import-conventions + "RET", # flake8-return "RUF", # ruff ] diff --git a/target_postgres/connector.py b/target_postgres/connector.py index 547055b2..283163eb 100644 --- a/target_postgres/connector.py +++ b/target_postgres/connector.py @@ -187,10 +187,9 @@ def copy_table_structure( new_table = sa.Table(table_name, meta, *columns, prefixes=["TEMPORARY"]) new_table.create(bind=connection) return new_table - else: - new_table = sa.Table(table_name, meta, *columns) - new_table.create(bind=connection) - return new_table + new_table = sa.Table(table_name, meta, *columns) + new_table.create(bind=connection) + return new_table @contextmanager def _connect(self) -> t.Iterator[sa.engine.Connection]: @@ -653,17 +652,16 @@ def get_sqlalchemy_url(self, config: dict) -> str: if config.get("sqlalchemy_url"): return cast(str, config["sqlalchemy_url"]) - else: - sqlalchemy_url = URL.create( - drivername=config["dialect+driver"], - username=config["user"], - password=config["password"], - host=config["host"], - port=config["port"], - database=config["database"], - query=self.get_sqlalchemy_query(config), - ) - return cast(str, sqlalchemy_url) + sqlalchemy_url = URL.create( + drivername=config["dialect+driver"], + username=config["user"], + password=config["password"], + host=config["host"], + port=config["port"], + database=config["database"], + query=self.get_sqlalchemy_query(config), + ) + return cast(str, sqlalchemy_url) def get_sqlalchemy_query(self, config: dict) -> dict: """Get query values to be used for sqlalchemy URL creation. @@ -725,12 +723,11 @@ def filepath_or_certificate( """ if path.isfile(value): return value - else: - with open(alternative_name, "wb") as alternative_file: - alternative_file.write(value.encode("utf-8")) - if restrict_permissions: - chmod(alternative_name, 0o600) - return alternative_name + with open(alternative_name, "wb") as alternative_file: + alternative_file.write(value.encode("utf-8")) + if restrict_permissions: + chmod(alternative_name, 0o600) + return alternative_name def guess_key_type(self, key_data: str) -> paramiko.PKey: """Guess the type of the private key. diff --git a/target_postgres/sinks.py b/target_postgres/sinks.py index 39332b63..a8b9ee2e 100644 --- a/target_postgres/sinks.py +++ b/target_postgres/sinks.py @@ -307,14 +307,7 @@ def schema_name(self) -> str | None: if default_target_schema: return default_target_schema - if len(parts) in {2, 3}: - # Stream name is a two-part or three-part identifier. - # Use the second-to-last part as the schema name. - stream_schema = self.conform_name(parts[-2], "schema") - return stream_schema - - # Schema name not detected. - return None + return self.conform_name(parts[-2], "schema") if len(parts) in {2, 3} else None def activate_version(self, new_version: int) -> None: """Bump the active version of the target table.