lk-geimfari / mimesis

Mimesis is a robust data generator for Python that can produce a wide range of fake data in multiple languages.
https://mimesis.name
MIT License
4.39k stars 330 forks source link

Personal.identifier returns the same value #279

Closed faheel closed 6 years ago

faheel commented 6 years ago

The following code:

from mimesis import Personal

person = Personal('en')

for _ in range(10):
    print(person.identifier(mask='##-@@@-####'))

always prints the same identifiers. Sample output:

28-TKX-4789
28-TKX-4789
28-TKX-4789
28-TKX-4789
28-TKX-4789
28-TKX-4789
28-TKX-4789
28-TKX-4789
28-TKX-4789
28-TKX-4789

Whereas using Code.custom_code works fine:

from mimesis import Code

code = Code('en')

for _ in range(10):
    print(code.custom_code(mask='##-@@@-####'))

Sample output:

842-RSM-5674
414-HKU-3804
580-DHM-0816
822-IWU-2176
467-NWU-5089
535-KVB-3492
319-VMF-7333
665-YEZ-4076
915-ZXQ-5384
861-BOB-4256

I think this is because Personal.identifier(...) returns Code(self.locale).custom_code(...), each time creating a new temporary Code object, rather than storing a Code object in it, code = Code(self.locale), and calling code.custom_code(...) for it.

faheel commented 6 years ago

I'll further test and send a PR if the problem is what I suspect it to be.

lk-geimfari commented 6 years ago

@faheel Seems like you're right. I'll wait for your PR. Thanks!

lk-geimfari commented 6 years ago

@faheel I think that we need to move custom_code() to utils.py as function, becuase it is use too often. And the creation of the Code() objects each time is inexpedient.

lk-geimfari commented 6 years ago

@faheel So, i have fixed this issue in branch type-hinting.