-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
656 additions
and
385 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import re | ||
|
||
# Sample input string for demonstration purposes. | ||
input_data = """ | ||
@dataclass | ||
class MyClass: | ||
field1: int = dfield("int", default=0) | ||
field2: str = dfield("str", default="") | ||
""" | ||
|
||
# Regular expression pattern to match the specific format in data class fields | ||
pattern = re.compile(r'(\w+): (\w+|\[.*?\]|".*?"|\'.*?\') = dfield\(".*?", (.*?)\)') | ||
|
||
# Function to perform the substitution | ||
def replace_dfield(match): | ||
field_name = match.group(1) | ||
field_type = match.group(2) | ||
remaining_args = match.group(3) | ||
return f'{field_name}: {field_type} = dfield("{field_name}", {remaining_args})' | ||
|
||
# Perform the replacement using the sub method | ||
output_data = re.sub(pattern, replace_dfield, input_data) | ||
|
||
# Print result | ||
print(output_data) |
Oops, something went wrong.