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

Remove "type: ignore" comments #17048

Closed
1 task done
baskaryan opened this issue Feb 5, 2024 · 4 comments · Fixed by #19931
Closed
1 task done

Remove "type: ignore" comments #17048

baskaryan opened this issue Feb 5, 2024 · 4 comments · Fixed by #19931
Labels
good first issue Good for newcomers help wanted Good issue for contributors 🤖:refactor A large refactor of a feature(s) or restructuring of many files

Comments

@baskaryan
Copy link
Collaborator

Privileged issue

  • I am a LangChain maintainer, or was asked directly by a LangChain maintainer to create an issue here.

Issue Content

Currently we have many "type: ignore" comments in our code for ignoring mypy errors. We should rarely if ever use these. We've had to recently add a bunch of these ignore comments because of an error (i made) that was silently causing mypy not to run in CI.

We should work to remove as many of them as possible by fixing the underlying issues. To find the you can just grep for:

git grep "type: ignore" libs/

This is a big effort, even just removing a few at a time would be very helpful.

@baskaryan baskaryan added help wanted Good issue for contributors good first issue Good for newcomers labels Feb 5, 2024
@langchain-ai langchain-ai deleted a comment from dosubot bot Feb 5, 2024
@dosubot dosubot bot added Ɑ: langserve Related to LangServe package 🤖:refactor A large refactor of a feature(s) or restructuring of many files labels Feb 5, 2024
@baskaryan baskaryan removed the Ɑ: langserve Related to LangServe package label Feb 5, 2024
baskaryan added a commit that referenced this issue Feb 5, 2024
baskaryan added a commit that referenced this issue Feb 5, 2024
baskaryan added a commit that referenced this issue Feb 5, 2024
moorej-oci added a commit to moorej-oci/langchain that referenced this issue Feb 5, 2024
baskaryan pushed a commit that referenced this issue Feb 6, 2024
- **Description:** Add relevant type annotations for relevant session
and query objects to resolve mypy errors when `# type: ignore` comments
are removed.
  - **Issue:** #17048
  - **Dependencies:** None,
  - **Twitter handle:** [clesiemo3](https://twitter.com/clesiemo3)
 
I attempted to solve the `UpsertionRecord` ignore but it would require
added a deprecated plugin or moving completely to sqlalchemy 2.0+ from
my understanding. I'm assuming this is not something desired at this
point in time.
@ali-nobariasl
Copy link

Hello, I am a new contributor, I could handle this issue if it is still open.

Copy link

dosubot bot commented Feb 6, 2024

🤖

I understand your concern about the "type: ignore" comments in the LangChain codebase. These comments are indeed used to suppress type checking errors in the Python static type checker, mypy. However, they should be used sparingly and only as a last resort when other solutions to resolve the type checking errors are not feasible.

Here are the specific "type: ignore" comments currently present in the LangChain codebase:

  1. wrapped = obj.__init__ # type: ignore
  2. obj.__init__ = functools.wraps(obj.__init__)( # type: ignore[misc] warn_if_direct_instance )
  3. class _deprecated_property(type(obj)): # type: ignore
  4. _name = _name or obj.__name__ # type: ignore
  5. def finalize(_: Any, new_doc: str) -> Any: # type: ignore
  6. def finalize( # type: ignore wrapper: Callable[..., Any], new_doc: str ) -> T:

These comments are found in the libs/core/langchain_core/_api/deprecation.py file.

Unfortunately, I don't have the specific mypy error messages that these "type: ignore" comments are suppressing. It would be helpful to know these error messages to understand the underlying issues that need to be fixed.

As for the best practices for handling mypy errors in Python projects, they include using the mypy tool for type checking, configuring mypy options in the pyproject.toml file, excluding certain directories from mypy checks, using type annotations in your Python code, and handling mypy errors by fixing the type annotations in your code. You can find more details about these best practices in the libs/community/pyproject.toml file.

I hope this information helps. If you have more specific information about the mypy errors, please share it so we can provide a more targeted solution.

Sources


This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

If you want to continue the conversation, start your reply with @dosu-bot.

hoanq1811 pushed a commit to hoanq1811/langchain that referenced this issue Feb 6, 2024
hoanq1811 pushed a commit to hoanq1811/langchain that referenced this issue Feb 6, 2024
hoanq1811 pushed a commit to hoanq1811/langchain that referenced this issue Feb 6, 2024
hoanq1811 pushed a commit to hoanq1811/langchain that referenced this issue Feb 6, 2024
hoanq1811 pushed a commit to hoanq1811/langchain that referenced this issue Feb 6, 2024
…gchain-ai#17073)

- **Description:** Add relevant type annotations for relevant session
and query objects to resolve mypy errors when `# type: ignore` comments
are removed.
  - **Issue:** langchain-ai#17048
  - **Dependencies:** None,
  - **Twitter handle:** [clesiemo3](https://twitter.com/clesiemo3)
 
I attempted to solve the `UpsertionRecord` ignore but it would require
added a deprecated plugin or moving completely to sqlalchemy 2.0+ from
my understanding. I'm assuming this is not something desired at this
point in time.
baskaryan pushed a commit that referenced this issue Feb 13, 2024
**Description:** Fixed `type: ignore`'s for mypy for some
document_loaders.
**Issue:** [Remove "type: ignore" comments #17048
](#17048)

---------

Co-authored-by: Robby <h0rv@users.noreply.github.com>
Co-authored-by: Eugene Yurtsev <eyurtsev@gmail.com>
@baskaryan baskaryan pinned this issue Feb 14, 2024
@baskaryan baskaryan unpinned this issue Feb 14, 2024
snsten pushed a commit to snsten/langchain that referenced this issue Feb 15, 2024
**Description:** Fixed `type: ignore`'s for mypy for some
document_loaders.
**Issue:** [Remove "type: ignore" comments langchain-ai#17048
](langchain-ai#17048)

---------

Co-authored-by: Robby <h0rv@users.noreply.github.com>
Co-authored-by: Eugene Yurtsev <eyurtsev@gmail.com>
haydeniw pushed a commit to haydeniw/langchain that referenced this issue Feb 27, 2024
**Description:** Fixed `type: ignore`'s for mypy for some
document_loaders.
**Issue:** [Remove "type: ignore" comments langchain-ai#17048
](langchain-ai#17048)

---------

Co-authored-by: Robby <h0rv@users.noreply.github.com>
Co-authored-by: Eugene Yurtsev <eyurtsev@gmail.com>
baskaryan pushed a commit that referenced this issue Mar 1, 2024
baskaryan pushed a commit that referenced this issue Mar 1, 2024
Description: Fixed type: ignore's for mypy for
chat_message_histories(streamlit)
Adresses #17048 

Planning to add more based on reviews
@baskaryan
Copy link
Collaborator Author

We're bumping all our packages to use mypy v1 which is uncovering a bunch of issues that we're type: ignore-ing to start so we're not blocked on the upgrade, but which should fix as well. See #19163 for example

@Smit-Parmar
Copy link
Contributor

@baskaryan Is that mean we no longer need to work on this issue?

baskaryan pushed a commit that referenced this issue Mar 28, 2024
Relates to #17048 
Description : Applied fix to dynamodb and elasticsearch file.

Error was : `Cannot override writeable attribute with read-only
property`
Suggestion:
instead of adding 
```
@messages.setter
def messages(self, messages: List[BaseMessage]) -> None:
    raise NotImplementedError("Use add_messages instead")
```

we can change base class property
`messages: List[BaseMessage]`
to
```
@Property
def messages(self) -> List[BaseMessage]:...
```

then we don't need to add `@messages.setter` in all child classes.
bechbd pushed a commit to bechbd/langchain that referenced this issue Mar 29, 2024
Relates to langchain-ai#17048 
Description : Applied fix to dynamodb and elasticsearch file.

Error was : `Cannot override writeable attribute with read-only
property`
Suggestion:
instead of adding 
```
@messages.setter
def messages(self, messages: List[BaseMessage]) -> None:
    raise NotImplementedError("Use add_messages instead")
```

we can change base class property
`messages: List[BaseMessage]`
to
```
@Property
def messages(self) -> List[BaseMessage]:...
```

then we don't need to add `@messages.setter` in all child classes.
gkorland pushed a commit to FalkorDB/langchain that referenced this issue Mar 30, 2024
gkorland pushed a commit to FalkorDB/langchain that referenced this issue Mar 30, 2024
Description: Fixed type: ignore's for mypy for
chat_message_histories(streamlit)
Adresses langchain-ai#17048 

Planning to add more based on reviews
gkorland pushed a commit to FalkorDB/langchain that referenced this issue Mar 30, 2024
Relates to langchain-ai#17048 
Description : Applied fix to dynamodb and elasticsearch file.

Error was : `Cannot override writeable attribute with read-only
property`
Suggestion:
instead of adding 
```
@messages.setter
def messages(self, messages: List[BaseMessage]) -> None:
    raise NotImplementedError("Use add_messages instead")
```

we can change base class property
`messages: List[BaseMessage]`
to
```
@Property
def messages(self) -> List[BaseMessage]:...
```

then we don't need to add `@messages.setter` in all child classes.
marlenezw pushed a commit to marlenezw/langchain that referenced this issue Apr 2, 2024
Relates to langchain-ai#17048 
Description : Applied fix to dynamodb and elasticsearch file.

Error was : `Cannot override writeable attribute with read-only
property`
Suggestion:
instead of adding 
```
@messages.setter
def messages(self, messages: List[BaseMessage]) -> None:
    raise NotImplementedError("Use add_messages instead")
```

we can change base class property
`messages: List[BaseMessage]`
to
```
@Property
def messages(self) -> List[BaseMessage]:...
```

then we don't need to add `@messages.setter` in all child classes.
UtkarshaGupte added a commit to UtkarshaGupte/langchain that referenced this issue Apr 2, 2024
eyurtsev pushed a commit that referenced this issue Apr 4, 2024
core/langchain_core/_api[Patch]: mypy ignore fixes #17048
Related to #17048

Applied mypy fixes to below two files:
libs/core/langchain_core/_api/deprecation.py
libs/core/langchain_core/_api/beta_decorator.py

Summary of Fixes:
**Issue 1**
class _deprecated_property(type(obj)): # type: ignore
error: Unsupported dynamic base class "type"  [misc]
Fix: 
1. Added an __init__ method to _deprecated_property to initialize the
fget, fset, fdel, and __doc__ attributes.
2. In the __get__, __set__, and __delete__ methods, we now use the
self.fget, self.fset, and self.fdel attributes to call the original
methods after emitting the warning.

3. The finalize function now creates an instance of _deprecated_property
with the fget, fset, fdel, and doc attributes from the original obj
property.



**Issue 2**



 def finalize(  # type: ignore
                wrapper: Callable[..., Any], new_doc: str
            ) -> T:


error: All conditional function variants must have identical
signatures



Fix:
Ensured that both definitions of the finalize function have the
same signature

Twitter Handle -
https://x.com/gupteutkarsha?s=11&t=uwHe4C3PPpGRvoO5Qpm1aA
hinthornw pushed a commit that referenced this issue Apr 26, 2024
Relates to #17048 
Description : Applied fix to dynamodb and elasticsearch file.

Error was : `Cannot override writeable attribute with read-only
property`
Suggestion:
instead of adding 
```
@messages.setter
def messages(self, messages: List[BaseMessage]) -> None:
    raise NotImplementedError("Use add_messages instead")
```

we can change base class property
`messages: List[BaseMessage]`
to
```
@Property
def messages(self) -> List[BaseMessage]:...
```

then we don't need to add `@messages.setter` in all child classes.
hinthornw pushed a commit that referenced this issue Apr 26, 2024
core/langchain_core/_api[Patch]: mypy ignore fixes #17048
Related to #17048

Applied mypy fixes to below two files:
libs/core/langchain_core/_api/deprecation.py
libs/core/langchain_core/_api/beta_decorator.py

Summary of Fixes:
**Issue 1**
class _deprecated_property(type(obj)): # type: ignore
error: Unsupported dynamic base class "type"  [misc]
Fix: 
1. Added an __init__ method to _deprecated_property to initialize the
fget, fset, fdel, and __doc__ attributes.
2. In the __get__, __set__, and __delete__ methods, we now use the
self.fget, self.fset, and self.fdel attributes to call the original
methods after emitting the warning.

3. The finalize function now creates an instance of _deprecated_property
with the fget, fset, fdel, and doc attributes from the original obj
property.



**Issue 2**



 def finalize(  # type: ignore
                wrapper: Callable[..., Any], new_doc: str
            ) -> T:


error: All conditional function variants must have identical
signatures



Fix:
Ensured that both definitions of the finalize function have the
same signature

Twitter Handle -
https://x.com/gupteutkarsha?s=11&t=uwHe4C3PPpGRvoO5Qpm1aA
ccurme added a commit that referenced this issue May 6, 2024
Relates [#17048]
Description : Applied fix to redis and neo4j file.

Error was : `Cannot override writeable attribute with read-only
property`

fix with the same solution of
[[langchain/libs/community/langchain_community/chat_message_histories/elasticsearch.py](https://github.com/langchain-ai/langchain/blob/d5c412b0a9a8af02754de60f93d93c3efa33ccdb/libs/community/langchain_community/chat_message_histories/elasticsearch.py#L170-L175)]

---------

Co-authored-by: Bagatur <22008038+baskaryan@users.noreply.github.com>
Co-authored-by: Chester Curme <chester.curme@gmail.com>
dglogo pushed a commit to dglogo/langchain that referenced this issue May 8, 2024
…angchain-ai#20114)

Relates [langchain-ai#17048]
Description : Applied fix to redis and neo4j file.

Error was : `Cannot override writeable attribute with read-only
property`

fix with the same solution of
[[langchain/libs/community/langchain_community/chat_message_histories/elasticsearch.py](https://github.com/langchain-ai/langchain/blob/d5c412b0a9a8af02754de60f93d93c3efa33ccdb/libs/community/langchain_community/chat_message_histories/elasticsearch.py#L170-L175)]

---------

Co-authored-by: Bagatur <22008038+baskaryan@users.noreply.github.com>
Co-authored-by: Chester Curme <chester.curme@gmail.com>
kyle-cassidy pushed a commit to kyle-cassidy/langchain that referenced this issue May 10, 2024
…angchain-ai#20114)

Relates [langchain-ai#17048]
Description : Applied fix to redis and neo4j file.

Error was : `Cannot override writeable attribute with read-only
property`

fix with the same solution of
[[langchain/libs/community/langchain_community/chat_message_histories/elasticsearch.py](https://github.com/langchain-ai/langchain/blob/d5c412b0a9a8af02754de60f93d93c3efa33ccdb/libs/community/langchain_community/chat_message_histories/elasticsearch.py#L170-L175)]

---------

Co-authored-by: Bagatur <22008038+baskaryan@users.noreply.github.com>
Co-authored-by: Chester Curme <chester.curme@gmail.com>
kyle-cassidy pushed a commit to kyle-cassidy/langchain that referenced this issue May 16, 2024
…angchain-ai#20114)

Relates [langchain-ai#17048]
Description : Applied fix to redis and neo4j file.

Error was : `Cannot override writeable attribute with read-only
property`

fix with the same solution of
[[langchain/libs/community/langchain_community/chat_message_histories/elasticsearch.py](https://github.com/langchain-ai/langchain/blob/d5c412b0a9a8af02754de60f93d93c3efa33ccdb/libs/community/langchain_community/chat_message_histories/elasticsearch.py#L170-L175)]

---------

Co-authored-by: Bagatur <22008038+baskaryan@users.noreply.github.com>
Co-authored-by: Chester Curme <chester.curme@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers help wanted Good issue for contributors 🤖:refactor A large refactor of a feature(s) or restructuring of many files
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants