@@ -124,8 +124,8 @@ def _get_indexed_data() -> (
124
124
125
125
CODICEFISCALE_RE : Pattern [str ] = re .compile (
126
126
r"^"
127
- r"(?P<surname >[a-z]{3})"
128
- r"(?P<name >[a-z]{3})"
127
+ r"(?P<lastname >[a-z]{3})"
128
+ r"(?P<firstname >[a-z]{3})"
129
129
r"(?P<birthdate>(?P<birthdate_year>[a-z\d]{2})(?P<birthdate_month>[abcdehlmprst]{1})(?P<birthdate_day>[a-z\d]{2}))" # noqa: B950, E501
130
130
r"(?P<birthplace>[a-z]{1}[a-z\d]{3})"
131
131
r"(?P<cin>[a-z]{1})$" ,
@@ -236,55 +236,55 @@ def _get_omocodes(code: str) -> list[str]:
236
236
return codes
237
237
238
238
239
- def encode_surname ( surname : str ) -> str :
239
+ def encode_lastname ( lastname : str ) -> str :
240
240
"""
241
- Encode surname to the code used in italian fiscal code.
241
+ Encode lastname to the code used in italian fiscal code.
242
242
243
- :param surname : The surname
244
- :type surname : string
243
+ :param lastname : The lastname
244
+ :type lastname : string
245
245
246
246
:returns: The code used in italian fiscal code
247
247
:rtype: string
248
248
"""
249
- surname_slug = slugify (surname )
250
- surname_consonants = _get_consonants (surname_slug )
251
- surname_vowels = _get_vowels (surname_slug )
252
- surname_code = _get_consonants_and_vowels (surname_consonants , surname_vowels )
253
- return surname_code
249
+ lastname_slug = slugify (lastname )
250
+ lastname_consonants = _get_consonants (lastname_slug )
251
+ lastname_vowels = _get_vowels (lastname_slug )
252
+ lastname_code = _get_consonants_and_vowels (lastname_consonants , lastname_vowels )
253
+ return lastname_code
254
254
255
255
256
- def encode_name ( name : str ) -> str :
256
+ def encode_firstname ( firstname : str ) -> str :
257
257
"""
258
- Encodes name to the code used in italian fiscal code.
258
+ Encodes firstname to the code used in italian fiscal code.
259
259
260
- :param name : The name
261
- :type name : string
260
+ :param firstname : The firstname
261
+ :type firstname : string
262
262
263
263
:returns: The code used in italian fiscal code
264
264
:rtype: string
265
265
"""
266
- name_slug = slugify (name )
267
- name_consonants = _get_consonants (name_slug )
266
+ firstname_slug = slugify (firstname )
267
+ firstname_consonants = _get_consonants (firstname_slug )
268
268
269
- if len (name_consonants ) > 3 :
270
- del name_consonants [1 ]
269
+ if len (firstname_consonants ) > 3 :
270
+ del firstname_consonants [1 ]
271
271
272
- name_vowels = _get_vowels (name_slug )
273
- name_code = _get_consonants_and_vowels (name_consonants , name_vowels )
274
- return name_code
272
+ firstname_vowels = _get_vowels (firstname_slug )
273
+ firstname_code = _get_consonants_and_vowels (firstname_consonants , firstname_vowels )
274
+ return firstname_code
275
275
276
276
277
277
def encode_birthdate (
278
278
birthdate : datetime | str | None ,
279
- sex : Literal ["m" , "M" , "f" , "F" ],
279
+ gender : Literal ["m" , "M" , "f" , "F" ],
280
280
) -> str :
281
281
"""
282
282
Encodes birthdate to the code used in italian fiscal code.
283
283
284
284
:param birthdate: The birthdate
285
285
:type birthdate: datetime or string
286
- :param sex : The sex , 'M' or 'F'
287
- :type sex : string
286
+ :param gender : The gender , 'M' or 'F'
287
+ :type gender : string
288
288
289
289
:returns: The code used in italian fiscal code
290
290
:rtype: string
@@ -295,15 +295,15 @@ def encode_birthdate(
295
295
if not date :
296
296
raise ValueError ("[codicefiscale] 'date' argument cant be None" )
297
297
298
- if not sex :
299
- raise ValueError ("[codicefiscale] 'sex ' argument cant be None" )
300
- sex_code = sex .upper ()
301
- if sex_code not in ("M" , "F" ):
302
- raise ValueError ("[codicefiscale] 'sex ' argument must be 'M' or 'F'" )
298
+ if not gender :
299
+ raise ValueError ("[codicefiscale] 'gender ' argument cant be None" )
300
+ gender_code = gender .upper ()
301
+ if gender_code not in ("M" , "F" ):
302
+ raise ValueError ("[codicefiscale] 'gender ' argument must be 'M' or 'F'" )
303
303
304
304
year_code = str (date .year )[2 :]
305
305
month_code = _MONTHS [date .month - 1 ]
306
- day_code = str (date .day + (40 if sex_code == "F" else 0 )).zfill (2 ).upper ()
306
+ day_code = str (date .day + (40 if gender_code == "F" else 0 )).zfill (2 ).upper ()
307
307
date_code = f"{ year_code } { month_code } { day_code } "
308
308
return date_code
309
309
@@ -372,21 +372,21 @@ def encode_cin(code: str) -> str:
372
372
373
373
374
374
def encode (
375
- surname : str ,
376
- name : str ,
377
- sex : Literal ["m" , "M" , "f" , "F" ],
375
+ lastname : str ,
376
+ firstname : str ,
377
+ gender : Literal ["m" , "M" , "f" , "F" ],
378
378
birthdate : datetime | str | None ,
379
379
birthplace : str ,
380
380
) -> str :
381
381
"""
382
382
Encodes the italian fiscal code.
383
383
384
- :param surname : The surname
385
- :type surname : string
386
- :param name : The name
387
- :type name : string
388
- :param sex : The sex , 'M' or 'F'
389
- :type sex : string
384
+ :param lastname : The lastname
385
+ :type lastname : string
386
+ :param firstname : The firstname
387
+ :type firstname : string
388
+ :param gender : The gender , 'M' or 'F'
389
+ :type gender : string
390
390
:param birthdate: The birthdate
391
391
:type birthdate: datetime or string
392
392
:param birthplace: The birthplace
@@ -396,11 +396,11 @@ def encode(
396
396
:rtype: string
397
397
"""
398
398
399
- surname_code = encode_surname ( surname )
400
- name_code = encode_name ( name )
401
- birthdate_code = encode_birthdate (birthdate , sex )
399
+ lastname_code = encode_lastname ( lastname )
400
+ firstname_code = encode_firstname ( firstname )
401
+ birthdate_code = encode_birthdate (birthdate , gender )
402
402
birthplace_code = encode_birthplace (birthplace , birthdate )
403
- code = f"{ surname_code } { name_code } { birthdate_code } { birthplace_code } "
403
+ code = f"{ lastname_code } { firstname_code } { birthdate_code } { birthplace_code } "
404
404
cin_code = encode_cin (code )
405
405
code = f"{ code } { cin_code } "
406
406
@@ -429,8 +429,8 @@ def decode_raw(code: str) -> dict[str, str]:
429
429
430
430
data = {
431
431
"code" : code ,
432
- "surname " : match ["surname " ],
433
- "name " : match ["name " ],
432
+ "lastname " : match ["lastname " ],
433
+ "firstname " : match ["firstname " ],
434
434
"birthdate" : match ["birthdate" ],
435
435
"birthdate_year" : match ["birthdate_year" ],
436
436
"birthdate_month" : match ["birthdate_month" ],
@@ -462,9 +462,9 @@ def decode(code: str) -> dict[str, Any]:
462
462
463
463
if birthdate_day > 40 :
464
464
birthdate_day -= 40
465
- sex = "F"
465
+ gender = "F"
466
466
else :
467
- sex = "M"
467
+ gender = "M"
468
468
469
469
current_year = datetime .now ().year
470
470
current_year_century_prefix = str (current_year )[0 :- 2 ]
@@ -496,7 +496,7 @@ def decode(code: str) -> dict[str, Any]:
496
496
data = {
497
497
"code" : code ,
498
498
"omocodes" : _get_omocodes (code ),
499
- "sex " : sex ,
499
+ "gender " : gender ,
500
500
"birthdate" : birthdate ,
501
501
"birthplace" : birthplace ,
502
502
"raw" : raw ,
0 commit comments