Skip to content

Commit

Permalink
Merge branch 'main' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
christianhelle committed Aug 2, 2023
2 parents 3f177a0 + b1c3623 commit 2ee3a12
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/workflows/sonar-cloud.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ jobs:

- name: SonarCloud Scan
uses: SonarSource/sonarcloud-github-action@master
continue-on-error: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
11 changes: 11 additions & 0 deletions src/autofaker/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,23 @@ def create_datetime(type_name, field_name: str = None, use_fake_data: bool = Fal

@staticmethod
def _get_type_name(t) -> str:
PRIMITIVE_TYPES = {
"int", "float", "str", "complex", "range", "bytes", "bytearray"
}

try:
return t.__name__
except Exception:
attributes = dir(t)
if "_name" in attributes:
return t._name
# If __future__.annotations was imported by the user, then the type
# will be a str. Thus, asserting the type with type() will fail,
# because it will always be a string. This is because, annotations
# transforms any type into a string object. Therefore, if the type
# is a string, assess if it is the name of a known primitive type.
elif type(t) == str and t in PRIMITIVE_TYPES:
return t
return type(t).__name__


Expand Down

0 comments on commit 2ee3a12

Please sign in to comment.