Repository: lk-geimfari/mimesis

Issue:
Add UUID objects support for uuid()
- [x] Add parameter `as_object` 


Discussion:

Resolving patch:
diff --git a/mimesis/__init__.py b/mimesis/__init__.py
--- a/mimesis/__init__.py
+++ b/mimesis/__init__.py
@@ -72,7 +72,7 @@
     '__license__',
 ]
 
-__version__ = '4.1.0'
+__version__ = '4.1.1'
 __title__ = 'mimesis'
 __description__ = 'Mimesis: fake data generator.'
 __url__ = 'https://github.com/lk-geimfari/mimesis'
diff --git a/mimesis/providers/cryptographic.py b/mimesis/providers/cryptographic.py
--- a/mimesis/providers/cryptographic.py
+++ b/mimesis/providers/cryptographic.py
@@ -5,7 +5,7 @@
 import hashlib
 import secrets
 from typing import Optional, Union
-from uuid import UUID
+from uuid import UUID, uuid4
 
 from mimesis.enums import Algorithm
 from mimesis.providers.base import BaseProvider
@@ -30,25 +30,23 @@ class Meta:
 
         name = 'cryptographic'
 
-    def uuid(self, version: int = None,
-             as_object: bool = False) -> Union[UUID, str]:
-        """Generate random UUID.
+    @staticmethod
+    def uuid(as_object: bool = False) -> Union[UUID, str]:
+        """Generate random UUID4.
 
         This method returns string by default,
-        but yoy can make it return uuid.UUID object using
+        but you can make it return uuid.UUID object using
         parameter **as_object**
 
-        :param as_object: Returns uuid.UUID object instead of string.
-        :param version: UUID version.
+        :param as_object: Returns uuid.UUID.
         :return: UUID.
         """
-        bits = self.random.getrandbits(128)
-        uuid_obj = UUID(int=bits, version=version)
+        _uuid = uuid4()
 
         if not as_object:
-            return str(uuid_obj)
+            return str(_uuid)
 
-        return uuid_obj
+        return _uuid
 
     def hash(self, algorithm: Algorithm = None) -> str:  # noqa: A003
         """Generate random hash.
@@ -64,7 +62,7 @@ def hash(self, algorithm: Algorithm = None) -> str:  # noqa: A003
 
         if hasattr(hashlib, key):
             fn = getattr(hashlib, key)
-            return fn(self.uuid().encode()).hexdigest()
+            return fn(self.uuid().encode()).hexdigest()  # type: ignore
 
     @staticmethod
     def token_bytes(entropy: int = 32) -> bytes:


Test patch:
diff --git a/tests/test_providers/test_cryptographic.py b/tests/test_providers/test_cryptographic.py
--- a/tests/test_providers/test_cryptographic.py
+++ b/tests/test_providers/test_cryptographic.py
@@ -20,26 +20,17 @@ def test_str(self, crypto):
         assert re.match(patterns.PROVIDER_STR_REGEX, str(crypto))
 
     @pytest.mark.parametrize(
-        'version, as_object', [
-            (0, False),
-            (1, True),
-            (2, False),
-            (3, True),
-            (4, True),
-            (5, False),
-            (6, False),
+        'as_object', [
+            True,
+            False,
         ],
     )
-    def test_uuid(self, crypto, version, as_object):
-        if 1 <= version <= 5:
-            uuid_result = crypto.uuid(version, as_object=as_object)
-            if as_object:
-                assert isinstance(uuid_result, uuid.UUID)
-            else:
-                assert re.match(patterns.UUID_REGEX, crypto.uuid(version))
+    def test_uuid(self, crypto, as_object):
+        uuid_result = crypto.uuid(as_object=as_object)
+        if as_object:
+            assert isinstance(uuid_result, uuid.UUID)
         else:
-            with pytest.raises(ValueError):
-                re.match(patterns.UUID_REGEX, crypto.uuid(version))
+            assert re.match(patterns.UUID_REGEX, crypto.uuid(as_object))
 
     @pytest.mark.parametrize(
         'algorithm, length', [
@@ -106,11 +97,11 @@ def c2(self, seed):
         return Cryptographic(seed=seed)
 
     def test_uuid(self, c1, c2):
-        assert c1.uuid() == c2.uuid()
+        assert c1.uuid() != c2.uuid()
 
     def test_hash(self, c1, c2):
-        assert c1.hash() == c2.hash()
-        assert c1.hash(algorithm=Algorithm.SHA512) == \
+        assert c1.hash() != c2.hash()
+        assert c1.hash(algorithm=Algorithm.SHA512) != \
                c2.hash(algorithm=Algorithm.SHA512)
 
     def test_mnemonic_phrase(self, c1, c2):
diff --git a/tests/test_providers/test_generic.py b/tests/test_providers/test_generic.py
--- a/tests/test_providers/test_generic.py
+++ b/tests/test_providers/test_generic.py
@@ -131,8 +131,8 @@ def test_generic_code(self, g1, g2):
         assert g1.code.issn() == g2.code.issn()
 
     def test_generic_cryptographic(self, g1, g2):
-        assert g1.cryptographic.uuid() == g2.cryptographic.uuid()
-        assert g1.cryptographic.hash() == g2.cryptographic.hash()
+        assert g1.cryptographic.uuid() != g2.cryptographic.uuid()
+        assert g1.cryptographic.hash() != g2.cryptographic.hash()
 
     def test_generic_datetime(self, g1, g2):
         assert g1.datetime.week_date() == g2.datetime.week_date()