Skip to content

Commit ee240b5

Browse files
aaronsteersdevin-ai-integration[bot]github-advanced-security[bot]
authored
chore: swap mypy with pyrefly for type checking (#817)
Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
1 parent 1a3354d commit ee240b5

32 files changed

+219
-482
lines changed

.github/workflows/python_lint.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ on:
99
env:
1010
AIRBYTE_ANALYTICS_ID: ${{ vars.AIRBYTE_ANALYTICS_ID }}
1111

12+
permissions:
13+
contents: read
1214
jobs:
1315
ruff-lint-check:
1416
name: Ruff Lint Check
@@ -58,8 +60,8 @@ jobs:
5860
- name: Check code format
5961
run: poetry run ruff format --diff .
6062

61-
mypy-check:
62-
name: MyPy Check
63+
python-type-checks:
64+
name: Python Type Checks
6365
runs-on: ubuntu-latest
6466
steps:
6567
# Common steps:
@@ -81,5 +83,5 @@ jobs:
8183
run: poetry install
8284

8385
# Job-specifc step(s):
84-
- name: Check MyPy typing
85-
run: poetry run mypy .
86+
- name: Run Pyrefly Check
87+
run: poetry run pyrefly check

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ venv.bak/
118118
# mkdocs documentation
119119
/site
120120

121-
# mypy
121+
# Type checkers (mypy, pyrefly)
122122
.mypy_cache/
123123
.dmypy.json
124124
dmypy.json

.ruff.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ ignore = [
8080
"RUF022", # Allow unsorted __all__ (sometimes useful for grouping by type with pdoc)
8181
"S", # flake8-bandit (noisy, security related)
8282
"SIM910", # Allow "None" as second argument to Dict.get(). "Explicit is better than implicit."
83+
"TC006", # Require quoted type names in cast() calls
8384
"TD002", # Require author for TODOs
8485
"ASYNC1", # flake8-trio (opinionated, noisy)
8586
"INP001", # Dir 'examples' is part of an implicit namespace package. Add an __init__.py.

airbyte/_connector_base.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -283,10 +283,10 @@ def print_config_spec(
283283
content = json.dumps(self.config_spec, indent=2)
284284

285285
if output_file:
286-
output_file.write_text(content)
286+
output_file.write_text(content) # pyrefly: ignore[unbound-name]
287287
return
288288

289-
syntax_highlighted = Syntax(content, format)
289+
syntax_highlighted = Syntax(content, format) # pyrefly: ignore[unbound-name]
290290
rich.print(syntax_highlighted, file=sys.stderr if stderr else None)
291291

292292
@property
@@ -300,7 +300,7 @@ def _yaml_spec(self) -> str:
300300
for each connector.
301301
"""
302302
spec_obj: ConnectorSpecification = self._get_spec()
303-
spec_dict = spec_obj.dict(exclude_unset=True)
303+
spec_dict = spec_obj.model_dump(exclude_unset=True)
304304
# convert to a yaml string
305305
return yaml.dump(spec_dict)
306306

@@ -405,25 +405,33 @@ def _peek_airbyte_message(
405405
AirbyteConnectorFailedError: If a TRACE message of type ERROR is emitted.
406406
"""
407407
if message.type == Type.LOG:
408-
self._print_info_message(message.log.message)
408+
self._print_info_message(message.log.message) # pyrefly: ignore[missing-attribute]
409409
return
410410

411-
if message.type == Type.TRACE and message.trace.type == TraceType.ERROR:
412-
self._print_error_message(message.trace.error.message)
411+
if (
412+
message.type == Type.TRACE
413+
and message.trace.type == TraceType.ERROR # pyrefly: ignore[missing-attribute]
414+
):
415+
self._print_error_message(
416+
message.trace.error.message # pyrefly: ignore[missing-attribute]
417+
)
413418
if raise_on_error:
414419
raise exc.AirbyteConnectorFailedError(
415420
connector_name=self.name,
416-
message=message.trace.error.message,
421+
message=message.trace.error.message, # pyrefly: ignore[missing-attribute]
417422
log_text=self._last_log_messages,
418423
)
419424
return
420425

421426
if (
422427
message.type == Type.CONTROL
423-
and message.control.type == OrchestratorType.CONNECTOR_CONFIG
428+
and message.control.type # pyrefly: ignore[missing-attribute]
429+
== OrchestratorType.CONNECTOR_CONFIG
424430
and self.config_change_callback is not None
425431
):
426-
self.config_change_callback(message.control.connectorConfig.config)
432+
self.config_change_callback(
433+
message.control.connectorConfig.config # pyrefly: ignore[missing-attribute]
434+
)
427435
return
428436

429437
def _execute(

airbyte/_message_iterators.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,9 @@ def generator() -> Generator[AirbyteMessage, None, None]:
178178
if current_file_buffer is None:
179179
try:
180180
current_file = next(file_iterator)
181-
current_file_buffer = file_opener(current_file)
181+
current_file_buffer = file_opener(
182+
current_file # pyrefly: ignore[bad-argument-type]
183+
)
182184
except StopIteration:
183185
# No more files to read; Exit the loop
184186
break
@@ -192,7 +194,7 @@ def generator() -> Generator[AirbyteMessage, None, None]:
192194

193195
try:
194196
# Let Pydantic handle the JSON decoding from the raw string
195-
yield (
197+
yield ( # pyrefly: ignore[invalid-yield]
196198
AirbyteMessage.model_validate_json(next_line),
197199
current_file,
198200
)

airbyte/_processors/sql/bigquery.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77
from pathlib import Path
88
from typing import TYPE_CHECKING, cast, final
99

10+
import google.auth
1011
import google.oauth2
1112
import sqlalchemy
13+
import sqlalchemy.exc
1214
from google.api_core.exceptions import NotFound
1315
from google.cloud import bigquery
1416
from google.oauth2 import service_account

airbyte/_processors/sql/postgres.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,5 +71,5 @@ class PostgresSqlProcessor(SqlProcessorBase):
7171
file_writer_class = JsonlWriter
7272
sql_config: PostgresConfig
7373

74-
normalizer = PostgresNormalizer
74+
normalizer = PostgresNormalizer # pyrefly: ignore[bad-override]
7575
"""A Postgres-specific name normalizer for table and column name normalization."""

airbyte/_processors/sql/snowflake.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,9 @@ class SnowflakeSqlProcessor(SqlProcessorBase):
204204
"""A Snowflake implementation of the cache."""
205205

206206
file_writer_class = JsonlWriter
207-
type_converter_class: type[SnowflakeTypeConverter] = SnowflakeTypeConverter
207+
type_converter_class: type[SnowflakeTypeConverter] = ( # pyrefly: ignore[bad-override]
208+
SnowflakeTypeConverter
209+
)
208210
supports_merge_insert = True
209211
sql_config: SnowflakeConfig
210212

airbyte/_util/api_util.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,7 @@ def create_destination(
606606
)
607607
definition_id_override: str | None = None
608608
if _get_destination_type_str(config) == "dev-null":
609-
# TODO: We have to hard-code the definition ID for dev-null destination. (important-comment)
609+
# TODO: We have to hard-code the definition ID for dev-null destination.
610610
# https://github.com/airbytehq/PyAirbyte/issues/743
611611
definition_id_override = "a7bcc9d8-13b3-4e49-b80d-d020b90045e3"
612612
response: api.CreateDestinationResponse = airbyte_instance.destinations.create_destination(
@@ -660,9 +660,9 @@ def get_destination(
660660
}
661661

662662
if destination_type in destination_mapping:
663-
response.destination_response.configuration = destination_mapping[destination_type](
664-
**raw_configuration
665-
)
663+
response.destination_response.configuration = destination_mapping[
664+
destination_type # pyrefly: ignore[index-error]
665+
](**raw_configuration)
666666
return response.destination_response
667667

668668
raise AirbyteMissingResourceError(

airbyte/_util/meta.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ def get_notebook_name() -> str | None:
134134
@lru_cache
135135
def get_vscode_notebook_name() -> str | None:
136136
with suppress(Exception):
137-
import IPython # noqa: PLC0415
137+
import IPython # noqa: PLC0415 # pyrefly: ignore[missing-import]
138138

139139
return Path(
140140
IPython.extract_module_locals()[1]["__vsc_ipynb_file__"],

0 commit comments

Comments
 (0)