Skip to content

Commit 2ee3a12

Browse files
Merge branch 'main' into release
2 parents 3f177a0 + b1c3623 commit 2ee3a12

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

.github/workflows/sonar-cloud.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ jobs:
3939

4040
- name: SonarCloud Scan
4141
uses: SonarSource/sonarcloud-github-action@master
42+
continue-on-error: true
4243
env:
4344
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4445
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

src/autofaker/generator.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,23 @@ def create_datetime(type_name, field_name: str = None, use_fake_data: bool = Fal
4343

4444
@staticmethod
4545
def _get_type_name(t) -> str:
46+
PRIMITIVE_TYPES = {
47+
"int", "float", "str", "complex", "range", "bytes", "bytearray"
48+
}
49+
4650
try:
4751
return t.__name__
4852
except Exception:
4953
attributes = dir(t)
5054
if "_name" in attributes:
5155
return t._name
56+
# If __future__.annotations was imported by the user, then the type
57+
# will be a str. Thus, asserting the type with type() will fail,
58+
# because it will always be a string. This is because, annotations
59+
# transforms any type into a string object. Therefore, if the type
60+
# is a string, assess if it is the name of a known primitive type.
61+
elif type(t) == str and t in PRIMITIVE_TYPES:
62+
return t
5263
return type(t).__name__
5364

5465

0 commit comments

Comments
 (0)