Skip to content

Commit 2a066a2

Browse files
committed
Bump ruff to v0.5.0 and pyright to v1.1.369 (#9801)
1 parent 11b8340 commit 2a066a2

7 files changed

Lines changed: 110 additions & 114 deletions

File tree

.github/actions/people/people.py

Lines changed: 74 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
This logic is inspired by that of @tiangolo's
44
[FastAPI people script](https://github.com/tiangolo/fastapi/blob/master/.github/actions/people/app/main.py).
55
"""
6-
import requests
6+
77
import logging
88
import subprocess
99
import sys
@@ -12,12 +12,14 @@
1212
from pathlib import Path
1313
from typing import Any, Container, Dict, List, Set, Union
1414

15+
import requests
1516
import yaml
1617
from github import Github
17-
from pydantic import BaseModel, SecretStr
1818
from pydantic_settings import BaseSettings
1919

20-
github_graphql_url = "https://api.github.com/graphql"
20+
from pydantic import BaseModel, SecretStr
21+
22+
github_graphql_url = 'https://api.github.com/graphql'
2123

2224
discussions_query = """
2325
query Q($after: String) {
@@ -287,7 +289,7 @@ class PRsResponse(BaseModel):
287289

288290
class Settings(BaseSettings):
289291
input_token: SecretStr
290-
github_repository: str = "pydantic/pydantic"
292+
github_repository: str = 'pydantic/pydantic'
291293
request_timeout: int = 30
292294

293295

@@ -297,24 +299,22 @@ def get_graphql_response(
297299
query: str,
298300
after: Union[str, None] = None,
299301
) -> Dict[str, Any]:
300-
headers = {"Authorization": f"token {settings.input_token.get_secret_value()}"}
301-
variables = {"after": after}
302+
headers = {'Authorization': f'token {settings.input_token.get_secret_value()}'}
303+
variables = {'after': after}
302304
response = requests.post(
303305
github_graphql_url,
304306
headers=headers,
305307
timeout=settings.request_timeout,
306-
json={"query": query, "variables": variables, "operationName": "Q"},
308+
json={'query': query, 'variables': variables, 'operationName': 'Q'},
307309
)
308310
if response.status_code != 200:
309-
logging.error(
310-
f"Response was not 200, after: {after}"
311-
)
311+
logging.error(f'Response was not 200, after: {after}')
312312
logging.error(response.text)
313313
raise RuntimeError(response.text)
314314
data = response.json()
315-
if "errors" in data:
316-
logging.error(f"Errors in response, after: {after}")
317-
logging.error(data["errors"])
315+
if 'errors' in data:
316+
logging.error(f'Errors in response, after: {after}')
317+
logging.error(data['errors'])
318318
logging.error(response.text)
319319
raise RuntimeError(response.text)
320320
return data
@@ -390,9 +390,7 @@ def get_discussions_experts(settings: Settings):
390390
for discussion_edge in discussion_edges:
391391
discussion_nodes.append(discussion_edge.node)
392392
last_edge = discussion_edges[-1]
393-
discussion_edges = get_graphql_question_discussion_edges(
394-
settings=settings, after=last_edge.cursor
395-
)
393+
discussion_edges = get_graphql_question_discussion_edges(settings=settings, after=last_edge.cursor)
396394

397395
commentors = Counter()
398396
last_month_commentors = Counter()
@@ -483,7 +481,7 @@ def get_contributors(settings: Settings):
483481
pr_reviewers.add(review.author.login)
484482
for reviewer in pr_reviewers:
485483
reviewers[reviewer] += 1
486-
if pr.state == "MERGED" and pr.author:
484+
if pr.state == 'MERGED' and pr.author:
487485
contributors[pr.author.login] += 1
488486
return contributors, commentors, reviewers, authors
489487

@@ -503,40 +501,45 @@ def get_top_users(
503501
author = authors[commentor]
504502
users.append(
505503
{
506-
"login": commentor,
507-
"count": count,
508-
"avatarUrl": author.avatarUrl,
509-
"url": author.url,
504+
'login': commentor,
505+
'count': count,
506+
'avatarUrl': author.avatarUrl,
507+
'url': author.url,
510508
}
511509
)
512510
return users
513511

514512

515-
if __name__ == "__main__":
513+
if __name__ == '__main__':
516514
logging.basicConfig(level=logging.INFO)
517515
settings = Settings()
518-
logging.info(f"Using config: {settings.model_dump_json()}")
516+
logging.info(f'Using config: {settings.model_dump_json()}')
519517
g = Github(settings.input_token.get_secret_value())
520518
repo = g.get_repo(settings.github_repository)
521-
question_commentors, question_last_month_commentors, question_authors = get_experts(
522-
settings=settings
523-
)
524-
contributors, pr_commentors, reviewers, pr_authors = get_contributors(
525-
settings=settings
526-
)
519+
question_commentors, question_last_month_commentors, question_authors = get_experts(settings=settings)
520+
contributors, pr_commentors, reviewers, pr_authors = get_contributors(settings=settings)
527521
authors = {**question_authors, **pr_authors}
528-
maintainers_logins = {'samuelcolvin', 'adriangb', 'dmontagu', 'hramezani', 'Kludex', 'davidhewitt', 'sydney-runkle', 'alexmojaki'}
529-
bot_names = {"codecov", "github-actions", "pre-commit-ci", "dependabot"}
522+
maintainers_logins = {
523+
'samuelcolvin',
524+
'adriangb',
525+
'dmontagu',
526+
'hramezani',
527+
'Kludex',
528+
'davidhewitt',
529+
'sydney-runkle',
530+
'alexmojaki',
531+
}
532+
bot_names = {'codecov', 'github-actions', 'pre-commit-ci', 'dependabot'}
530533
maintainers = []
531534
for login in maintainers_logins:
532535
user = authors[login]
533536
maintainers.append(
534537
{
535-
"login": login,
536-
"answers": question_commentors[login],
537-
"prs": contributors[login],
538-
"avatarUrl": user.avatarUrl,
539-
"url": user.url,
538+
'login': login,
539+
'answers': question_commentors[login],
540+
'prs': contributors[login],
541+
'avatarUrl': user.avatarUrl,
542+
'url': user.url,
540543
}
541544
)
542545

@@ -572,53 +575,45 @@ def get_top_users(
572575

573576
extra_experts = [
574577
{
575-
"login": "ybressler",
576-
"count": None,
577-
"avatarUrl": "https://avatars.githubusercontent.com/u/40807730?v=4",
578-
"url": "https://github.com/ybressler"
578+
'login': 'ybressler',
579+
'count': None,
580+
'avatarUrl': 'https://avatars.githubusercontent.com/u/40807730?v=4',
581+
'url': 'https://github.com/ybressler',
579582
},
580583
]
581-
expert_logins = {e["login"] for e in experts}
582-
experts.extend([expert for expert in extra_experts if expert["login"] not in expert_logins])
584+
expert_logins = {e['login'] for e in experts}
585+
experts.extend([expert for expert in extra_experts if expert['login'] not in expert_logins])
583586

584587
people = {
585-
"maintainers": maintainers,
586-
"experts": experts,
587-
"last_month_active": last_month_active,
588-
"top_contributors": top_contributors,
589-
"top_reviewers": top_reviewers,
588+
'maintainers': maintainers,
589+
'experts': experts,
590+
'last_month_active': last_month_active,
591+
'top_contributors': top_contributors,
592+
'top_reviewers': top_reviewers,
590593
}
591-
people_path = Path("./docs/plugins/people.yml")
592-
people_old_content = people_path.read_text(encoding="utf-8")
593-
new_people_content = yaml.dump(
594-
people, sort_keys=False, width=200, allow_unicode=True
595-
)
596-
if (
597-
people_old_content == new_people_content
598-
):
594+
people_path = Path('./docs/plugins/people.yml')
595+
people_old_content = people_path.read_text(encoding='utf-8')
596+
new_people_content = yaml.dump(people, sort_keys=False, width=200, allow_unicode=True)
597+
if people_old_content == new_people_content:
599598
logging.info("The Pydantic People data hasn't changed, finishing.")
600599
sys.exit(0)
601-
people_path.write_text(new_people_content, encoding="utf-8")
602-
603-
logging.info("Setting up GitHub Actions git user")
604-
subprocess.run(["git", "config", "user.name", "github-actions"], check=True)
605-
subprocess.run(
606-
["git", "config", "user.email", "github-actions@github.com"], check=True
607-
)
608-
609-
branch_name = "pydantic-people-update"
610-
logging.info(f"Creating a new branch {branch_name}")
611-
subprocess.run(["git", "checkout", "-b", branch_name], check=True)
612-
logging.info("Adding updated file")
613-
subprocess.run(
614-
["git", "add", str(people_path)], check=True
615-
)
616-
logging.info("Committing updated file")
617-
message = "👥 Update Pydantic People"
618-
result = subprocess.run(["git", "commit", "-m", message], check=True)
619-
logging.info("Pushing branch")
620-
subprocess.run(["git", "push", "origin", branch_name], check=True)
621-
logging.info("Creating PR")
622-
pr = repo.create_pull(title=message, body=message, base="main", head=branch_name)
623-
logging.info(f"Created PR: {pr.number}")
624-
logging.info("Finished")
600+
people_path.write_text(new_people_content, encoding='utf-8')
601+
602+
logging.info('Setting up GitHub Actions git user')
603+
subprocess.run(['git', 'config', 'user.name', 'github-actions'], check=True)
604+
subprocess.run(['git', 'config', 'user.email', 'github-actions@github.com'], check=True)
605+
606+
branch_name = 'pydantic-people-update'
607+
logging.info(f'Creating a new branch {branch_name}')
608+
subprocess.run(['git', 'checkout', '-b', branch_name], check=True)
609+
logging.info('Adding updated file')
610+
subprocess.run(['git', 'add', str(people_path)], check=True)
611+
logging.info('Committing updated file')
612+
message = '👥 Update Pydantic People'
613+
result = subprocess.run(['git', 'commit', '-m', message], check=True)
614+
logging.info('Pushing branch')
615+
subprocess.run(['git', 'push', 'origin', branch_name], check=True)
616+
logging.info('Creating PR')
617+
pr = repo.create_pull(title=message, body=message, base='main', head=branch_name)
618+
logging.info(f'Created PR: {pr.number}')
619+
logging.info('Finished')

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ jobs:
275275
node-version: '18'
276276

277277
- name: install pyright
278-
run: npm install -g pyright@1.1.367 # try to keep this in sync with .pre-commit-config.yaml
278+
run: npm install -g pyright@1.1.369 # try to keep this in sync with .pre-commit-config.yaml
279279

280280
- name: run pyright tests
281281
run: make test-pyright

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,4 @@ repos:
3636
types: [python]
3737
language: node
3838
pass_filenames: false
39-
additional_dependencies: ["pyright@1.1.367"] # try to keep this in sync with .github/workflows/ci.yml
39+
additional_dependencies: ["pyright@1.1.369"] # try to keep this in sync with .github/workflows/ci.yml

pdm.lock

Lines changed: 26 additions & 25 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pydantic/_internal/_generate_schema.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -827,7 +827,7 @@ def match_type(self, obj: Any) -> core_schema.CoreSchema: # noqa: C901
827827
return self._dict_schema(obj, *self._get_first_two_args_or_any(obj))
828828
elif isinstance(obj, TypeAliasType):
829829
return self._type_alias_type_schema(obj)
830-
elif obj == type:
830+
elif obj is type:
831831
return self._type_schema()
832832
elif _typing_extra.is_callable_type(obj):
833833
return core_schema.callable_schema()
@@ -1538,11 +1538,11 @@ def _pattern_schema(self, pattern_type: Any) -> core_schema.CoreSchema:
15381538
pattern_type,
15391539
required=True,
15401540
)[0]
1541-
if param == str:
1541+
if param is str:
15421542
return core_schema.no_info_plain_validator_function(
15431543
_validators.pattern_str_validator, serialization=ser, metadata=metadata
15441544
)
1545-
elif param == bytes:
1545+
elif param is bytes:
15461546
return core_schema.no_info_plain_validator_function(
15471547
_validators.pattern_bytes_validator, serialization=ser, metadata=metadata
15481548
)

pydantic/_internal/_validators.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,18 @@ def sequence_validator(
3737
# Additionally, we should be able to remove one of either this validator or the
3838
# SequenceValidator in _std_types_schema.py (preferably this one, while porting over some logic).
3939
# Effectively, a refactor for sequence validation is needed.
40-
if value_type == tuple:
40+
if value_type is tuple:
4141
input_value = list(input_value)
4242

4343
v_list = validator(input_value)
4444

4545
# the rest of the logic is just re-creating the original type from `v_list`
46-
if value_type == list:
46+
if value_type is list:
4747
return v_list
4848
elif issubclass(value_type, range):
4949
# return the list as we probably can't re-create the range
5050
return v_list
51-
elif value_type == tuple:
51+
elif value_type is tuple:
5252
return tuple(v_list)
5353
else:
5454
# best guess at how to re-create the original type, more custom construction logic might be required

0 commit comments

Comments
 (0)