-
Notifications
You must be signed in to change notification settings - Fork 330
-
Notifications
You must be signed in to change notification settings - Fork 330
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Seed does not work for some providers #325
Comments
Thanks for the quick response, @lk-geimfari 😄 I can try moving |
@duckyou You know, it's better to move it to |
@duckyou after that, we can just call |
@duckyou If you don't want to do it, I can do it by myself, but if you want work on it, then, please, create new PR, because old is really hard to read and review 😄 . Thanks! |
@lk-geimfari Hmm... You goddamn right! I do this ;) |
@duckyou Thank you! |
Lines 6 to 12 in af9c877
Method get_random_item also affected 😟 |
@duckyou We will not change it, because it's not really about |
@lk-geimfari Issue explain: >>> from mimesis import Address
>>> from mimesis.enums import CountryCode
>>> a = Address(seed=42)
>>> a.country_iso_code(fmt=CountryCode.ISO3)
'NIC'
>>> a.country_iso_code(fmt=CountryCode.ISO3)
'BRN'
>>> a.country_iso_code(fmt=CountryCode.ISO3)
'ARM'
>>> a = Address(seed=42)
>>> a.country_iso_code(fmt=CountryCode.ISO3)
'NIC'
>>> a.country_iso_code(fmt=CountryCode.ISO3)
'BRN'
>>> a.country_iso_code(fmt=CountryCode.ISO3)
'ARM'
... This worked because we set format directly ...
>>> a = Address(seed=42)
>>> a.country_iso_code()
'558'
>>> a.country_iso_code()
'096'
>>> a.country_iso_code()
'ARM'
>>> a = Address(seed=42)
>>> a.country_iso_code()
'NIC'
>>> a.country_iso_code()
'096'
>>> a.country_iso_code()
'051' its happen beause: mimesis/mimesis/providers/address.py Lines 147 to 148 in af9c877
|
@duckyou Skip this for now. I'll think about it later. Our priority for a right now is |
Fixed. Now we should think about how should we test providers with seed. |
@lk-geimfari good job! 😸 |
@duckyou It's okay. Unfortunately, not yet. We have a small community, so usually, we discuss everything here, although it would be great, of course, to have a place where we could discuss everything. We can create repository |
@duckyou I have invited you to @mimesis-lab. Accept the invitation if you're interested. Thanks! |
@lk-geimfari im in! ^^ |
@lk-geimfari don't forget about #325 (comment) ? Heres two problems: Ok.. firstly how to get random enum with seed? Lines 11 to 12 in 217e5fa
aka we can just do this self.random.choice(list(CountryCode)) without mentioned method
and if we create this simple hack in def __getitem__(self, index):
if isinstance(index, int):
return list(self._member_map_)[index]
return super().__getitem__(index) we can do now |
@duckyou Also we can add the method def get_item(self, enum: Optional[Any] = None):
return self.choice(list(self)) What do you think? In my opinion, it will be easier. |
In this case, we should move |
@lk-geimfari key = self.random.get_enum_item(fmt, CountryCode) Something like this: def get_enum_item(self, enum: Any, item: Any = None) -> Any:
if item:
raise NonEnumerableError(enum) if item not in enum
return item
return self.choice(list(enum)) |
@duckyou Stop stop. Seems like the solution which I suggested above will not work, it seems. Do you suggest something like this? class Enum(enum.Enum):
def __getitem__(self, index):
if isinstance(index, int):
return list(self._member_map_)[index]
return super().__getitem__(index)
class PortRange(Enum):
ALL = (1, 65535)
WELL_KNOWN = (1, 1023)
EPHEMERAL = (49152, 65535)
REGISTERED = (1024, 49151) |
@duckyou The problem that we need to handle different cases. For example, sometimes we need the value of the enum, but sometimes we need item of enum object, i.e |
Oh... here is: class MimEnumMeta(EnumMeta):
def __getitem__(self, index):
if isinstance(index, int):
return list(self)[index]
return super().__getitem__(index)
class PortRange(Enum, metaclass=MimEnumMeta):
ALL = (1, 65535)
WELL_KNOWN = (1, 1023)
EPHEMERAL = (49152, 65535)
REGISTERED = (1024, 49151)
... Now: >>> from mimesis import enums
>>> import random
>>> pr = enums.PortRange
>>> pr
<enum 'PortRange'>
>>> pr['ALL']
<PortRange.ALL: (1, 65535)>
>>> pr.ALL
<PortRange.ALL: (1, 65535)>
>>> pr[0]
<PortRange.ALL: (1, 65535)>
>>> random.choice(pr)
<PortRange.REGISTERED: (1024, 49151)>
>>> random.choice(pr) in enums.PortRange
True
>>> random.choice(pr).value
(1, 1023)
>>> random.choice(pr).name
'EPHEMERAL' |
@duckyou I'll wait for your PR. Keep in mind that we have |
@lk-geimfari Can i also move |
@duckyou If we do it, then tests will fail because |
@lk-geimfari I see here several solutions:
|
@duckyou Let's will weigh the pros and cons of all solutions. |
@duckyou We need to take a decision that will allow us to make the minimum number of changes. |
@duckyou I have found a new problem: And this is only the tip of the iceberg I think. Now I'm tired and can not figure out why the data is changing for fixed seed, sorry. I have created PR where you can see changes: #332 |
Seems like |
Description:
Seems like @duckyou have found a bug in our code and
seed
is really does not work sometime and we should fix it.Reason:
It's happening because we use
custom_code
which use anotherrandom
object.Decision:
We should move utils which use
random
tohelpers.Random
The text was updated successfully, but these errors were encountered: