Skip to content

Update csv_generator.py#2231

Closed
cicada0007 wants to merge 1 commit intoelastic:mainfrom
cicada0007:patch-2
Closed

Update csv_generator.py#2231
cicada0007 wants to merge 1 commit intoelastic:mainfrom
cicada0007:patch-2

Conversation

@cicada0007
Copy link
Copy Markdown

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor

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
@github-actions
Copy link
Copy Markdown
Contributor

This PR has been automatically closed due to inactivity. If you'd like to
continue working on this, feel free to re-open the PR or create a new one.

Thank you for your contribution!

@github-actions github-actions Bot closed this Mar 19, 2026
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