Skip to content

Commit

Permalink
Fixed bug with improper handling of attributes in __dir__
Browse files Browse the repository at this point in the history
  • Loading branch information
lk-geimfari committed Dec 16, 2017
1 parent 568f22e commit c22b8c2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
8 changes: 4 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@
- Added method `boolean` for `Development` which returns random boolean value
- Added method `integers` for `Numbers`
- Added new built in specific provider `UkraineSpecProvider`
- Added support of `key functions` for the object `Field`
- Added object `Schema` which helps generate data by schema
- Added support of `key functions` for the object `schema.Field`
- Added object `schema.Schema` which helps generate data by schema

**Fixed**:

- Fixed issue `full_name` when method return female surname for male name and vice versa

- Fixed bug with improper handling of attributes that begin with an underscore for class `schema.Field`

**Updated**:

- Updated method `version` for supporting pre-releases
- Updated method `version` for supporting pre-releases and calendar versioning

---

Expand Down
15 changes: 11 additions & 4 deletions mimesis/providers/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def __init__(self, *args, **kwargs):
self.games = Games()
self.cryptographic = Cryptographic()

def __getattr__(self, attrname):
def __getattr__(self, attrname: str):
"""Get _attribute without underscore
:param attrname: Attribute name.
Expand All @@ -61,10 +61,17 @@ def __getattr__(self, attrname):
return attribute(self.locale)

def __dir__(self) -> List[str]:
attributes = []
exclude = BaseProvider().__dict__.keys()
attrs = [a.replace('_', '') for a
in self.__dict__ if a not in exclude]
return attrs

for a in self.__dict__:
if a not in exclude:
if a.startswith('_'):
attribute = a.replace('_', '', 1)
attributes.append(attribute)
else:
attributes.append(a)
return attributes

def add_provider(self, cls) -> None:
"""Add a custom provider to Generic() object.
Expand Down

0 comments on commit c22b8c2

Please sign in to comment.