question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

python providers should use value_types as a keyword argument

See original GitHub issue

Some of the python providers use a slightly unusual function call signature like this:

fake.pydict(nb_elements=10, variable_nb_elements=True, *value_types)
fake.pylist(nb_elements=10, variable_nb_elements=True, *value_types)

This leads to some usage problems with factory_boy (https://github.com/FactoryBoy/factory_boy/issues/387).

IMHO it would be much more convenient to be able to call the python providers with value_types as a keyword argument like so:

fake.pydict(nb_elements=10, variable_nb_elements=True, value_types=['str'])
fake.pylist(nb_elements=10, variable_nb_elements=True, value_types=['str'])

I know this would introduce a braking change to the python provider api, but if this is acceptable I can try to provide a PR.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:6
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

6reactions
fodracommented, Mar 29, 2018

I agree this confused me a little bit.

At first I was doing this

>>> fake.pydict(nb_elements=5, variable_nb_elements=False, ['str', 'str', 'str', 'str', 'str'])
  File "<input>", line 1
SyntaxError: positional argument follows keyword argument

Figured out you should not use the keywords if you want to specify value_types

>>> fake.pydict(5, False, 'str')
{'kind': 'NNxcLDYxjKXcCypxOanT', 'social': 'RfNzeHzBFhcHdEbUMiGL', 'article': 'HrTMTBGFOAcsUAibdVRo', 'per': 'gwZMuksrnrvMyVPXAkJB', '
imagine': 'RkvSHFrUMESRLIQDgkxL'}

I hope this helps someone going through the same issue.

2reactions
joke2kcommented, Jul 7, 2017

Hi @mhubig, it seems reasonable. To handle the backcompatibility we could use some signature like that:

fake.pydict(nb_elements=10, variable_nb_elements=True, value_types=None, *allowed_types)
fake.pylist(nb_elements=10, variable_nb_elements=True, value_types=None, *allowed_types)

Combining values_types and allowed_types carefully.

Read more comments on GitHub >

github_iconTop Results From Across the Web

PEP 692 – Using TypedDict for more precise **kwargs typing
The new approach revolves around using TypedDict to type **kwargs that comprise keyword arguments of different types.
Read more >
faker.providers.python — Faker 15.3.4 documentation
class faker.providers.python. ... Parameters: enum_cls – The Enum type to produce the value for. ... is use variable number of elements for dictionary....
Read more >
Entity Property Reference - App Engine - Google Cloud
Optional keyword argument: compressed . PickleProperty, Value is a Python object (such as a list or a dict or a string) that is...
Read more >
typing — PyTorch/Elastic master documentation
Internal helper functions: these should never be used in code outside this module. * _SpecialForm and its instances (special forms): Any, NoReturn, ...
Read more >
_ncs - NSO API 6.0 - Document - Cisco Developer
There should be no need to call this function directly. It is called internally when the Python module is loaded. Keyword arguments: name...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found