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

Fix PyCharm/VSCode static type checking for dummy objects #1596

Merged
merged 11 commits into from Dec 8, 2022

Conversation

anton-l
Copy link
Member

@anton-l anton-l commented Dec 7, 2022

Applies the fix from huggingface/transformers#16578 to allow PyCharm and VSCode users to jump to the real class definition instead of the Dummy one (which is picked up by the type checker if not wrapped in an extra try-except).

PyCharm needed an index rebuild to see the changes, closing and reopening the IDE should do the trick.

Fixes #1479

Comment on lines 118 to 124
try:
if not (is_torch_available() and is_librosa_available()):
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
from ..utils.dummy_torch_and_librosa_objects import * # noqa F403
else:
from .utils.dummy_torch_and_transformers_and_onnx_objects import * # noqa F403
from .pipelines import AudioDiffusionPipeline, Mel
Copy link
Member Author

@anton-l anton-l Dec 7, 2022

Choose a reason for hiding this comment

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

These were under is_torch_available() before, so I suspect the dummies in dummy_torch_and_librosa_objects.py were created manually, instead of using make fix-copies.

Copy link
Member Author

Choose a reason for hiding this comment

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

And there were no import errors because is_torch_available() and is_librosa_available() was correctly used in pipelines.__init__.py instead.

@HuggingFaceDocBuilderDev
Copy link

HuggingFaceDocBuilderDev commented Dec 7, 2022

The documentation is not available anymore as the PR was closed or merged.

Copy link
Member

@pcuenca pcuenca left a comment

Choose a reason for hiding this comment

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

Awesome! Many thanks!

utils/check_dummies.py Outdated Show resolved Hide resolved
anton-l and others added 2 commits December 7, 2022 19:39
Co-authored-by: Pedro Cuenca <pedro@huggingface.co>
@@ -29,14 +36,12 @@
)
from .pipeline_utils import DiffusionPipeline
from .pipelines import (
AudioDiffusionPipeline,
Copy link
Contributor

Choose a reason for hiding this comment

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

ah it's further down

Co-authored-by: Patrick von Platen <patrick.v.platen@gmail.com>
Copy link
Contributor

@patrickvonplaten patrickvonplaten left a comment

Choose a reason for hiding this comment

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

Thanks!

@anton-l anton-l merged commit dbe0719 into main Dec 8, 2022
@anton-l anton-l deleted the fix-dummy-type-checking branch December 8, 2022 13:02
tcapelle pushed a commit to tcapelle/diffusers that referenced this pull request Dec 12, 2022
…e#1596)

* Fix PyCharm/VSCode static type checking for dummy objects

* Re-add dummies

* Fix AudioDiffusion imports

* fix import

* fix import

* Update utils/check_dummies.py

Co-authored-by: Pedro Cuenca <pedro@huggingface.co>

* Update src/diffusers/utils/import_utils.py

* Update src/diffusers/__init__.py

Co-authored-by: Patrick von Platen <patrick.v.platen@gmail.com>

* Update src/diffusers/pipelines/stable_diffusion/__init__.py

* fix double import

Co-authored-by: Pedro Cuenca <pedro@huggingface.co>
Co-authored-by: Patrick von Platen <patrick.v.platen@gmail.com>
sliard pushed a commit to sliard/diffusers that referenced this pull request Dec 21, 2022
…e#1596)

* Fix PyCharm/VSCode static type checking for dummy objects

* Re-add dummies

* Fix AudioDiffusion imports

* fix import

* fix import

* Update utils/check_dummies.py

Co-authored-by: Pedro Cuenca <pedro@huggingface.co>

* Update src/diffusers/utils/import_utils.py

* Update src/diffusers/__init__.py

Co-authored-by: Patrick von Platen <patrick.v.platen@gmail.com>

* Update src/diffusers/pipelines/stable_diffusion/__init__.py

* fix double import

Co-authored-by: Pedro Cuenca <pedro@huggingface.co>
Co-authored-by: Patrick von Platen <patrick.v.platen@gmail.com>
yoonseokjin pushed a commit to yoonseokjin/diffusers that referenced this pull request Dec 25, 2023
…e#1596)

* Fix PyCharm/VSCode static type checking for dummy objects

* Re-add dummies

* Fix AudioDiffusion imports

* fix import

* fix import

* Update utils/check_dummies.py

Co-authored-by: Pedro Cuenca <pedro@huggingface.co>

* Update src/diffusers/utils/import_utils.py

* Update src/diffusers/__init__.py

Co-authored-by: Patrick von Platen <patrick.v.platen@gmail.com>

* Update src/diffusers/pipelines/stable_diffusion/__init__.py

* fix double import

Co-authored-by: Pedro Cuenca <pedro@huggingface.co>
Co-authored-by: Patrick von Platen <patrick.v.platen@gmail.com>
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.

DummyObjects are impeding PyCharm
4 participants