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: correct set item for attrs >23.1 #678

Merged
merged 1 commit into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ repos:
language: system
always_run: true
pass_filenames: false
entry: mypy --strict
entry: python ./tools/update-mypy.py && mypy --strict
- repo: https://github.com/editorconfig-checker/editorconfig-checker.python
rev: '2.7.3'
hooks:
Expand Down
35 changes: 18 additions & 17 deletions openllm-core/src/openllm_core/_configuration.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# mypy: disable-error-code="attr-defined,no-untyped-call,type-var,operator,arg-type,no-redef,misc"
from __future__ import annotations
import copy
import importlib.util
import inspect
import logging
import os
import sys
Expand Down Expand Up @@ -807,22 +807,23 @@ def make_closure(self, cls: type[t.Any]) -> type[t.Any]:
return cls

def add_attrs_init(self) -> Self:
self._cls_dict['__attrs_init__'] = codegen.add_method_dunders(
self._cls,
_make_init(
self._cls,
self._attrs,
self._has_pre_init,
self._has_post_init,
False,
True,
False,
self._base_attr_map,
False,
None,
True,
),
_item = dict(
cls=self._cls,
attrs=self._attrs,
pre_init=self._has_pre_init,
post_init=self._has_post_init,
frozen=False,
slots=True,
cache_hash=False,
base_attr_map=self._base_attr_map,
is_exc=False,
cls_on_setattr=None,
attrs_init=True,
)
_make_init_args = inspect.getfullargspec(_make_init)
if 'pre_init_has_args' in _make_init_args.args:
_item['pre_init_has_args'] = False
self._cls_dict['__attrs_init__'] = codegen.add_method_dunders(self._cls, _make_init(**_item))
return self

def add_repr(self) -> Self:
Expand All @@ -836,7 +837,7 @@ def add_repr(self) -> Self:


@attr.define(slots=True, init=False)
class LLMConfig(_ConfigAttr[t.Any, t.Any]):
class LLMConfig(_ConfigAttr[GenerationConfig, SamplingParams]):
"""``openllm.LLMConfig`` is a pydantic-like ``attrs`` interface that offers fast and easy-to-use APIs.

It lives in between the nice UX of `pydantic` and fast performance of `attrs` where it allows users to quickly formulate
Expand Down
6 changes: 6 additions & 0 deletions tools/update-mypy.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ def update_mypy_ini(pyi_files: List[str], mypy_ini_path: str) -> int:
# Write changes back to mypy.ini
with open(mypy_ini_path, 'w') as configfile:
config.write(configfile)
# Remove last newline if exists
with open(mypy_ini_path, 'rb+') as file:
file.seek(-1, os.SEEK_END)
if file.read(1) == b'\n':
file.seek(-1, os.SEEK_END)
file.truncate()
return 0


Expand Down