Browse Source

⬆️ Upgrade version of Ruff and reformat (#12032)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
pull/10168/head
Sebastián Ramírez 8 months ago
committed by GitHub
parent
commit
3a3ad5d66d
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 6
      .github/actions/people/app/main.py
  2. 2
      .pre-commit-config.yaml
  3. 6
      fastapi/dependencies/utils.py
  4. 12
      fastapi/routing.py
  5. 6
      fastapi/utils.py
  6. 2
      requirements-tests.txt
  7. 6
      tests/test_dependency_contextmanager.py
  8. 4
      tests/test_inherited_custom_class.py

6
.github/actions/people/app/main.py

@ -515,9 +515,9 @@ def get_individual_sponsors(settings: Settings):
tiers: DefaultDict[float, Dict[str, SponsorEntity]] = defaultdict(dict) tiers: DefaultDict[float, Dict[str, SponsorEntity]] = defaultdict(dict)
for node in nodes: for node in nodes:
tiers[node.tier.monthlyPriceInDollars][ tiers[node.tier.monthlyPriceInDollars][node.sponsorEntity.login] = (
node.sponsorEntity.login node.sponsorEntity
] = node.sponsorEntity )
return tiers return tiers

2
.pre-commit-config.yaml

@ -14,7 +14,7 @@ repos:
- id: end-of-file-fixer - id: end-of-file-fixer
- id: trailing-whitespace - id: trailing-whitespace
- repo: https://github.com/charliermarsh/ruff-pre-commit - repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.2.0 rev: v0.6.1
hooks: hooks:
- id: ruff - id: ruff
args: args:

6
fastapi/dependencies/utils.py

@ -342,9 +342,9 @@ def analyze_param(
if isinstance(arg, (params.Param, params.Body, params.Depends)) if isinstance(arg, (params.Param, params.Body, params.Depends))
] ]
if fastapi_specific_annotations: if fastapi_specific_annotations:
fastapi_annotation: Union[ fastapi_annotation: Union[FieldInfo, params.Depends, None] = (
FieldInfo, params.Depends, None fastapi_specific_annotations[-1]
] = fastapi_specific_annotations[-1] )
else: else:
fastapi_annotation = None fastapi_annotation = None
if isinstance(fastapi_annotation, FieldInfo): if isinstance(fastapi_annotation, FieldInfo):

12
fastapi/routing.py

@ -454,9 +454,9 @@ class APIRoute(routing.Route):
methods = ["GET"] methods = ["GET"]
self.methods: Set[str] = {method.upper() for method in methods} self.methods: Set[str] = {method.upper() for method in methods}
if isinstance(generate_unique_id_function, DefaultPlaceholder): if isinstance(generate_unique_id_function, DefaultPlaceholder):
current_generate_unique_id: Callable[ current_generate_unique_id: Callable[[APIRoute], str] = (
["APIRoute"], str generate_unique_id_function.value
] = generate_unique_id_function.value )
else: else:
current_generate_unique_id = generate_unique_id_function current_generate_unique_id = generate_unique_id_function
self.unique_id = self.operation_id or current_generate_unique_id(self) self.unique_id = self.operation_id or current_generate_unique_id(self)
@ -482,9 +482,9 @@ class APIRoute(routing.Route):
# By being a new field, no inheritance will be passed as is. A new model # By being a new field, no inheritance will be passed as is. A new model
# will always be created. # will always be created.
# TODO: remove when deprecating Pydantic v1 # TODO: remove when deprecating Pydantic v1
self.secure_cloned_response_field: Optional[ self.secure_cloned_response_field: Optional[ModelField] = (
ModelField create_cloned_field(self.response_field)
] = create_cloned_field(self.response_field) )
else: else:
self.response_field = None # type: ignore self.response_field = None # type: ignore
self.secure_cloned_response_field = None self.secure_cloned_response_field = None

6
fastapi/utils.py

@ -34,9 +34,9 @@ if TYPE_CHECKING: # pragma: nocover
from .routing import APIRoute from .routing import APIRoute
# Cache for `create_cloned_field` # Cache for `create_cloned_field`
_CLONED_TYPES_CACHE: MutableMapping[ _CLONED_TYPES_CACHE: MutableMapping[Type[BaseModel], Type[BaseModel]] = (
Type[BaseModel], Type[BaseModel] WeakKeyDictionary()
] = WeakKeyDictionary() )
def is_body_allowed_for_status_code(status_code: Union[int, str, None]) -> bool: def is_body_allowed_for_status_code(status_code: Union[int, str, None]) -> bool:

2
requirements-tests.txt

@ -3,7 +3,7 @@
pytest >=7.1.3,<8.0.0 pytest >=7.1.3,<8.0.0
coverage[toml] >= 6.5.0,< 8.0 coverage[toml] >= 6.5.0,< 8.0
mypy ==1.8.0 mypy ==1.8.0
ruff ==0.2.0 ruff ==0.6.1
dirty-equals ==0.6.0 dirty-equals ==0.6.0
# TODO: once removing databases from tutorial, upgrade SQLAlchemy # TODO: once removing databases from tutorial, upgrade SQLAlchemy
# probably when including SQLModel # probably when including SQLModel

6
tests/test_dependency_contextmanager.py

@ -196,9 +196,9 @@ async def get_sync_context_b_bg(
tasks: BackgroundTasks, state: dict = Depends(context_b) tasks: BackgroundTasks, state: dict = Depends(context_b)
): ):
async def bg(state: dict): async def bg(state: dict):
state[ state["sync_bg"] = (
"sync_bg" f"sync_bg set - b: {state['context_b']} - a: {state['context_a']}"
] = f"sync_bg set - b: {state['context_b']} - a: {state['context_a']}" )
tasks.add_task(bg, state) tasks.add_task(bg, state)
return state return state

4
tests/test_inherited_custom_class.py

@ -36,7 +36,7 @@ def test_pydanticv2():
def return_fast_uuid(): def return_fast_uuid():
asyncpg_uuid = MyUuid("a10ff360-3b1e-4984-a26f-d3ab460bdb51") asyncpg_uuid = MyUuid("a10ff360-3b1e-4984-a26f-d3ab460bdb51")
assert isinstance(asyncpg_uuid, uuid.UUID) assert isinstance(asyncpg_uuid, uuid.UUID)
assert type(asyncpg_uuid) != uuid.UUID assert type(asyncpg_uuid) is not uuid.UUID
with pytest.raises(TypeError): with pytest.raises(TypeError):
vars(asyncpg_uuid) vars(asyncpg_uuid)
return {"fast_uuid": asyncpg_uuid} return {"fast_uuid": asyncpg_uuid}
@ -79,7 +79,7 @@ def test_pydanticv1():
def return_fast_uuid(): def return_fast_uuid():
asyncpg_uuid = MyUuid("a10ff360-3b1e-4984-a26f-d3ab460bdb51") asyncpg_uuid = MyUuid("a10ff360-3b1e-4984-a26f-d3ab460bdb51")
assert isinstance(asyncpg_uuid, uuid.UUID) assert isinstance(asyncpg_uuid, uuid.UUID)
assert type(asyncpg_uuid) != uuid.UUID assert type(asyncpg_uuid) is not uuid.UUID
with pytest.raises(TypeError): with pytest.raises(TypeError):
vars(asyncpg_uuid) vars(asyncpg_uuid)
return {"fast_uuid": asyncpg_uuid} return {"fast_uuid": asyncpg_uuid}

Loading…
Cancel
Save