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

Add Type Hints for Function Parameters to Improve Inference and Bug Checking #3

Open
TreacherousDev opened this issue Nov 28, 2024 · 0 comments
Labels
good first issue Good for newcomers help wanted Extra attention is needed

Comments

@TreacherousDev
Copy link
Owner

Many functions across the project lack type hints for their parameters, which makes it harder to perform static type checking and inference before runtime. Adding type hints to function parameters will improve code clarity, help with error detection, and assist with better auto-completion in IDEs.

Below are examples of functions that could benefit from type hints:

def render_input_box(screen, label, x, y, width, height, active, text, font, color_active, color_inactive, label_font):
def render_text_with_outline(text, font, color, outline_color, position, screen, outline_offset=2):

Problem:

  • Lack of type hints for function parameters makes it harder to perform static analysis of the code.
  • This can lead to bugs or mistakes that aren't caught until runtime, and also reduces the effectiveness of code editors' auto-completion and type inference features.

Expected Solution:

  • Add type hints for all function parameters to improve inference and help with bug checking before runtime.

  • Type hints should specify the expected types for parameters, and defaults should be included where applicable.

    Example:

    def render_input_box(
        screen: pygame.Surface, 
        label: str, 
        x: int, 
        y: int, 
        width: int, 
        height: int, 
        active: bool, 
        text: str, 
        font: pygame.font.Font, 
        color_active: pygame.Color, 
        color_inactive: pygame.Color, 
        label_font: pygame.font.Font
    ):

Request:

  • Please add type hints to all functions across the project.
  • Ensure that the changes do not break or change any existing functionality.

By adding type hints, the code will become more maintainable, and the IDE will provide better error-checking and autocompletion. This will help both current and future developers to work with the code more effectively and with fewer bugs.

@TreacherousDev TreacherousDev added help wanted Extra attention is needed good first issue Good for newcomers labels Nov 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant