Skip to content

DEP: adjust requirements for extra dependency on typing-extensions#15686

Merged
pllim merged 1 commit into
astropy:mainfrom
neutrinoceros:typing_extensions_req
Jan 7, 2024
Merged

DEP: adjust requirements for extra dependency on typing-extensions#15686
pllim merged 1 commit into
astropy:mainfrom
neutrinoceros:typing_extensions_req

Conversation

@neutrinoceros
Copy link
Copy Markdown
Contributor

Description

@hamogu @eerovaher

While reviewing #15685, I noticed that requirements on typing_extensions needed slight adjustements:

  • we use it only for the Self symbol, which was added in version 4.0.0
  • this symbol is in the standard library (typing.Self) in Python 3.11 and newer, so I made this requirement py310- only

I also found a note in a doctoring that doesn't seem relevant now that support for Python 3.8 was dropped.

  • By checking this box, the PR author has requested that maintainers do NOT use the "Squash and Merge" button. Maintainers should respect this when possible; however, the final decision is at the discretion of the maintainer that merges the PR.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Dec 6, 2023

Thank you for your contribution to Astropy! 🌌 This checklist is meant to remind the package maintainers who will review this pull request of some common things to look for.

  • Do the proposed changes actually accomplish desired goals?
  • Do the proposed changes follow the Astropy coding guidelines?
  • Are tests added/updated as required? If so, do they follow the Astropy testing guidelines?
  • Are docs added/updated as required? If so, do they follow the Astropy documentation guidelines?
  • Is rebase and/or squash necessary? If so, please provide the author with appropriate instructions. Also see instructions for rebase and squash.
  • Did the CI pass? If no, are the failures related? If you need to run daily and weekly cron jobs as part of the PR, please apply the "Extra CI" label. Codestyle issues can be fixed by the bot.
  • Is a change log needed? If yes, did the change log check pass? If no, add the "no-changelog-entry-needed" label. If this is a manual backport, use the "skip-changelog-checks" label unless special changelog handling is necessary.
  • Is this a big PR that makes a "What's new?" entry worthwhile and if so, is (1) a "what's new" entry included in this PR and (2) the "whatsnew-needed" label applied?
  • Is a milestone set? Milestone must be set but we cannot check for it on Actions; do not let the green checkmark fool you.
  • At the time of adding the milestone, if the milestone set requires a backport to release branch(es), apply the appropriate "backport-X.Y.x" label(s) before merge.

@neutrinoceros
Copy link
Copy Markdown
Contributor Author

I guess that the adjustment in minimal required version is technically a bug fix, so I'd suggest to backport this.

@pllim pllim requested review from eerovaher and nstarman December 6, 2023 13:40
@pllim pllim added this to the v6.1.0 milestone Dec 6, 2023
Comment on lines 19 to +28
if TYPE_CHECKING:
import sys
from typing import Any, Callable

from typing_extensions import Self

from astropy.units import UnitBase

if sys.version_info >= (3, 11):
from typing import Self
else:
from typing_extensions import Self
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.

This if TYPE_CHECKING: block was added in #15354. An early version of that pull request did include explicitly version dependent code, but during the review @nstarman pointed out that Ruff (specifically UP035) knows enough about typing and typing_extensions that it can automatically change the import when support for Python 3.10 is dropped. The change proposed here is not necessary.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ruff (specifically UP035) knows enough about typing and typing_extensions that it can automatically change the import when support for Python 3.10 is dropped.

good to know, but that's not why I added it here; my reasoning is that, I can't make typing-extensions a py310- only extra dependency without handling the py311+ case explicitly in code.
If you guys still prefer to keep the current style that's fine with me, and in that case, please feel free to close !

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.

Then it might be a good idea to have explicitly version-dependent code here after all. Note that Ruff rule UP036 recognizes obsolete sys.version_info comparisons, so there's no reason we should use astropy.utils.compat.PYTHON_LT_3_11 here.

Copy link
Copy Markdown
Member

@nstarman nstarman Dec 6, 2023

Choose a reason for hiding this comment

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

I still think it's best to not version check on typing_extension imports. The package does it internally and its MO is to make using typing features seamless. Later version-dependent code doesn't care where Self is from so long as it's there. And with typing_extensions it always will be.

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.

#minimum-effort.

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.

Is this conversation resolved or not? Is this PR good to merge? @eerovaher ?

Comment thread astropy/units/quantity.py Outdated
Comment on lines +391 to +390
-----
With Python 3.9+ or :mod:`typing_extensions`, |Quantity| types are also
static-type compatible.
|Quantity| types are also static-type compatible.
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.

In the pull request @nstarman opened to drop support for Python 3.9 he also found some code and documentation that should or could have been updated when support for Python 3.8 was dropped. That pull request has not been merged yet. Perhaps it would be a good idea to open a separate pull request for removing the obsolete mentions of Python 3.9 like this.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

You must be referring to #15603. I notice this specific line isn't touched there. I'm happy to open another PR with just this (and possibly other similar changes if I find any), but I'm also fine if @nstarman wants to add it to his PR instead !

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.

The problem with #15603 is that it seems to be stuck because the reference images for image comparison tests need to be regenerated. It would be better to split off things from there in new pull requests instead of adding more things to it that would then get stuck too.

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.

Agreed. Anything that can be paired off is good. Feel free to 🍒pick commits.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ok, I'll move it to a separate branch, and will open a PR in a few days with maybe more of the same !

Comment thread pyproject.toml Outdated
"fsspec[http]>=2023.4.0",
"s3fs>=2023.4.0",
"pre-commit",
"typing_extensions>=4.0.0 ; python_version < '3.11'",
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.

It is good to try to keep track of why typing_extensions is needed, but it is also important to record the reason in commit messages.

Copy link
Copy Markdown
Member

@nstarman nstarman left a comment

Choose a reason for hiding this comment

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

Thanks @neutrinoceros! Looks good as is, but I have a small suggestion. Also @eerovaher's comment on comments is good, lest we forget why typing_extensions is version-pinned

@eerovaher
Copy link
Copy Markdown
Member

Do we actually need typing_extensions as a direct dependency anyways? It should only ever be used in if TYPE_CHECKING: blocks, which are not executed at runtime.

@neutrinoceros
Copy link
Copy Markdown
Contributor Author

Do we actually need typing_extensions as a direct dependency anyways?

it's currently only included as an extra dependency (part of the all target), which seems reasonable ?

@neutrinoceros neutrinoceros marked this pull request as draft December 6, 2023 17:33
@neutrinoceros
Copy link
Copy Markdown
Contributor Author

@eerovaher @nstarman I just removed the adjacent-but-not-strictly-related part of the patch and amended the commit message with more details.

@neutrinoceros neutrinoceros marked this pull request as ready for review December 6, 2023 17:38
@eerovaher
Copy link
Copy Markdown
Member

If we don't list typing_extensions as a dependency at all then we don't have to worry about which Python versions it should be installed with, and then it's clear that we don't need any version dependent code inside if TYPE_CHECKING: blocks either.

@neutrinoceros
Copy link
Copy Markdown
Contributor Author

Then I'll leave it to @nstarman to decide what to do here since he previously approved, but again, no harm done in closing this PR if we don't collectively think it's needed :)

@eerovaher
Copy link
Copy Markdown
Member

I'm not suggesting to close this pull request without merging, I'm suggesting remove typing_extensions from the dependency list.

@nstarman
Copy link
Copy Markdown
Member

nstarman commented Dec 6, 2023

I think if someone installs Astropy[all] they should get everything, including static type time stuff. Perhaps we should add an install option [type] that is included in all. Because with Protocols and API we can support interfaces without run-time dependencies. So IMO let's leave it all for now and follow up with a type install option

@neutrinoceros
Copy link
Copy Markdown
Contributor Author

Fine by me @nstarman. I'm also happy to open another PR to implement your proposed [type] extra, if you'd like.

@nstarman
Copy link
Copy Markdown
Member

nstarman commented Dec 6, 2023

Fine by me @nstarman. I'm also happy to open another PR to implement your proposed [type] extra, if you'd like.

Much appreciated!

@neutrinoceros
Copy link
Copy Markdown
Contributor Author

done in #15689

@nstarman
Copy link
Copy Markdown
Member

nstarman commented Dec 7, 2023

Merge this first or what's the order?

@neutrinoceros
Copy link
Copy Markdown
Contributor Author

@nstarman any order is fine, I'll just need to rebase whatever comes in second

@eerovaher
Copy link
Copy Markdown
Member

What is this pull request supposed to do when #15689 is merged?

@nstarman
Copy link
Copy Markdown
Member

nstarman commented Dec 7, 2023

Add the info. 2 small PRs. Could combine, but it's fine as is, reflecting our discussions.
@eerovaher, is this good to merge? I still think we can drop the version check in modeling, but that's entirely stylistic since typing_extensions does it internally and we have ruff's pyupgrade to take care of all future cleanup.

@neutrinoceros
Copy link
Copy Markdown
Contributor Author

rebased and updated. Now it should be clear what it does on top of #15689 , and it's good to go !

@eerovaher
Copy link
Copy Markdown
Member

I don't think the version check is necessary for preventing unwanted installations of typing_extensions now that #15689 is merged. If users install astropy[typing] they probably want typing_extensions. If they install astropy[all] they shouldn't be surprised if they end up with packages they are not actually using.

@neutrinoceros
Copy link
Copy Markdown
Contributor Author

If users install astropy[typing] they probably want typing_extensions.

I respectfully disagree here, but I won't insist. Again, I'm fine with this PR being closed if it's controversial.

@neutrinoceros
Copy link
Copy Markdown
Contributor Author

I believe the only remaining failure is due to #15692, which I think can be resolved separately, so I'll start working on that now.

@pllim
Copy link
Copy Markdown
Member

pllim commented Jan 6, 2024

Will this fix #15819 ? If so, can we wrap this up for merge? Thanks!

@pllim
Copy link
Copy Markdown
Member

pllim commented Jan 6, 2024

Actually needs a rebase, and then I can slap "Extra CI" on this, to be sure.

@neutrinoceros
Copy link
Copy Markdown
Contributor Author

Will this fix #15819 ?

I don't think so, but I'll rebase now anyway !

At the moment, typing-extensions is only ever used to replace `typing.Self`, which is included in the standard library from Python 3.11 on.
The backport symbol, `typing_extensions.Self`, requires version 4.0 (or newer).
@neutrinoceros neutrinoceros force-pushed the typing_extensions_req branch from d703f40 to 169f461 Compare January 6, 2024 07:59
@pllim pllim added the Extra CI Run cron CI as part of PR label Jan 6, 2024
@pllim
Copy link
Copy Markdown
Member

pllim commented Jan 6, 2024

Hmm link check is green here. 🤷

@nstarman
Copy link
Copy Markdown
Member

nstarman commented Jan 7, 2024

My personal preference would be to just have typing_extensions as a standard dependency of Astropy and let ruff switch imports from typing_extensions to typing per our minimum Python version. typing_extensions is developed within the core Python org (https://github.com/python/typing_extensions), so this is a very safe approach. That said, since we have not yet committed to having typing_extensions as a dependency, this PR is good to merge. Thanks @neutrinoceros!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants