Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor/perf: Eliminate redundant string casting in random_gen utility #455

Merged
merged 2 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Added

### Changed
- Remove unnecessary casting to string methods random_gen.gen_slug and random_gen.gen_string

### Removed

Expand Down
6 changes: 2 additions & 4 deletions model_bakery/random_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,7 @@ def gen_time() -> time:


def gen_string(max_length: int) -> str:
return str(
"".join(baker_random.choice(string.ascii_letters) for _ in range(max_length))
)
return "".join(baker_random.choice(string.ascii_letters) for _ in range(max_length))


def _gen_string_get_max_length(field: Field) -> Tuple[str, int]:
Expand All @@ -129,7 +127,7 @@ def _gen_string_get_max_length(field: Field) -> Tuple[str, int]:

def gen_slug(max_length: int) -> str:
valid_chars = string.ascii_letters + string.digits + "_-"
return str("".join(baker_random.choice(valid_chars) for _ in range(max_length)))
return "".join(baker_random.choice(valid_chars) for _ in range(max_length))


gen_slug.required = ["max_length"] # type: ignore[attr-defined]
Expand Down