【问题标题】:TypeHinting: How to typehint pygame Surface?类型提示:如何在 pygame Surface 中输入提示?
【发布时间】:2021-11-27 12:56:08
【问题描述】:

-> pygame.Surface: 使用正确还是应该以其他方式使用?

import pygame


def get_image() -> pygame.Surface:
    return pygame.image.load(f'img/player.png').convert_alpha()

【问题讨论】:

  • 一种方法是尝试type(pygame.image.load(f'img/player.png').convert_alpha())
  • 是的,这是正确的。

标签: python pygame type-hinting python-typing


【解决方案1】:

看看pygame.Surface.convert_alpha,他们似乎也使用pygame.Surface作为该方法的结果类型提示。

所以我猜它是正确的。


convert_alpha()
  change the pixel format of an image including per pixel alphas
  convert_alpha(Surface) -> Surface
  convert_alpha() -> Surface

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-02-06
    • 2016-03-19
    • 1970-01-01
    • 2020-11-03
    • 2020-10-14
    • 1970-01-01
    • 2021-02-11
    • 2021-02-10
    相关资源
    最近更新 更多