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

Replace == by is for types comparison #33983

Merged
merged 1 commit into from
Sep 11, 2023

Conversation

hussein-awala
Copy link
Member


^ Add meaningful description above
Read the Pull Request Guidelines for more information.
In case of fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
In case of a new dependency, check compliance with the ASF 3rd Party License Policy.
In case of backwards incompatible changes please leave a note in a newsfragment file, named {pr_number}.significant.rst or {issue_number}.significant.rst, in newsfragments.

@uranusjr
Copy link
Member

uranusjr commented Sep 1, 2023

Not sure this is advantaguous. Readability is approximately on par, but

$ py -m timeit -s 't = dict; from typing import Dict' 't in (Dict, dict)'
10000000 loops, best of 5: 35.9 nsec per loop
$ py -m timeit -s 't = dict; from typing import Dict' 't in (dict, Dict)'
10000000 loops, best of 5: 25 nsec per loop

$ py -m timeit -s 't = dict; from typing import Dict' 't is Dict or t is dict'
20000000 loops, best of 5: 13.7 nsec per loop
$ py -m timeit -s 't = dict; from typing import Dict' 't is dict or t is Dict'
20000000 loops, best of 5: 9.98 nsec per loop

$ py -m timeit -s 't = dict; from typing import Dict' 't == Dict or t == dict'
10000000 loops, best of 5: 27.2 nsec per loop
$ py -m timeit -s 't = dict; from typing import Dict' 't == dict or t == Dict'
20000000 loops, best of 5: 13.8 nsec per loop

both the is and == versions are consistently faster. Considering we’re comparing types here, is would be best IMO.

@hussein-awala hussein-awala changed the title Use in tuple instead of multiple equality comparisons Replace == by is for types comparison Sep 9, 2023
@potiuk potiuk merged commit 8b6ab5a into apache:main Sep 11, 2023
42 checks passed
@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
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