keras-team / keras-nlp

Modular Natural Language Processing workflows with Keras
Apache License 2.0
734 stars 216 forks source link

Change the order of importing `keras` #1596

Closed james77777778 closed 2 months ago

james77777778 commented 2 months ago

This should fix the issue (after #1593) with type annotations for modern editors such as vscode.

Before After
before after
SamanehSaadat commented 2 months ago

Hi @james77777778!

Thanks for catching this and thanks for sending the fix! I'm curious to understand why changing the order in the if/else fixes the issue. Also, do you know which docstring it's showing on the vscode? Is it Keras 2 docstring or Keras 3?

james77777778 commented 2 months ago

@SamanehSaadat

I'm curious to understand why changing the order in the if/else fixes the issue.

I'm not an expert on Pylance, but it seems to always choose the else condition when it fails to recognize the condition. Same observation applies to Keras library. For example, keras.ops.* will always be directed to keras.src.backend.numpy.*.

Also, do you know which docstring it's showing on the vscode? Is it Keras 2 docstring or Keras 3?

It will be Keras 3 since it is placed in else condition.