Skip to content

Commit

Permalink
Fix code snippets in docs
Browse files Browse the repository at this point in the history
  • Loading branch information
lk-geimfari committed Aug 20, 2023
1 parent cde6395 commit 033c399
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 50 deletions.
4 changes: 4 additions & 0 deletions docs/_static/css/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -285,4 +285,8 @@ div.highlight pre, table.highlighttable pre {
background: transparent !important;
text-decoration: none !important;
}

.highlight .fm {
color: #4fb8ff !important;
}
}
6 changes: 3 additions & 3 deletions docs/about.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ The key features are:
- **Easy**: Mimesis offers a simple design and clear documentation for easy data generation.
- **Multilingual**: Mimesis can generate data in multiple languages.
- **Performance**: Widely recognized as the fastest data generator among Python solutions.
- **Data variety**: Mimesis includes various data providers for names, addresses, phone numbers, email addresses, dates, times, and more, catering to different use cases.
- **Country-specific data providers**: Mimesis supports country-specific data providers for generating region-specific data.
- **Extensibility**: Developers can extend Mimesis by creating and integrating their own data providers.
- **Data variety**: Mimesis includes various data providers for names, addresses, phone numbers, email addresses, dates, and more, catering to different use cases.
- **Country-specific data**: Mimesis supports country-specific data providers for generating region-specific data.
- **Extensibility**: You can extend Mimesis by creating and integrating your own data providers.
- **Generic data provider**: Mimesis provides a single object that grants easy access to all available data providers in the library.
- **Zero hard dependencies**: Mimesis has no hard dependencies, eliminating the need for additional third-party libraries.
- **Schema-based generators**: Mimesis offers schema-based data generators to effortlessly produce data of any complexity.
Expand Down
25 changes: 12 additions & 13 deletions docs/providers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ irrespective of the selected locale.

By examining the example provided (the code won't execute), you can see this for yourself:

.. code:: python
.. code-block:: python
from mimesis import Person
from mimesis.locales import Locale
Expand All @@ -119,7 +119,7 @@ class structure for all languages and their objects.

Here’s how it works:

.. code:: python
.. code-block:: python
from mimesis import Generic
from mimesis.locales import Locale
Expand All @@ -132,7 +132,7 @@ Here’s how it works:
To modify the default name of the built-in provider, you can change the value of the attribute **Meta.name**:

.. code:: python
.. code-block:: python
BrazilSpecProvider.Meta.name = 'brasil'
generic.add_provider(BrazilSpecProvider)
Expand All @@ -142,7 +142,7 @@ To modify the default name of the built-in provider, you can change the value of
Or just inherit the class and override the value of attribute *name*
of class *Meta* of the provider (in our case this is :class:`~mimesis.builtins.BrazilSpecProvider`) :

.. code:: python
.. code-block:: python
class Brasil(BrazilSpecProvider):
class Meta:
Expand All @@ -158,7 +158,7 @@ Generally, you don’t need to add built-it classes to the object
demonstrating in which cases you should add a built-in class provider to
the object :class:`~mimesis.Generic`. You can use it directly, as shown below:

.. code:: python
.. code-block:: python
from mimesis.builtins import RussiaSpecProvider
from mimesis.enums import Gender
Expand All @@ -180,7 +180,7 @@ The library provides support for a wide range of data, which is sufficient
for most use cases. However, for those who wish to create their own providers
with more specific data, this can be achieved as follows:

.. code:: python
.. code-block:: python
from mimesis import Generic
from mimesis.locales import Locale
Expand Down Expand Up @@ -218,7 +218,7 @@ with more specific data, this can be achieved as follows:
In addition, you can also add multiple providers:

.. code:: python
.. code-block:: python
generic.add_providers(SomeProvider, Another)
generic.some_provider.hello()
Expand All @@ -229,15 +229,15 @@ In addition, you can also add multiple providers:
If you attempt to add a provider that does not inherit from :class:`~mimesis.providers.base.BaseProvider`,
you will receive a **TypeError** exception:

.. code:: python
.. code-block:: python
class InvalidProvider:
@staticmethod
def hello() -> str:
return 'Hello!'
generic.add_provider(InvalidProvider)
Traceback (most recent call last):
...
...
TypeError: The provider must be a subclass of mimesis.providers.BaseProvider.
Expand All @@ -247,7 +247,7 @@ that only a single instance of the Random object is used.

Everything here is quite straightforward, but we would like to clarify one point:
the **name** attribute in the **Meta** class refers to the name of the class through which access
to methods of user-class providers is carried out. By default, the class name is used in
to methods of user-class providers is carried out. By default, the class name (``cls.__name__``) is used in
lowercase letters.

See :ref:`seeded_data` to learn how to access the :class:`~mimesis.random.Random` object.
Expand Down Expand Up @@ -290,7 +290,7 @@ For example:
Afterwards, you will need to create a class that inherits from :class:`~mimesis.providers.base.BaseDataProvider`:

.. code:: python
.. code-block:: python
from pathlib import Path
Expand All @@ -314,10 +314,9 @@ The **Meta** class is required and must contain the following attributes:

That’s it! Now you can use your custom data provider:

.. code:: python
.. code-block:: python
>>> from mimesis.locales import Locale
>>> cdp = CustomDataProvider(Locale.EN)
>>> cdp.my_method()
'value3'
10 changes: 5 additions & 5 deletions docs/quickstart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ desired method with the appropriate parameters.

Consider the following example:

.. code:: python
.. code-block:: python
from mimesis import Person
from mimesis.locales import Locale
Expand Down Expand Up @@ -46,7 +46,7 @@ code.

Incorrect:

.. code:: python
.. code-block:: python
from mimesis import Person, Datetime, Text, Code
from mimesis.locales import Locale
Expand All @@ -59,7 +59,7 @@ Incorrect:
Correct:

.. code:: python
.. code-block:: python
from mimesis import Generic
from mimesis.locales import Locale
Expand All @@ -73,7 +73,7 @@ Correct:
Still correct:

.. code:: python
.. code-block:: python
from mimesis import Person
from mimesis.locales import Locale
Expand All @@ -84,7 +84,7 @@ Still correct:
Also correct:

.. code:: python
.. code-block:: python
from mimesis import Person
Expand Down
9 changes: 3 additions & 6 deletions docs/random_and_seed.rst
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ to data provider:

.. code-block:: python
from mimesis import Person
from mimesis.locales import Locale
from mimesis import Person, Locale
person = Person(locale=Locale.TR, seed=0xFF)
person.full_name()
Expand All @@ -67,8 +66,7 @@ method of the :class:`~mimesis.providers.BaseProvider` class

.. code-block:: python
from mimesis import Person
from mimesis.locales import Locale
from mimesis import Person, Locale
person = Person(Locale.EN, seed='Wow.')
Expand All @@ -85,8 +83,7 @@ If you want to use the same seed for all your data providers, then using :class:

.. code-block:: python
from mimesis import Generic
from mimesis.locales import Locale
from mimesis import Generic, Locale
generic = Generic(Locale.EN, seed='Wow. Much seed. Much random.')
Expand Down
34 changes: 17 additions & 17 deletions docs/schema.rst
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ while :class:`~mimesis.schema.Field` generates a single value.

Let's take a look at the example:

.. code:: python
.. code-block:: python
>>> from mimesis import Field, Fieldset, Locale
>>> field = Field(locale=Locale.EN)
Expand All @@ -196,7 +196,7 @@ of a keyword argument **i** for a specific field.

Let's take a look at the example:

.. code:: python
.. code-block:: python
>>> from mimesis import Fieldset, Locale
>>> fs = Fieldset(locale=Locale.EN)
Expand All @@ -217,7 +217,7 @@ With :class:`~mimesis.schema.Fieldset`, you can create datasets that are
similar in structure to your real-world data, allowing you to perform accurate
and reliable testing and analysis:

.. code:: python
.. code-block:: python
import pandas as pd
from mimesis import Fieldset
Expand Down Expand Up @@ -255,7 +255,7 @@ the final result as the **key** parameter.

Let's take a look at the example:

.. code-block::
.. code-block:: python
>>> from mimesis import Field, Fieldset, Locale
>>> field = Field(Locale.EN)
Expand Down Expand Up @@ -290,7 +290,7 @@ it is just a closure which accepts two arguments: **value** and **probability**.

Let's take a look at the example:

.. code:: python
.. code-block:: python
>>> from mimesis import Fieldset, Locale
>>> from mimesis.keys import maybe
Expand All @@ -303,7 +303,7 @@ In the example above, the probability of generating a **None** value instead of

You can use any other value instead of **None**:

.. code:: python
.. code-block:: python
>>> from mimesis import Fieldset
>>> from mimesis.keys import maybe
Expand All @@ -323,7 +323,7 @@ data in romanized form, you can make use of the following key function :func:`~m

Let's take a look at the example:

.. code:: python
.. code-block:: python
>>> from mimesis.schema import Field, Fieldset, Locale
>>> from mimesis.keys import romanize
Expand Down Expand Up @@ -355,7 +355,7 @@ class used to ensure that all key functions accessing random have the same seed.

Here is an example of how to do this:

.. code:: python
.. code-block:: python
>>> from mimesis import Field
>>> from mimesis.locales import Locale
Expand Down Expand Up @@ -404,7 +404,7 @@ Register Field Handler
Suppose you want to create a field that returns a random value from a list of values. First, you need to
create a field handler. Let's call it ``my_field``.

.. code:: python
.. code-block:: python
def my_field(random, a=None, b=None) -> Any:
return random.choice([a, b])
Expand All @@ -421,7 +421,7 @@ In this example, we will name the field ``hohoho``.
To avoid receiving a ValueError, the field name must be a string that conforms to a valid Python identifier,
i.e ``field_name.isidentifier()`` returns ``True``.

.. code:: python
.. code-block:: python
>>> from mimesis import Field
Expand All @@ -433,14 +433,14 @@ In this example, we will name the field ``hohoho``.
Note that you can still use a `key function`, but the order of the arguments matters, so the field name comes first,
the `key function` second, and then the rest of the keyword arguments (`**kwargs`) that are passed to the field handler:

.. code:: python
.. code-block:: python
>>> field("hohoho", key=str.upper, a="a", b="b")
'A'
You can register multiple fields at once:

.. code:: python
.. code-block:: python
>>> field.register_fields(
fields=[
Expand All @@ -457,22 +457,22 @@ Unregister Field Handler

If you want to unregister a field handler, you can do it like this:

.. code:: python
.. code-block:: python
>>> field.unregister_field("hohoho")
Now you can't use it anymore and will get a ``FieldError`` if you try to do so.

If you'll attempt to unregister a field that was never registered then nothing going to happen:

.. code:: python
.. code-block:: python
>>> field.unregister_field("blabla") # nothing happens
It's pretty obvious that you can unregister multiple fields at once as well:

.. code:: python
.. code-block:: python
>>> field.unregister_fields(
fields=[
Expand All @@ -484,7 +484,7 @@ It's pretty obvious that you can unregister multiple fields at once as well:
or all fields at once:

.. code:: python
.. code-block:: python
>>> field.unregister_all_fields()
Expand All @@ -496,7 +496,7 @@ Data can be exported in JSON or CSV formats, as well as pickled object represent

Let's take a look at the example:

.. code:: python
.. code-block:: python
from mimesis.enums import TimestampFormat
from mimesis.locales import Locale
Expand Down
Loading

0 comments on commit 033c399

Please sign in to comment.