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

Conditionally load stubs based on specific version of package installed #693

Open
mkurnikov opened this issue Dec 12, 2019 · 1 comment
Open
Labels
topic: feature Discussions about new features for Python's type annotations

Comments

@mkurnikov
Copy link

mkurnikov commented Dec 12, 2019

For django-stubs, we would like to be able to load stubs conditionally, like it's done for typeshed via https://mypy.readthedocs.io/en/latest/common_issues.html#python-version-and-system-platform-checks

See typeddjango/django-stubs#262

I'd like to propose to add a special function is_package_installed for stub files:

if is_package_installed('Django>=3.0.*')
    class Django30Class: ...
else:
    class Django22Class: ...

which will evaluate according to the rules specified in PEP440 https://www.python.org/dev/peps/pep-0440/#version-specifiers

It was discussed in python/typeshed#153, current workaround seems to be (from python/typeshed#153 (comment)):

release and install a separate stub package for each version of the library

I believe it's too complex, as one needs to maintain lots of separate branches for specific versions of the supported package. And versioning of the stubs package would then be PACKAGE_VERSION.STUBS_VERSION_INCREMENT?

@sobolevn
Copy link
Member

I am also interested in how stubs resolution / merge works in this case.

For example:

  • what if new functions / classes are added to a new version?
  • what if their types are changed?
  • what if something is removed from the future version?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: feature Discussions about new features for Python's type annotations
Projects
None yet
Development

No branches or pull requests

3 participants