Skip to content

Commit

Permalink
Fix typing errors
Browse files Browse the repository at this point in the history
  • Loading branch information
hongquan committed Jan 4, 2025
1 parent 1a21d47 commit 09dce05
Show file tree
Hide file tree
Showing 7 changed files with 20,879 additions and 22,005 deletions.
2 changes: 1 addition & 1 deletion dev/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def configure_logging(verbose):
# Beautify code using Ruff and save to file
def format_code(content: str, outfile: Path) -> bool:
cmd = ('ruff', 'format', '-', '--stdin-filename', 'code.py')
with outfile.open() as f:
with outfile.open('w') as f:
p = subprocess.run(cmd, input=content, text=True, stdout=f)
return p.returncode == 0

Expand Down
2 changes: 1 addition & 1 deletion dev/_enum_ward_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ class WardDEnum(metaclass=FastEnum):
It helps developer have more idea what Ward he is selecting.
'''
DA_UY_NO_478 = WardEnum.W_478.value
DA_UY_NO_478 = WardEnum.W_478
10 changes: 4 additions & 6 deletions dev/divisions.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def abbrev(self):
class Province(BaseRegion):
# Redefine here, or the validator won't run
division_type: VietNamDivisionType = VietNamDivisionType.TINH
phone_code: str | None = None
phone_code: int | None = None
# Actual districts are saved here for fast searching
indexed_districts: dict[str, District] = Field(exclude=True, default_factory=dict)

Expand Down Expand Up @@ -283,7 +283,7 @@ def convert_to_nested(
if matched_phone_code is None:
logger.error('Could not find phone code for {}', province.name)
else:
province.phone_code = str(matched_phone_code.code)
province.phone_code = matched_phone_code.code
district = District(name=w.district_name, code=w.district_code, codename=w.district_codename)
province.indexed_districts[str(w.district_code)] = district
if w.ward_code and w.ward_name:
Expand Down Expand Up @@ -400,15 +400,13 @@ def ward_enum_member(ward: Ward, district: District, province: Province):
def ward_descriptive_enum_member(ward: Ward, district: District, province: Province):
"""
Generate AST tree for line of code equivalent to:
QN_TAN_BINH_6904 = WardEnum.W_6904.value
QN_TAN_BINH_6904 = WardEnum.W_6904
where:
- QN means "Tỉnh Quảng Ninh"
- 6904 is the numeric code of "Xã Tân Bình"
"""
ward_id = f'{province.abbrev}_{ward.short_codename}_{ward.code}'.upper()
right_hand_side = ast.Attribute(
value=ast.Attribute(value=ast.Name(id='WardEnum'), attr=f'W_{ward.code}'), attr='value'
)
right_hand_side = ast.Attribute(value=ast.Name(id='WardEnum'), attr=f'W_{ward.code}')
node = ast.Assign(targets=[ast.Name(id=ward_id)], value=right_hand_side)
return node

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ disable_error_code = 'prop-decorator'

[[tool.mypy.overrides]]
module = [
"astor.*",
"fast_enum",
"logbook.*"
]
ignore_missing_imports = true
Expand Down
6 changes: 3 additions & 3 deletions vietnam_provinces/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Ward:
codename: str
district_code: int

def __eq__(self, other: 'Ward'):
def __eq__(self, other: object):
if not isinstance(other, Ward):
return False
return other.code == self.code
Expand All @@ -45,7 +45,7 @@ class District:
codename: str
province_code: int

def __eq__(self, other: 'District'):
def __eq__(self, other: object):
if not isinstance(other, District):
return False
return other.code == self.code
Expand All @@ -59,7 +59,7 @@ class Province:
codename: str
phone_code: int

def __eq__(self, other: 'Province'):
def __eq__(self, other: object):
if not isinstance(other, Province):
return False
return other.code == self.code
1,562 changes: 767 additions & 795 deletions vietnam_provinces/enums/districts.py

Large diffs are not rendered by default.

41,300 changes: 20,102 additions & 21,198 deletions vietnam_provinces/enums/wards.py

Large diffs are not rendered by default.

0 comments on commit 09dce05

Please sign in to comment.