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: Consolidate import and usage of random #34108

Merged
merged 1 commit into from Sep 7, 2023
Merged

Conversation

eumiro
Copy link
Contributor

@eumiro eumiro commented Sep 5, 2023

No description provided.

assert tis[i].state == State.SUCCESS
assert tis[i].try_number == 3
assert tis[i].max_tries == 1
for ti in tis:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow this entire function can use a rewrite. (Not saying you should do it in this PR.)

Copy link
Member

@Lee-W Lee-W left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as #34113. I'm wondering why we want to consolidate imports this way. Does that mean we should avoid from ... import ... pattern.

@eumiro
Copy link
Contributor Author

eumiro commented Sep 6, 2023

Same as #34113. I'm wondering why we want to consolidate imports this way. Does that mean we should avoid from ... import ... pattern.

I'm suggesting having all imported modules/classes the same way, so in this case there's always import random and not from random import random which could confuse devs. random is a case where direct import random is better, since solitary random() or randrange() may be obvious, but sample() or choice() not.

There are cases where I do from … import …, e.g. collections or pathlib. The most important rule is to be repo-wide-consistent. I also usually do import itertools as it, but the maintainers suggested to keep it as itertools, which I do not object.

@potiuk potiuk merged commit 4fa66d1 into apache:main Sep 7, 2023
63 of 64 checks passed
@Lee-W
Copy link
Member

Lee-W commented Sep 7, 2023

Same as #34113. I'm wondering why we want to consolidate imports this way. Does that mean we should avoid from ... import ... pattern.

I'm suggesting having all imported modules/classes the same way, so in this case there's always import random and not from random import random which could confuse devs. random is a case where direct import random is better, since solitary random() or randrange() may be obvious, but sample() or choice() not.

There are cases where I do from … import …, e.g. collections or pathlib. The most important rule is to be repo-wide-consistent. I also usually do import itertools as it, but the maintainers suggested to keep it as itertools, which I do not object.

Yep, agree unifying them would be great 👍 Do we want to document it somewhere? (e.g., use import random instead of from random import random)

@potiuk
Copy link
Member

potiuk commented Sep 7, 2023

I think those kind of rules are rarely read and we have two approaches there that 'work'

a) hope that people will follow what is in the code (not perfect but mostly works) - this is a stage we are currently in

b) better - add pre-commit to do ast parsing and add rules of things we want do not want to have. I'd say it would be great if thos unification that can be done (imports are generally easy) are added as a rule to pre-commits

Maybe you can work with @eumiro together to determine the list of rules that can be automatically verified and and write a pre&commit doing it ?

@eumiro eumiro deleted the random branch September 7, 2023 17:36
@ephraimbuddy ephraimbuddy added this to the Airflow 2.7.2 milestone Oct 3, 2023
@ephraimbuddy ephraimbuddy added the type:misc/internal Changelog: Misc changes that should appear in change log label Oct 3, 2023
ephraimbuddy pushed a commit that referenced this pull request Oct 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:dev-tools area:providers area:system-tests provider:amazon-aws AWS/Amazon - related issues provider:google Google (including GCP) related issues provider:oracle provider:ssh type:misc/internal Changelog: Misc changes that should appear in change log
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants