joke2k / faker

Faker is a Python package that generates fake data for you.
https://faker.readthedocs.io
MIT License
17.74k stars 1.93k forks source link

'Generator' object has no attribute ... #1139

Closed fannyhub closed 2 years ago

fannyhub commented 4 years ago

a number of providers causes this problem: zipcode postalcode zipcode_plus4 military_ship

Steps to reproduce

  1. f = Faker('pl_PL')
  2. f.zipcode()
  3. f.postalcode()

Expected behavior

I was expecting '80-358'

Actual behavior

AttributeError: 'Generator' object has no attribute 'postalcode'

malefice commented 4 years ago

The provider methods you listed are exclusive to the en_US address provider. The pl_PL provider does not support those methods, so it is actually behaving as expected.

What is wrong, however, is the current documentation that gives that impression as shown in this page. Because of how the docs are currently generated, the "standard providers" page use en_US provider classes instead of the "core" provider classes, and that is why those methods are included even if they should not be.

While I did not mention this specific issue in #1083, this is something I already addressed in my PR #1128 as part of revamping the provider docs. It is still a WIP, but standard provider docs can be found here, and localized pl_PL provider docs can be found here. The way to view this is that the localized provider categories, e.g. address, automotive, etc, "overrides" the standard provider categories.

For example, in pl_PL, the address provider has been localized, so methods in that localized address provider will be available instead of the standard address provider methods. The color provider, however, has not been localized, so the standard color provider methods will be available.

github-actions[bot] commented 2 years ago

This issue is stale because it has been open for 30 days with no activity.

github-actions[bot] commented 2 years ago

This issue was closed because it has been inactive for 14 days since being marked as stale.

kirmola commented 5 months ago

This actually gave me an idea about how to solve a problem that I have been tackling for hours. It seems some methods are locale specific. Like Faker("en_IN").aadhar_id(). For anyone who struggled like me Just add respective locales to Faker() instance and you will be good to go.