Skip to content

Commit

Permalink
1.0.9
Browse files Browse the repository at this point in the history
1.Found a method description error and fixed it, in `Path.getsize`.
2.Improve a magic method definition, define `__repr__` directly in class `Open` and omit `__str__`.
3.Improve `MasqueradeClass`, masquerade the attribute `__qualname__`.
4.Fix an exception description error in `ReadOnly` and improved similar exception description in `ReadOnlyMode`.

1.发现一个方法的描述错误并修复,方法 `Path.getsize`。
2.改进一个魔化方法定义,在类 `Open` 中直接定义 `__repr__`,省略 `__str__`。
3.改进 `MasqueradeClass`,隐藏属性 `__qualname__`。
4.修正 `ReadOnly` 中异常描述信息的错误,并改进了 `ReadOnlyMode` 中的类似的异常描述。
  • Loading branch information
2018-11-27 committed May 7, 2023
1 parent bf93ef7 commit 02bb2e8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
4 changes: 2 additions & 2 deletions systempath/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
>>> file.open.rb().read()
b'GQYLPY \xe6\x94\xb9\xe5\x8f\x98\xe4\xb8\x96\xe7\x95\x8c'
@version: 1.0.8
@version: 1.0.9
@author: 竹永康 <gqylpy@outlook.com>
@source: https://github.com/gqylpy/systempath
Expand Down Expand Up @@ -465,7 +465,7 @@ def lstat(self) -> os.stat_result:
).stat

def getsize(self) -> int:
"""Get the size of the file, Return 0 if the path is a directory."""
"""Get the size of the file, return 0 if the path is a directory."""
return os.path.getsize(self.name)

def getctime(self) -> float:
Expand Down
11 changes: 5 additions & 6 deletions systempath/i systempath.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ def __new__(mcs, __name__: str, __bases__: tuple, __dict__: dict):
)

mcs.__name__ = type.__name__
mcs.__qualname__ = type.__qualname__
cls.__module__ = __masquerade_class__.__module__
cls.__qualname__ = __masquerade_class__.__qualname__

Expand Down Expand Up @@ -158,7 +159,7 @@ def __setattr__(cls, name: str, value: Any) -> None:

def __delattr__(cls, name: str) -> NoReturn:
raise ge.DeleteAttributeError(
f'cannot execute operation to delete attribute '
f'cannot delete "{name}" attribute '
f'of immutable type "{cls.__name__}".'
)

Expand All @@ -184,8 +185,8 @@ def __setattr__(self, name: str, value: Any) -> None:
def __delattr__(self, name: str) -> None:
if not isinstance(self, File) or name != 'content':
raise ge.DeleteAttributeError(
f'cannot execute operation to delete attribute in instance '
f'of immutable type "{File.__name__}".'
f'cannot delete "{name}" attribute in instance '
f'of immutable type "{self.__class__.__name__}".'
)
object.__delattr__(self, name)

Expand Down Expand Up @@ -1007,12 +1008,10 @@ def __dir__(self) -> Iterable[str]:
methods += self.__modes__
return methods

def __str__(self) -> str:
def __repr__(self) -> str:
return f'<{__package__}.{self.__class__.__name__} ' \
f'file={repr(self.__path__)}>'

__repr__ = __str__

@property
def __path__(self) -> PathLink:
return self.file.name if isinstance(self.file, File) else self.file
Expand Down

0 comments on commit 02bb2e8

Please sign in to comment.