1010import os
1111import re
1212from pathlib import Path
13- from typing import Any , final , override
13+ from typing import Any , TextIO , final , override
1414
1515import jsonschema
1616import yaml
2222# https://yaml.org/spec/1.2.2/ requires unique keys
2323class UniqueKeyLoader (yaml .SafeLoader ):
2424 @override
25- def construct_mapping (self , node , deep = False ):
26- mapping = set ()
25+ def construct_mapping (self , node : Any , deep : bool = False ):
26+ mapping = set [ str ] ()
2727 for key_node , _ in node .value :
28- key = self .construct_object (key_node , deep = deep )
28+ key : str = str ( self .construct_object (key_node , deep = deep )) # pyright: ignore[reportUnknownMemberType, reportUnknownArgumentType]
2929 if key in mapping :
3030 raise yaml .MarkedYAMLError (f"Duplicate key { key !r} found." , key_node .start_mark )
3131 mapping .add (key )
@@ -47,10 +47,12 @@ def __init__(
4747 working_groups : list [str ] | None = None ,
4848 branch_protection : str | None = None ,
4949 ):
50- self .org_cfg = OrgGenerator ._validate_github_org_cfg (OrgGenerator ._yaml_load (static_org_cfg )) if static_org_cfg else {"orgs" : {}}
50+ self .org_cfg : dict [str , Any ] = (
51+ OrgGenerator ._validate_github_org_cfg (OrgGenerator ._yaml_load (static_org_cfg )) if static_org_cfg else {"orgs" : {}}
52+ )
5153 self .contributors = dict [str , set [str ]]()
52- self .working_groups = {}
53- self .branch_protection = (
54+ self .working_groups : dict [ str , Any ] = {}
55+ self .branch_protection : dict [ str , Any ] = (
5456 OrgGenerator ._validate_branch_protection (OrgGenerator ._yaml_load (branch_protection ))
5557 if branch_protection
5658 else {"branch-protection" : {"orgs" : {}}}
@@ -218,7 +220,7 @@ def write_branch_protection(self, path: str):
218220 return yaml .safe_dump (self .branch_protection , stream )
219221
220222 @staticmethod
221- def _yaml_load (stream ) -> dict [str , Any ]:
223+ def _yaml_load (stream : TextIO | str ) -> dict [str , Any ]:
222224 # safe_load + reject unique keys
223225 return yaml .load (stream , UniqueKeyLoader )
224226
@@ -247,7 +249,7 @@ def _extract_wg_config(wg_charter: str):
247249 return OrgGenerator ._validate_wg (OrgGenerator ._yaml_load (match .group (1 ))) if match else None
248250
249251 @staticmethod
250- def _empty_wg_config (name : str ):
252+ def _empty_wg_config (name : str ) -> dict [ str , Any ] :
251253 return {
252254 "name" : name ,
253255 "org" : OrgGenerator ._DEFAULT_ORG ,
@@ -258,7 +260,7 @@ def _empty_wg_config(name: str):
258260 }
259261
260262 @staticmethod
261- def _wg_github_users (wg ) -> set [str ]:
263+ def _wg_github_users (wg : dict [ str , Any ] ) -> set [str ]:
262264 users = {u ["github" ] for u in wg ["execution_leads" ]}
263265 users |= {u ["github" ] for u in wg ["technical_leads" ]}
264266 users |= {u ["github" ] for u in wg ["bots" ]}
@@ -271,7 +273,7 @@ def _wg_github_users(wg) -> set[str]:
271273 return users
272274
273275 @staticmethod
274- def _wg_github_users_leads (wg ) -> set [str ]:
276+ def _wg_github_users_leads (wg : dict [ str , Any ] ) -> set [str ]:
275277 users = {u ["github" ] for u in wg ["execution_leads" ]}
276278 users |= {u ["github" ] for u in wg ["technical_leads" ]}
277279 return users
@@ -297,7 +299,7 @@ def _wg_github_users_leads(wg) -> set[str]:
297299 }
298300
299301 @staticmethod
300- def _validate_contributors (contributors ) -> dict [str , Any ]:
302+ def _validate_contributors (contributors : dict [ str , Any ] ) -> dict [str , Any ]:
301303 jsonschema .validate (contributors , OrgGenerator ._CONTRIBUTORS_SCHEMA )
302304 # check that orgs are in _ORGS
303305 for org in contributors ["orgs" ]:
@@ -343,7 +345,7 @@ def _validate_contributors(contributors) -> dict[str, Any]:
343345 }
344346
345347 @staticmethod
346- def _validate_wg (wg ) -> dict [str , Any ]:
348+ def _validate_wg (wg : dict [ str , Any ] ) -> dict [str , Any ]:
347349 jsonschema .validate (wg , OrgGenerator ._WG_SCHEMA )
348350 # validate org and use 'cloudfoundry' if missing
349351 if "org" not in wg :
@@ -375,7 +377,7 @@ def _validate_wg(wg) -> dict[str, Any]:
375377 }
376378
377379 @staticmethod
378- def _validate_github_org_cfg (cfg ) :
380+ def _validate_github_org_cfg (cfg : dict [ str , Any ]) -> dict [ str , Any ] :
379381 jsonschema .validate (cfg , OrgGenerator ._GITHUB_ORG_CFG_SCHEMA )
380382 # check that orgs are in _ORGS
381383 for org in cfg ["orgs" ]:
@@ -410,7 +412,7 @@ def _validate_github_org_cfg(cfg):
410412 }
411413
412414 @staticmethod
413- def _validate_branch_protection (cfg ) :
415+ def _validate_branch_protection (cfg : dict [ str , Any ]) -> dict [ str , Any ] :
414416 jsonschema .validate (cfg , OrgGenerator ._BRANCH_PROTECTION_SCHEMA )
415417 # check that orgs are in _ORGS
416418 for org in cfg ["branch-protection" ]["orgs" ]:
@@ -420,7 +422,7 @@ def _validate_branch_protection(cfg):
420422
421423 # https://github.com/cloudfoundry/community/blob/main/toc/rfc/rfc-0005-github-teams-and-access.md
422424 @staticmethod
423- def _generate_wg_teams (wg ) -> tuple [str , dict [str , Any ]]:
425+ def _generate_wg_teams (wg : dict [ str , Any ] ) -> tuple [str , dict [str , Any ]]:
424426 org = wg ["org" ]
425427 org_prefix = org + "/"
426428 org_prefix_len = len (org_prefix )
@@ -489,7 +491,7 @@ def _generate_wg_teams(wg) -> tuple[str, dict[str, Any]]:
489491 return (name , team )
490492
491493 @staticmethod
492- def _generate_toc_team (wg ) -> tuple [str , dict [str , Any ]]:
494+ def _generate_toc_team (wg : dict [ str , Any ] ) -> tuple [str , dict [str , Any ]]:
493495 org = wg ["org" ]
494496 org_prefix = org + "/"
495497 org_prefix_len = len (org_prefix )
@@ -504,7 +506,7 @@ def _generate_toc_team(wg) -> tuple[str, dict[str, Any]]:
504506 return ("toc" , team )
505507
506508 @staticmethod
507- def _generate_wg_leads_team (wgs : list [Any ]) -> tuple [str , dict [str , Any ]]:
509+ def _generate_wg_leads_team (wgs : list [dict [ str , Any ] ]) -> tuple [str , dict [str , Any ]]:
508510 members = {u for wg in wgs for u in OrgGenerator ._wg_github_users_leads (wg )}
509511 team = {
510512 "description" : "Technical and Execution Leads for all WGs" ,
@@ -515,7 +517,7 @@ def _generate_wg_leads_team(wgs: list[Any]) -> tuple[str, dict[str, Any]]:
515517
516518 # https://github.com/cloudfoundry/community/blob/main/toc/rfc/rfc-0015-branch-protection.md
517519 # returns hash with branch protection rules per repo
518- def _generate_wg_branch_protection (self , wg ) -> dict [str , Any ]:
520+ def _generate_wg_branch_protection (self , wg : dict [ str , Any ] ) -> dict [str , Any ]:
519521 org = wg ["org" ]
520522 org_prefix = org + "/"
521523 org_prefix_len = len (org_prefix )
0 commit comments