forked from jupyterlab/jupyter-ai
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* implement ProviderMetaclass * add ProviderMetaclass test * bump langchain to v0.1.0 * migrate import statements deprecated by langchain v0.1 * lint
- Loading branch information
Showing
7 changed files
with
85 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
packages/jupyter-ai-magics/jupyter_ai_magics/tests/test_provider_metaclass.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from typing import ClassVar, Optional | ||
|
||
from langchain.pydantic_v1 import BaseModel | ||
|
||
from ..providers import ProviderMetaclass | ||
|
||
|
||
def test_provider_metaclass(): | ||
""" | ||
Asserts that the metaclass prevents class attributes from being omitted due | ||
to parent classes defining an instance field of the same name. | ||
You can reproduce the original issue by removing the | ||
`metaclass=ProviderMetaclass` argument from the definition of `Child`. | ||
""" | ||
|
||
class Parent(BaseModel): | ||
test: Optional[str] | ||
|
||
class Base(BaseModel): | ||
test: ClassVar[str] | ||
|
||
class Child(Base, Parent, metaclass=ProviderMetaclass): | ||
test: ClassVar[str] = "expected" | ||
|
||
assert Child.test == "expected" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters