Skip to content

Conversation

@miurahr
Copy link
Owner

@miurahr miurahr commented Jun 1, 2025

Pull request type

select from below

  • refactor

Which ticket is resolved?

What does this PR change?

  • Refactored _make_file_info function: Split into platform-specific methods: _make_win32_file_info, _make_unix_file_info, and _make_generic_file_info.
  • New utility methods: Added methods to handle file attributes and timestamps for better modularity.
  • Platform logic in _make_file_info: Platform detection now dispatches calls to appropriate platform-specific methods.
  • Test updates: Refactored test cases to instantiate SevenZipFile before using _make_file_info for validation.

Other information

Split the _make_file_info method into platform-specific implementations (_make_win32_file_info, _make_unix_file_info, _make_generic_file_info) to improve clarity and maintainability. Adjusted test cases to ensure proper usage of SevenZipFile and comply with the new structure. This modular approach simplifies future enhancements and isolates platform-specific logic.
@coveralls
Copy link

coveralls commented Jun 1, 2025

Coverage Status

coverage: 87.186% (-0.2%) from 87.346%
when pulling e5f29c8 on topic/miurahr/refactor-complex-function
into 087a9c3 on master.

miurahr added 3 commits June 1, 2025 18:12
Replaced the installation of python3-pip with python3-venv in the GitHub Actions workflow. This ensures the virtual environment creation process is aligned with best practices and avoids unnecessary dependencies.
Introduced constants for Windows file attributes for better readability and consistency. Added a helper method `_get_win32_file_attribute` to streamline attribute extraction on Windows platforms, ensuring compatibility and reducing code redundancy.

@staticmethod
def _make_file_info(target: pathlib.Path, arcname: Optional[str] = None, dereference=False) -> dict[str, Any]:
def _make_win32_file_info(
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[mypy] reported by reviewdog 🐶
error: Function is missing a type annotation for one or more arguments [no-untyped-def]

f["emptystream"] = False
f["attributes"] = FILE_ATTRIBUTE_ARCHIVE # noqa
f["uncompressed"] = fstat.st_size
f["creationtime"] = ArchiveTimestamp.from_datetime(fstat.st_ctime)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[mypy] reported by reviewdog 🐶
error: Call to untyped function "from_datetime" in typed context [no-untyped-call]

f["attributes"] = FILE_ATTRIBUTE_ARCHIVE # noqa
f["uncompressed"] = fstat.st_size
f["creationtime"] = ArchiveTimestamp.from_datetime(fstat.st_ctime)
f["lastwritetime"] = ArchiveTimestamp.from_datetime(fstat.st_mtime)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[mypy] reported by reviewdog 🐶
error: Call to untyped function "from_datetime" in typed context [no-untyped-call]

f["uncompressed"] = fstat.st_size
f["creationtime"] = ArchiveTimestamp.from_datetime(fstat.st_ctime)
f["lastwritetime"] = ArchiveTimestamp.from_datetime(fstat.st_mtime)
f["lastaccesstime"] = ArchiveTimestamp.from_datetime(fstat.st_atime)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[mypy] reported by reviewdog 🐶
error: Call to untyped function "from_datetime" in typed context [no-untyped-call]

return fstat.st_file_attributes & FILE_ATTRIBUTE_WINDOWS_MASK
return 0

def _make_unix_file_info(self, target: pathlib.Path, arcname: Optional[str] = None, dereference=False) -> dict[str, Any]:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[mypy] reported by reviewdog 🐶
error: Function is missing a type annotation for one or more arguments [no-untyped-def]

f["lastaccesstime"] = ArchiveTimestamp.from_datetime(fstat.st_atime)
return f

def _make_generic_file_info(
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[mypy] reported by reviewdog 🐶
error: Function is missing a type annotation for one or more arguments [no-untyped-def]

f["emptystream"] = False
f["uncompressed"] = fstat.st_size
f["attributes"] = FILE_ATTRIBUTE_ARCHIVE
f["creationtime"] = ArchiveTimestamp.from_datetime(fstat.st_ctime)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[mypy] reported by reviewdog 🐶
error: Call to untyped function "from_datetime" in typed context [no-untyped-call]

f["uncompressed"] = fstat.st_size
f["attributes"] = FILE_ATTRIBUTE_ARCHIVE
f["creationtime"] = ArchiveTimestamp.from_datetime(fstat.st_ctime)
f["lastwritetime"] = ArchiveTimestamp.from_datetime(fstat.st_mtime)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[mypy] reported by reviewdog 🐶
error: Call to untyped function "from_datetime" in typed context [no-untyped-call]

f["attributes"] = FILE_ATTRIBUTE_ARCHIVE
f["creationtime"] = ArchiveTimestamp.from_datetime(fstat.st_ctime)
f["lastwritetime"] = ArchiveTimestamp.from_datetime(fstat.st_mtime)
f["lastaccesstime"] = ArchiveTimestamp.from_datetime(fstat.st_atime)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[mypy] reported by reviewdog 🐶
error: Call to untyped function "from_datetime" in typed context [no-untyped-call]

f["lastaccesstime"] = ArchiveTimestamp.from_datetime(fstat.st_atime)
return f

def _make_file_info(self, target: pathlib.Path, arcname: Optional[str] = None, dereference=False) -> dict[str, Any]:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[mypy] reported by reviewdog 🐶
error: Function is missing a type annotation for one or more arguments [no-untyped-def]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants