-
Notifications
You must be signed in to change notification settings - Fork 418
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
Update csv_generator.py #2231
base: main
Are you sure you want to change the base?
Update csv_generator.py #2231
Conversation
added some features
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Type hints have been added to the code to specify the types of the function parameters and return values. This helps make the code easier to understand and maintain by providing clear information about the expected types of values
I actually see some of the type hinting removed in the changes. Is that intended, and, if so, what's the reasoning? As you stated, the type hints are intended to help.
The file opening mode has been updated to use 'w' instead of 'wb' when running Python 3 or above. This ensures compatibility with both Python 2 and Python 3.
Python 2.x support ended from the Python community in 2020. Since the ECS repo supports Python 3.8+, we could simplify by removing the check for Python 2.x vs. 3.x.
Removed unnecessary type casting: The str.lower() method is unnecessary when calling str() on a boolean value. It has been removed for simplicity.
This is the behavior I see in the REPL. I also don't actually see the .lower()
method removed.
>>> str(True)
'True'
>>> str(True).lower()
'true'
@@ -1,33 +1,10 @@ | |||
# Licensed to Elasticsearch B.V. under one or more contributor |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suspect this header was removed by your editor, but it would need to remain with any changes.
import _csv | ||
import csv | ||
import sys | ||
from typing import ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like with the header, I suspect this changes were done automatically by your editor. If not, can you explain your reasoning for the edits?
open_mode: str = "wb" | ||
if sys.version_info >= (3, 0): | ||
open_mode: str = "w" | ||
open_mode = "w" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd suggest simplifying even more:
with open(file. "w") as csvfile:
If we do make this change in this generator, I think it'd make sense to do the same across the repo (e.g. here).
quoting=csv.QUOTE_MINIMAL, | ||
lineterminator='\n') | ||
|
||
schema_writer = csv.writer(csvfile, delimiter=',', quoting=csv.QUOTE_MINIMAL, lineterminator='\n') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why remove the type hint, _csv._writer
?
field_set: str = 'base' | ||
else: | ||
field_set: str = key_parts[0] | ||
key_parts = field['flat_name'].split('.') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, why remove the type hints?
This PR is stale because it has been open for 60 days with no activity. |
Changes in the
csv_generator.py
file'w'
instead of'wb'
when running Python 3 or above. This ensures compatibility with both Python 2 and Python 3.str.lower()
method is unnecessary when callingstr()
on a boolean value. It has been removed for simplicity.