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: some type hints (tools/extractor, legacy patch stubs) #285

Merged
merged 5 commits into from
Nov 18, 2024

Conversation

Nattsu39
Copy link
Contributor

@Nattsu39 Nattsu39 commented Nov 14, 2024

Not sure if there is a better way to implement type hints for legacy patches...

UnityPy/classes/generated.py Outdated Show resolved Hide resolved
This is better than putting all patched classes into __init__.pyi, and may be worth it given the backwards-compatible immutability of the legacy patch.
Copy link
Owner

@K0lb3 K0lb3 left a comment

Choose a reason for hiding this comment

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

Looks pretty good now, and thanks for figuring this out.
I still have something to complain about 😛

... / pass isn't necessary if the class has declared fields,
so all of them can be removed from the classes.

The .py files use all to restrict the export to the class itself,
so the _ helper function can't be imported.
Instead of defining them as separate entities, you can directly put them into the class stubs themselves.

e.g. for AudioClip

from typing import Dict, List, Optional

from UnityPy.classes.generated import SampleClip, StreamedResource

class AudioClip(SampleClip):
  m_Name: str
  m_3D: Optional[bool] = None
  m_Ambisonic: Optional[bool] = None
  m_AudioData: Optional[List[int]] = None
  m_BitsPerSample: Optional[int] = None
  m_Channels: Optional[int] = None
  m_CompressionFormat: Optional[int] = None
  m_Format: Optional[int] = None
  m_Frequency: Optional[int] = None
  m_IsTrackerFormat: Optional[bool] = None
  m_Legacy3D: Optional[bool] = None
  m_Length: Optional[float] = None
  m_LoadInBackground: Optional[bool] = None
  m_LoadType: Optional[int] = None
  m_PreloadAudioData: Optional[bool] = None
  m_Resource: Optional[StreamedResource] = None
  m_Stream: Optional[int] = None
  m_SubsoundIndex: Optional[int] = None
  m_Type: Optional[int] = None
  m_UseHardware: Optional[bool] = None

  @property
  def extension(self) -> str: ...
  
  @property
  def samples(self) -> Dict[str, bytes]: ...
  

extension = property(_AudioClip_extension)
samples = property(_AudioClip_samples)

@Nattsu39 Nattsu39 requested a review from K0lb3 November 18, 2024 00:27
@Nattsu39
Copy link
Contributor Author

I think I need to click Re-request-review.
😶

Copy link
Owner

@K0lb3 K0lb3 left a comment

Choose a reason for hiding this comment

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

Thanks a lot 👍

@K0lb3 K0lb3 merged commit d2c6697 into K0lb3:master Nov 18, 2024
3 checks passed
@K0lb3 K0lb3 changed the title Fix: some type hints Fix: some type hints (tools/extractor, legacy patch stubs) Nov 18, 2024
@Nattsu39 Nattsu39 deleted the fix-typehint branch November 26, 2024 04:24
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.

2 participants