Skip to content

Commit

Permalink
use stdl 0.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
zigai committed Dec 2, 2023
1 parent 32c78fb commit e9ab01d
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 21 deletions.
4 changes: 2 additions & 2 deletions objinspect/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from collections import defaultdict

from stdl.log import br
from stdl.st import FG, colored
from stdl.st import colored

from objinspect._class import Class
from objinspect.function import Function
Expand Down Expand Up @@ -123,7 +123,7 @@ def is_dunder(name: str):
if len(variables):
print("\nVariables:")
for k, v in variables.items():
k = colored(k, FG.LIGHT_BLUE) if color else k
k = colored(k, "light_blue") if color else k
val_str = str(v)
if isinstance(v, str):
val_str = f"'{val_str}'"
Expand Down
6 changes: 3 additions & 3 deletions objinspect/_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import typing as T

import docstring_parser
from stdl.st import FG, colored
from stdl.st import colored

from objinspect.function import _get_docstr_desc, _has_docstr
from objinspect.method import Method, MethodFilter
Expand Down Expand Up @@ -184,12 +184,12 @@ def dict(self) -> dict[str, T.Any]:

def to_str(self, *, color: bool = True) -> str:
if color:
string = colored("class", FG.BLUE) + " " + colored(self.name, FG.GREEN) + ":"
string = colored("class", "blue") + " " + colored(self.name, "green") + ":"
else:
string = f"class {self.name}:"
if self.description:
if color:
string += "\n" + colored(self.description, FG.GRAY)
string += "\n" + colored(self.description, "gray")
else:
string += "\n" + self.description
if not len(self.methods):
Expand Down
2 changes: 0 additions & 2 deletions objinspect/constants.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import inspect

inspect._empty.__repr__ = lambda: "EMPTY"
inspect._empty.__str__ = lambda: "EMPTY"
EMPTY = inspect._empty

__all__ = ["EMPTY"]
10 changes: 5 additions & 5 deletions objinspect/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import docstring_parser
from docstring_parser import Docstring
from stdl.st import FG, ansi_ljust, colored
from stdl.st import ansi_ljust, colored

from objinspect.constants import EMPTY
from objinspect.parameter import Parameter
Expand Down Expand Up @@ -137,15 +137,15 @@ def to_str(self, *, color: bool = True, description: bool = True, ljust: int = 5
description (bool, optional): Whether to include the description of the function. Defaults to True.
ljust (int, optional): The width of the string. Defaults to 50.
"""
name_str = self.name if not color else colored(self.name, FG.YELLOW)
name_str = self.name if not color else colored(self.name, "yellow")
params = ", ".join([i.to_str(color=color) for i in self.params])
if color:
params = colored("(", FG.YELLOW) + params + colored(")", FG.YELLOW)
params = colored("(", "yellow") + params + colored(")", "yellow")

if self.return_type is not EMPTY:
return_str = type_to_str(self.return_type)
if color:
return_str = colored(return_str, FG.GREEN)
return_str = colored(return_str, "green")
return_str = " -> " + return_str
else:
return_str = ""
Expand All @@ -156,7 +156,7 @@ def to_str(self, *, color: bool = True, description: bool = True, ljust: int = 5
string = ansi_ljust(string, ljust)
description_str = f" # {self.description}"
if color:
description_str = colored(description_str, FG.GRAY)
description_str = colored(description_str, "gray")
return string + description_str
return string

Expand Down
8 changes: 4 additions & 4 deletions objinspect/parameter.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import inspect
import typing as T

from stdl.st import FG, colored
from stdl.st import colored

from objinspect.constants import EMPTY
from objinspect.util import type_to_str
Expand Down Expand Up @@ -84,17 +84,17 @@ def to_str(self, *, color: bool = True) -> str:
"""
type_str = f"{type_to_str(self.type)}" if self.is_typed else ""
if color and type_str:
type_str = colored(type_str, FG.GREEN)
type_str = colored(type_str, "green")
type_str = f": {type_str}" if type_str != "" else ""

default_str = f"{self.default}" if self.is_optional else ""
if self.default is not EMPTY:
if color:
default_str = colored(default_str, FG.BLUE)
default_str = colored(default_str, "blue")
default_str = f" = {default_str}"
else:
default_str = ""
name_str = self.name if not color else colored(self.name, FG.LIGHT_BLUE)
name_str = self.name if not color else colored(self.name, "light_blue")
return f"{name_str}{type_str}{default_str}"

@classmethod
Expand Down
9 changes: 5 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
[project]
name = "objinspect"
version = "0.2.7"
version = "0.2.8"
description = "View the structure of Python classes and functions"
authors = [{ name = "Žiga Ivanšek", email = "ziga.ivansek@gmail.com" }]
license = { file = "LICENSE" }
readme = "README.md"
requires-python = ">=3.10"
dependencies = [
"docstring-parser==0.15.0",
"stdl>=0.4.8",
"typing-extensions==4.7.1",
"docstring-parser>=0.15.0",
"stdl>=0.5.0",
"typing-extensions>=4.7.1",
]

classifiers = [
Expand All @@ -19,6 +19,7 @@ classifiers = [
"Programming Language :: Python",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3 :: Only",
"Topic :: Software Development :: Libraries :: Python Modules",
]
Expand Down
2 changes: 1 addition & 1 deletion tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import pytest

from objinspect.util import EMPTY, create_function
from objinspect.util import create_function


class TestCreateFunction:
Expand Down

0 comments on commit e9ab01d

Please sign in to comment.