Skip to content

hasattr(faker, 'bank') returns True for en_US locale #2377

@lexakimov

Description

@lexakimov

Problem occurs from version 37.12.0

def test_faker():
    locale = 'en_US'
    faker = Faker(locale=locale)
    faker.seed_instance(123)

    if hasattr(faker, 'company'): # True
        value = faker.company() # Ok
        print(value) # 'Adams Group'

    if hasattr(faker, 'bank'): # True
        value = faker.bank() # AttributeError: The Provider provider does not have a 'banks' attribute. Consider contributing to the project and  adding a 'banks' tuple to enable bank name generation.
        print(value)

full error message

self = <faker.providers.bank.en_GB.Provider object at 0x7f7955a88190>

    def bank(self) -> str:
        """Generate a bank name."""
        if not hasattr(self, "banks"):
>           raise AttributeError(
                f"The {self.__class__.__name__} provider does not have a 'banks' "
                "attribute. Consider contributing to the project and "
                " adding a 'banks' tuple to enable bank name generation."
            )
E           AttributeError: The Provider provider does not have a 'banks' attribute. Consider contributing to the project and  adding a 'banks' tuple to enable bank name generation.

.venv/lib/python3.14/site-packages/faker/providers/bank/__init__.py:54: AttributeError

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions