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

Update csv_generator.py #2231

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

cicada0007
Copy link

Changes in the csv_generator.py file

1 change

  • 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

2 change

  • 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.

3 change

  • Removed unnecessary type casting: The str.lower() method is unnecessary when calling str() on a boolean value. It has been removed for simplicity.

added some features
@cicada0007 cicada0007 requested a review from a team as a code owner June 30, 2023 16:29
Copy link
Member

@ebeahan ebeahan left a 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
Copy link
Member

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 (
Copy link
Member

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"
Copy link
Member

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')
Copy link
Member

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('.')
Copy link
Member

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?

@github-actions
Copy link

github-actions bot commented Sep 6, 2023

This PR is stale because it has been open for 60 days with no activity.

@github-actions github-actions bot added the stale Stale issues and pull requests label Sep 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale Stale issues and pull requests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants