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

Use sys.version_info in compatibility layer #220

Merged
merged 4 commits into from
Dec 12, 2023
Merged

Conversation

hauntsaninja
Copy link
Collaborator

@hauntsaninja hauntsaninja commented Apr 17, 2023

Fixes #219

Static type checkers are able to understand checks against sys.version_info much better than try-except. In general, if type checkers tried to handle conditional imports fancily, this would result in unsoundness.

Another reason is that you may have tomli conditionally installed based on Python version, in which case a type checker would not even have a way of knowing what tomli is, but with a sys.version check it knows it doesn't need to know that.

hauntsaninja and others added 3 commits April 17, 2023 13:44
Fixes #219

Static type checkers are able to understand checks against sys.version_info much better than try-except. In general, if type checkers tried to handle conditional imports fancily, this would result in unsoundness.

Another reason is that you may have tomli conditionally installed based on Python version, in which case a type checker would not even have a way of knowing what tomli is.
@codecov-commenter
Copy link

codecov-commenter commented Apr 29, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

❗ No coverage uploaded for pull request base (master@39eff9b). Click here to learn what that means.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##             master      #220   +/-   ##
==========================================
  Coverage          ?   100.00%           
==========================================
  Files             ?         4           
  Lines             ?       507           
  Branches          ?        96           
==========================================
  Hits              ?       507           
  Misses            ?         0           
  Partials          ?         0           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

@DanielNoord DanielNoord left a comment

Choose a reason for hiding this comment

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

Can confirm that sys is also the pattern used by most open source projects I have seen, for the reasons outlined in the OP above.

@hugovk
Copy link
Contributor

hugovk commented Dec 1, 2023

A benefit of using sys.version_info is https://github.com/asottile/pyupgrade will automatically remove the old part when the time comes.

@hukkin
Copy link
Owner

hukkin commented Dec 12, 2023

Thanks! I don't think there was anything wrong with the try-except pattern but seems like the change can save some folks' time and reduce confusion so let's merge.

@hukkin hukkin merged commit a613867 into master Dec 12, 2023
28 checks passed
@hukkin hukkin deleted the hauntsaninja-patch-1 branch December 12, 2023 11:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

mypy errors with suggested tomli/tomllib compatibility layer
5 participants