Skip to content

Commit 61bd4b7

Browse files
authored
Merge pull request #68 from modern-python/ty
migrate to ty
2 parents 6966f80 + 5e0d81e commit 61bd4b7

10 files changed

Lines changed: 16 additions & 21 deletions

File tree

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ __pycache__/*
99
.idea
1010
.DS_Store
1111
.env
12-
.mypy_cache
1312
.pytest_cache
1413
.ruff_cache
1514
.coverage

Justfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ lint:
88
uv run eof-fixer .
99
uv run ruff format
1010
uv run ruff check --fix
11-
uv run mypy .
11+
uv run ty check
1212

1313
lint-ci:
1414
uv run eof-fixer . --check
1515
uv run ruff format --check
1616
uv run ruff check --no-fix
17-
uv run mypy .
17+
uv run ty check
1818

1919
test *args:
2020
uv run --no-sync pytest {{ args }}

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
Lite-Bootstrap
22
==
33
[![Test Coverage](https://codecov.io/gh/modern-python/lite-bootstrap/branch/main/graph/badge.svg)](https://codecov.io/gh/modern-python/lite-bootstrap)
4-
[![MyPy Strict](https://img.shields.io/badge/mypy-strict-blue)](https://mypy.readthedocs.io/en/stable/getting_started.html#strict-mode-and-configuration)
54
[![Supported versions](https://img.shields.io/pypi/pyversions/lite-bootstrap.svg)](https://pypi.python.org/pypi/lite-bootstrap)
65
[![downloads](https://img.shields.io/pypi/dm/lite-bootstrap.svg)](https://pypistats.org/packages/lite-bootstrap)
76
[![GitHub stars](https://img.shields.io/github/stars/modern-python/lite-bootstrap)](https://github.com/modern-python/lite-bootstrap/stargazers)

lite_bootstrap/bootstrappers/fastapi_bootstrapper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class FastApiCorsInstrument(CorsInstrument):
6464

6565
def bootstrap(self) -> None:
6666
self.bootstrap_config.application.add_middleware(
67-
CORSMiddleware,
67+
CORSMiddleware, # ty: ignore[invalid-argument-type]
6868
allow_origins=self.bootstrap_config.cors_allowed_origins,
6969
allow_methods=self.bootstrap_config.cors_allowed_methods,
7070
allow_headers=self.bootstrap_config.cors_allowed_headers,

lite_bootstrap/bootstrappers/faststream_bootstrapper.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def __init__(
5252

5353
@dataclasses.dataclass(kw_only=True, slots=True, frozen=True)
5454
class FastStreamConfig(HealthChecksConfig, LoggingConfig, OpentelemetryConfig, PrometheusConfig, SentryConfig):
55-
application: "AsgiFastStream" = dataclasses.field(default_factory=lambda: AsgiFastStream())
55+
application: "AsgiFastStream" = dataclasses.field(default_factory=AsgiFastStream)
5656
opentelemetry_middleware_cls: type[FastStreamTelemetryMiddlewareProtocol] | None = None
5757
prometheus_middleware_cls: type[FastStreamPrometheusMiddlewareProtocol] | None = None
5858

@@ -103,7 +103,7 @@ def bootstrap(self) -> None:
103103
if self.bootstrap_config.opentelemetry_middleware_cls and self.bootstrap_config.application.broker:
104104
self.bootstrap_config.opentelemetry_middleware_cls(tracer_provider=get_tracer_provider())
105105
self.bootstrap_config.application.broker.add_middleware(
106-
self.bootstrap_config.opentelemetry_middleware_cls(tracer_provider=get_tracer_provider()) # type: ignore[arg-type]
106+
self.bootstrap_config.opentelemetry_middleware_cls(tracer_provider=get_tracer_provider())
107107
)
108108

109109

@@ -116,7 +116,7 @@ class FastStreamSentryInstrument(SentryInstrument):
116116
class FastStreamPrometheusInstrument(PrometheusInstrument):
117117
bootstrap_config: FastStreamConfig
118118
collector_registry: "prometheus_client.CollectorRegistry" = dataclasses.field(
119-
default_factory=lambda: prometheus_client.CollectorRegistry(), init=False
119+
default_factory=prometheus_client.CollectorRegistry, init=False
120120
)
121121
not_ready_message = PrometheusInstrument.not_ready_message + " or prometheus_middleware_cls is missing"
122122
missing_dependency_message = "prometheus_client is not installed"
@@ -138,7 +138,7 @@ def bootstrap(self) -> None:
138138
)
139139
if self.bootstrap_config.prometheus_middleware_cls and self.bootstrap_config.application.broker:
140140
self.bootstrap_config.application.broker.add_middleware(
141-
self.bootstrap_config.prometheus_middleware_cls(registry=self.collector_registry) # type: ignore[arg-type]
141+
self.bootstrap_config.prometheus_middleware_cls(registry=self.collector_registry)
142142
)
143143

144144

lite_bootstrap/bootstrappers/litestar_bootstrapper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class LitestarConfig(
4949
SentryConfig,
5050
SwaggerConfig,
5151
):
52-
application_config: "AppConfig" = dataclasses.field(default_factory=lambda: AppConfig())
52+
application_config: "AppConfig" = dataclasses.field(default_factory=AppConfig)
5353
opentelemetry_excluded_urls: list[str] = dataclasses.field(default_factory=list)
5454
prometheus_additional_params: dict[str, typing.Any] = dataclasses.field(default_factory=dict)
5555
swagger_extra_params: dict[str, typing.Any] = dataclasses.field(default_factory=dict)

lite_bootstrap/instruments/opentelemetry_instrument.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88

99
if typing.TYPE_CHECKING:
10-
from opentelemetry.instrumentation.instrumentor import BaseInstrumentor # type: ignore[attr-defined]
10+
from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
1111

1212
if import_checker.is_opentelemetry_installed:
1313
from opentelemetry.exporter.otlp.proto.grpc.trace_exporter import OTLPSpanExporter

lite_bootstrap/instruments/sentry_instrument.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def enrich_sentry_event_from_structlog_log(
5858
return None
5959

6060
if event_name := loaded_formatted_log.get("event"):
61-
event["logentry"]["formatted"] = event_name # type: ignore[index]
61+
event["logentry"]["formatted"] = event_name
6262
else:
6363
return event
6464

pyproject.toml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ dev = [
123123
"redis>=5.2.1",
124124
]
125125
lint = [
126-
"mypy",
126+
"ty",
127127
"ruff",
128128
"eof-fixer",
129129
]
@@ -136,10 +136,6 @@ build-backend = "uv_build"
136136
module-name = "lite_bootstrap"
137137
module-root = ""
138138

139-
[tool.mypy]
140-
python_version = "3.10"
141-
strict = true
142-
143139
[tool.ruff]
144140
fix = false
145141
unsafe-fixes = true

tests/conftest.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@
55

66
import pytest
77
import sentry_sdk
8-
from opentelemetry.instrumentation.instrumentor import BaseInstrumentor # type: ignore[attr-defined]
8+
from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
9+
from sentry_sdk.envelope import Envelope
910
from structlog.typing import EventDict, WrappedLogger
1011

1112
from lite_bootstrap import import_checker
1213

1314

14-
class CustomInstrumentor(BaseInstrumentor): # type: ignore[misc]
15+
class CustomInstrumentor(BaseInstrumentor):
1516
def instrumentation_dependencies(self) -> typing.Collection[str]:
1617
return []
1718

@@ -22,9 +23,9 @@ def _uninstrument(self, **kwargs: typing.Mapping[str, typing.Any]) -> None:
2223
class SentryTestTransport(sentry_sdk.Transport):
2324
def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: # noqa: ANN401
2425
super().__init__(*args, **kwargs)
25-
self.mock_envelopes: list[sentry_sdk.envelope.Envelope] = []
26+
self.mock_envelopes: list[Envelope] = []
2627

27-
def capture_envelope(self, envelope: sentry_sdk.envelope.Envelope) -> None:
28+
def capture_envelope(self, envelope: Envelope) -> None:
2829
self.mock_envelopes.append(envelope)
2930

3031

0 commit comments

Comments
 (0)